Search in sources :

Example 26 with SortedMap

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());
}
Also used : NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) Iterator(java.util.Iterator)

Example 27 with SortedMap

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;
}
Also used : Iterator(java.util.Iterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 28 with SortedMap

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());
}
Also used : NodeLabelRange(org.neo4j.kernel.api.labelscan.NodeLabelRange) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TreeMap(java.util.TreeMap) PrimitiveIntObjectMap(org.neo4j.collection.primitive.PrimitiveIntObjectMap) SortedMap(java.util.SortedMap)

Example 29 with SortedMap

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++;
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Log(org.neo4j.logging.Log) File(java.io.File) Map(java.util.Map) SortedMap(java.util.SortedMap) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 30 with SortedMap

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();
    }
}
Also used : Closer(com.google.common.io.Closer) Joiner(com.google.common.base.Joiner) SortedMap(java.util.SortedMap) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) BufferedWriter(java.io.BufferedWriter)

Aggregations

SortedMap (java.util.SortedMap)216 Map (java.util.Map)162 TreeMap (java.util.TreeMap)108 HashMap (java.util.HashMap)59 Iterator (java.util.Iterator)31 NavigableMap (java.util.NavigableMap)31 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)25 IOException (java.io.IOException)20 ImmutableMap (com.google.common.collect.ImmutableMap)19 JASIExpr (org.matheclipse.core.convert.JASIExpr)16 IExpr (org.matheclipse.core.interfaces.IExpr)16 List (java.util.List)15 File (java.io.File)14 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)14 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)12 Entry (java.util.Map.Entry)12 ConcurrentNavigableMap (java.util.concurrent.ConcurrentNavigableMap)12 ConcurrentMap (java.util.concurrent.ConcurrentMap)11 LinkedHashMap (java.util.LinkedHashMap)9