Search in sources :

Example 46 with TreeMap

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

the class TreeMapTest method testFirstKey.

/**
     * firstKey returns first key
     */
public void testFirstKey() {
    TreeMap map = map5();
    assertEquals(one, map.firstKey());
}
Also used : TreeMap(java.util.TreeMap)

Example 47 with TreeMap

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

the class TreeMapTest method testTailMapContents.

/**
     * headMap returns map with keys in requested range
     */
public void testTailMapContents() {
    TreeMap map = map5();
    NavigableMap sm = map.tailMap(two, true);
    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 r = sm.descendingKeySet().iterator();
    k = (Integer) (r.next());
    assertEquals(five, k);
    k = (Integer) (r.next());
    assertEquals(four, k);
    k = (Integer) (r.next());
    assertEquals(three, k);
    k = (Integer) (r.next());
    assertEquals(two, k);
    assertFalse(r.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());
    NavigableMap ssm = sm.tailMap(four, true);
    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) Iterator(java.util.Iterator) TreeMap(java.util.TreeMap) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 48 with TreeMap

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

the class TreeSubMapTest method dmap5.

/**
     * Returns a new map from Integers -5 to -1 to Strings "A"-"E".
     */
private static NavigableMap dmap5() {
    TreeMap map = new TreeMap();
    assertTrue(map.isEmpty());
    map.put(m1, "A");
    map.put(m5, "E");
    map.put(m3, "C");
    map.put(m2, "B");
    map.put(m4, "D");
    assertFalse(map.isEmpty());
    assertEquals(5, map.size());
    return map.descendingMap();
}
Also used : TreeMap(java.util.TreeMap)

Example 49 with TreeMap

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

the class TreeMapTest method testLowerKey.

/**
     * lowerKey returns preceding element
     */
public void testLowerKey() {
    TreeMap q = map5();
    Object e1 = q.lowerKey(three);
    assertEquals(two, e1);
    Object e2 = q.lowerKey(six);
    assertEquals(five, e2);
    Object e3 = q.lowerKey(one);
    assertNull(e3);
    Object e4 = q.lowerKey(zero);
    assertNull(e4);
}
Also used : TreeMap(java.util.TreeMap)

Example 50 with TreeMap

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

the class TreeMapTest method testPollLastEntry.

/**
     * pollLastEntry returns entries in order
     */
public void testPollLastEntry() {
    TreeMap map = map5();
    Map.Entry e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(four, e.getKey());
    map.put(five, "E");
    e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(three, e.getKey());
    map.remove(two);
    e = map.pollLastEntry();
    assertEquals(one, e.getKey());
    try {
        e.setValue("E");
        shouldThrow();
    } catch (UnsupportedOperationException success) {
    }
    e = map.pollLastEntry();
    assertNull(e);
}
Also used : TreeMap(java.util.TreeMap) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Aggregations

TreeMap (java.util.TreeMap)4400 Map (java.util.Map)1245 ArrayList (java.util.ArrayList)930 HashMap (java.util.HashMap)871 Test (org.junit.Test)614 List (java.util.List)542 Before (org.junit.Before)505 IOException (java.io.IOException)402 HashSet (java.util.HashSet)301 Set (java.util.Set)268 File (java.io.File)267 SortedMap (java.util.SortedMap)240 TreeSet (java.util.TreeSet)213 LinkedHashMap (java.util.LinkedHashMap)196 Key (org.apache.accumulo.core.data.Key)156 Value (org.apache.accumulo.core.data.Value)156 Iterator (java.util.Iterator)149 NavigableMap (java.util.NavigableMap)124 Collection (java.util.Collection)115 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)111