Search in sources :

Example 21 with SortedMap

use of java.util.SortedMap in project mapdb by jankotek.

the class ConcurrentSkipListSubMapTest method testSubMapContents.

// TODO serialization?
//    /**
//     * A deserialized map equals original
//     */
//    @Test public void testSerialization() throws Exception {
//        NavigableMap x = map5();
//        NavigableMap y = serialClone(x);
//
//        assertNotSame(x, y);
//        assertEquals(x.size(), y.size());
//        assertEquals(x.toString(), y.toString());
//        assertEquals(x, y);
//        assertEquals(y, x);
//    }
/**
     * subMap returns map with keys in requested range
     */
@Test
public void testSubMapContents() {
    ConcurrentNavigableMap map = map5();
    SortedMap sm = map.subMap(two, four);
    assertEquals(two, sm.firstKey());
    assertEquals(three, sm.lastKey());
    assertEquals(2, sm.size());
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertFalse(sm.containsKey(four));
    assertFalse(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    if (isReadOnly())
        return;
    Iterator j = sm.keySet().iterator();
    j.next();
    j.remove();
    assertFalse(map.containsKey(two));
    assertEquals(4, map.size());
    assertEquals(1, sm.size());
    assertEquals(three, sm.firstKey());
    assertEquals(three, sm.lastKey());
    assertEquals("C", sm.remove(three));
    assertTrue(sm.isEmpty());
    assertEquals(3, map.size());
}
Also used : SortedMap(java.util.SortedMap) Iterator(java.util.Iterator) ConcurrentNavigableMap(java.util.concurrent.ConcurrentNavigableMap) Test(org.junit.Test)

Example 22 with SortedMap

use of java.util.SortedMap in project mapdb by jankotek.

the class TreeSubMapTest method testTailMapContents.

/**
     * headMap returns map with keys in requested range
     */
public void testTailMapContents() {
    NavigableMap map = map5();
    SortedMap sm = map.tailMap(two);
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertTrue(sm.containsKey(four));
    assertTrue(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    k = (Integer) (i.next());
    assertEquals(four, k);
    k = (Integer) (i.next());
    assertEquals(five, k);
    assertFalse(i.hasNext());
    Iterator ei = sm.entrySet().iterator();
    Map.Entry e;
    e = (Map.Entry) (ei.next());
    assertEquals(two, e.getKey());
    assertEquals("B", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(three, e.getKey());
    assertEquals("C", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(four, e.getKey());
    assertEquals("D", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    assertFalse(i.hasNext());
    SortedMap ssm = sm.tailMap(four);
    assertEquals(four, ssm.firstKey());
    assertEquals(five, ssm.lastKey());
    assertEquals("D", ssm.remove(four));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, map.size());
}
Also used : NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) Iterator(java.util.Iterator) TreeMap(java.util.TreeMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap)

Example 23 with SortedMap

use of java.util.SortedMap in project mapdb by jankotek.

the class TreeSubMapTest method testDescendingTailMapContents.

/**
     * headMap returns map with keys in requested range
     */
public void testDescendingTailMapContents() {
    NavigableMap map = dmap5();
    SortedMap sm = map.tailMap(m2);
    assertFalse(sm.containsKey(m1));
    assertTrue(sm.containsKey(m2));
    assertTrue(sm.containsKey(m3));
    assertTrue(sm.containsKey(m4));
    assertTrue(sm.containsKey(m5));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(m2, k);
    k = (Integer) (i.next());
    assertEquals(m3, k);
    k = (Integer) (i.next());
    assertEquals(m4, k);
    k = (Integer) (i.next());
    assertEquals(m5, k);
    assertFalse(i.hasNext());
    Iterator ei = sm.entrySet().iterator();
    Map.Entry e;
    e = (Map.Entry) (ei.next());
    assertEquals(m2, e.getKey());
    assertEquals("B", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(m3, e.getKey());
    assertEquals("C", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(m4, e.getKey());
    assertEquals("D", e.getValue());
    e = (Map.Entry) (ei.next());
    assertEquals(m5, e.getKey());
    assertEquals("E", e.getValue());
    assertFalse(i.hasNext());
    SortedMap ssm = sm.tailMap(m4);
    assertEquals(m4, ssm.firstKey());
    assertEquals(m5, ssm.lastKey());
    assertEquals("D", ssm.remove(m4));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, map.size());
}
Also used : NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) Iterator(java.util.Iterator) TreeMap(java.util.TreeMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap)

Example 24 with SortedMap

use of java.util.SortedMap in project mapdb by jankotek.

the class TreeSubMapTest method testSubMapContents.

/**
     * subMap returns map with keys in requested range
     */
public void testSubMapContents() {
    NavigableMap map = map5();
    SortedMap sm = map.subMap(two, four);
    assertEquals(two, sm.firstKey());
    assertEquals(three, sm.lastKey());
    assertEquals(2, sm.size());
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertFalse(sm.containsKey(four));
    assertFalse(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer) (i.next());
    assertEquals(two, k);
    k = (Integer) (i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    Iterator j = sm.keySet().iterator();
    j.next();
    j.remove();
    assertFalse(map.containsKey(two));
    assertEquals(4, map.size());
    assertEquals(1, sm.size());
    assertEquals(three, sm.firstKey());
    assertEquals(three, sm.lastKey());
    assertEquals("C", sm.remove(three));
    assertTrue(sm.isEmpty());
    assertEquals(3, map.size());
}
Also used : NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) Iterator(java.util.Iterator)

Example 25 with SortedMap

use of java.util.SortedMap in project mapdb by jankotek.

the class TreeSubMapTest method testDescendingHeadMapContents.

/**
     * headMap returns map with keys in requested range
     */
public void testDescendingHeadMapContents() {
    NavigableMap map = dmap5();
    SortedMap sm = map.headMap(m4);
    assertTrue(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(m1, k);
    k = (Integer) (i.next());
    assertEquals(m2, k);
    k = (Integer) (i.next());
    assertEquals(m3, k);
    assertFalse(i.hasNext());
    sm.clear();
    assertTrue(sm.isEmpty());
    assertEquals(2, map.size());
    assertEquals(m4, map.firstKey());
}
Also used : NavigableMap(java.util.NavigableMap) SortedMap(java.util.SortedMap) Iterator(java.util.Iterator)

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