use of java.util.SortedMap in project mapdb by jankotek.
the class TreeSubMapTest method testDescendingSubMapContents.
/**
* subMap returns map with keys in requested range
*/
public void testDescendingSubMapContents() {
NavigableMap map = dmap5();
SortedMap sm = map.subMap(m2, m4);
assertEquals(m2, sm.firstKey());
assertEquals(m3, sm.lastKey());
assertEquals(2, sm.size());
assertFalse(sm.containsKey(m1));
assertTrue(sm.containsKey(m2));
assertTrue(sm.containsKey(m3));
assertFalse(sm.containsKey(m4));
assertFalse(sm.containsKey(m5));
Iterator i = sm.keySet().iterator();
Object k;
k = (Integer) (i.next());
assertEquals(m2, k);
k = (Integer) (i.next());
assertEquals(m3, k);
assertFalse(i.hasNext());
Iterator j = sm.keySet().iterator();
j.next();
j.remove();
assertFalse(map.containsKey(m2));
assertEquals(4, map.size());
assertEquals(1, sm.size());
assertEquals(m3, sm.firstKey());
assertEquals(m3, sm.lastKey());
assertEquals("C", sm.remove(m3));
assertTrue(sm.isEmpty());
assertEquals(3, map.size());
}
use of java.util.SortedMap in project hudson-2.x by hudson.
the class DeepEquals method compareSortedMap.
/**
* Deeply compare two SortedMap instances. This method walks the Maps in order,
* taking advantage of the fact that they Maps are SortedMaps.
* @param map1 SortedMap one
* @param map2 SortedMap two
* @param stack add items to compare to the Stack (Stack versus recursion)
* @param visited Set containing items that have already been compared, to prevent cycles.
* @return false if the Maps are for certain not equals. 'true' indicates that 'on the surface' the maps
* are equal, however, it will place the contents of the Maps on the stack for further comparisons.
*/
private static boolean compareSortedMap(SortedMap map1, SortedMap map2, LinkedList stack, Set visited) {
if (map1.size() != map2.size()) {
return false;
}
Iterator i1 = map1.entrySet().iterator();
Iterator i2 = map2.entrySet().iterator();
while (i1.hasNext()) {
Map.Entry entry1 = (Map.Entry) i1.next();
Map.Entry entry2 = (Map.Entry) i2.next();
// Must split the Key and Value so that Map.Entry's equals() method is not used.
DualKey dk = new DualKey(entry1.getKey(), entry2.getKey());
if (!visited.contains(dk)) {
// Push Keys for further comparison
stack.addFirst(dk);
}
dk = new DualKey(entry1.getValue(), entry2.getValue());
if (!visited.contains(dk)) {
// Push values for further comparison
stack.addFirst(dk);
}
}
return true;
}
use of java.util.SortedMap in project neo4j by neo4j.
the class NativeAllEntriesLabelScanReaderTest method assertRanges.
private static void assertRanges(AllEntriesLabelScanReader reader, Labels[] data) {
Iterator<NodeLabelRange> iterator = reader.iterator();
long highestRangeId = highestRangeId(data);
for (long rangeId = 0; rangeId <= highestRangeId; rangeId++) {
SortedMap<Long, List<Long>> /*labelIds*/
expected = rangeOf(data, rangeId);
if (expected != null) {
assertTrue("Was expecting range " + expected, iterator.hasNext());
NodeLabelRange range = iterator.next();
assertEquals(rangeId, range.id());
assertArrayEquals("Unexpected data in range " + rangeId, nodesOf(expected), range.nodes());
for (Map.Entry<Long, List<Long>> expectedEntry : expected.entrySet()) {
long[] labels = range.labels(expectedEntry.getKey());
assertArrayEquals(asArray(expectedEntry.getValue().iterator()), labels);
}
}
// else there was nothing in this range
}
assertFalse(iterator.hasNext());
}
use of java.util.SortedMap in project neo4j by neo4j.
the class FileNamesTest method shouldWorkCorrectlyOnReasonableDirectoryContents.
@Test
public void shouldWorkCorrectlyOnReasonableDirectoryContents() throws Exception {
// Given
// a raft log directory with just the expected files, without gaps
File base = new File("base");
FileNames fileNames = new FileNames(base);
FileSystemAbstraction fsa = mock(FileSystemAbstraction.class);
Log log = mock(Log.class);
List<File> filesPresent = new LinkedList<>();
int lower = 0;
int upper = 24;
// the files are added in reverse order, so we can verify that FileNames orders based on version
for (int i = upper; i >= lower; i--) {
filesPresent.add(fileNames.getForVersion(i));
}
when(fsa.listFiles(base)).thenReturn(filesPresent.toArray(new File[] {}));
// When
// asked for the contents of the directory
SortedMap<Long, File> allFiles = fileNames.getAllFiles(fsa, log);
// Then
// all the things we added above should be returned
assertEquals(upper - lower + 1, allFiles.size());
long currentVersion = lower;
for (Map.Entry<Long, File> longFileEntry : allFiles.entrySet()) {
assertEquals(currentVersion, longFileEntry.getKey().longValue());
assertEquals(fileNames.getForVersion(currentVersion), longFileEntry.getValue());
currentVersion++;
}
}
use of java.util.SortedMap in project randomizedtesting by randomizedtesting.
the class ExecutionTimesReport method writeHints.
/**
* Writes back hints file.
*/
public static void writeHints(File file, Map<String, List<Long>> hints) throws IOException {
Closer closer = Closer.create();
try {
BufferedWriter w = closer.register(Files.newWriter(file, Charsets.UTF_8));
if (!(hints instanceof SortedMap)) {
hints = new TreeMap<String, List<Long>>(hints);
}
Joiner joiner = Joiner.on(',');
for (Map.Entry<String, List<Long>> e : hints.entrySet()) {
w.write(e.getKey());
w.write("=");
joiner.appendTo(w, e.getValue());
w.write("\n");
}
} catch (Throwable t) {
throw closer.rethrow(t);
} finally {
closer.close();
}
}
Aggregations