Search in sources :

Example 36 with TreeMap

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

the class TreeMapTest method testPollFirstEntry.

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

Example 37 with TreeMap

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

the class TreeMapTest method testFloorEntry.

/**
     * floorEntry returns preceding entry.
     */
public void testFloorEntry() {
    TreeMap map = map5();
    Map.Entry e1 = map.floorEntry(three);
    assertEquals(three, e1.getKey());
    Map.Entry e2 = map.floorEntry(six);
    assertEquals(five, e2.getKey());
    Map.Entry e3 = map.floorEntry(one);
    assertEquals(one, e3.getKey());
    Map.Entry e4 = map.floorEntry(zero);
    assertNull(e4);
}
Also used : TreeMap(java.util.TreeMap) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 38 with TreeMap

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

the class TreeMapTest method testDescendingEntrySetToArray.

/**
     * descendingEntrySet.toArray contains all entries
     */
public void testDescendingEntrySetToArray() {
    TreeMap map = map5();
    Set s = map.descendingMap().entrySet();
    Object[] ar = s.toArray();
    assertEquals(5, ar.length);
    for (int i = 0; i < 5; ++i) {
        assertTrue(map.containsKey(((Map.Entry) (ar[i])).getKey()));
        assertTrue(map.containsValue(((Map.Entry) (ar[i])).getValue()));
    }
}
Also used : Set(java.util.Set) NavigableSet(java.util.NavigableSet) BitSet(java.util.BitSet) TreeMap(java.util.TreeMap)

Example 39 with TreeMap

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

the class TreeMapTest method testDescendingKeySetOrder.

/**
     * descendingKeySet is ordered
     */
public void testDescendingKeySetOrder() {
    TreeMap map = map5();
    Set s = map.descendingKeySet();
    Iterator i = s.iterator();
    Integer last = (Integer) i.next();
    assertEquals(last, five);
    int count = 1;
    while (i.hasNext()) {
        Integer k = (Integer) i.next();
        assertTrue(last.compareTo(k) > 0);
        last = k;
        ++count;
    }
    assertEquals(5, count);
}
Also used : Set(java.util.Set) NavigableSet(java.util.NavigableSet) BitSet(java.util.BitSet) Iterator(java.util.Iterator) TreeMap(java.util.TreeMap)

Example 40 with TreeMap

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

the class TreeMapTest method testDescendingKeySetDescendingIteratorOrder.

/**
     * descending iterator of descendingKeySet is ordered
     */
public void testDescendingKeySetDescendingIteratorOrder() {
    TreeMap map = map5();
    NavigableSet s = map.descendingKeySet();
    Iterator i = s.descendingIterator();
    Integer last = (Integer) i.next();
    assertEquals(last, one);
    int count = 1;
    while (i.hasNext()) {
        Integer k = (Integer) i.next();
        assertTrue(last.compareTo(k) < 0);
        last = k;
        ++count;
    }
    assertEquals(5, count);
}
Also used : NavigableSet(java.util.NavigableSet) Iterator(java.util.Iterator) TreeMap(java.util.TreeMap)

Aggregations

TreeMap (java.util.TreeMap)4328 Map (java.util.Map)1215 ArrayList (java.util.ArrayList)908 HashMap (java.util.HashMap)848 Test (org.junit.Test)610 List (java.util.List)530 Before (org.junit.Before)504 IOException (java.io.IOException)390 HashSet (java.util.HashSet)292 File (java.io.File)260 Set (java.util.Set)258 SortedMap (java.util.SortedMap)238 TreeSet (java.util.TreeSet)208 LinkedHashMap (java.util.LinkedHashMap)181 Key (org.apache.accumulo.core.data.Key)156 Value (org.apache.accumulo.core.data.Value)156 Iterator (java.util.Iterator)147 NavigableMap (java.util.NavigableMap)124 Collection (java.util.Collection)111 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)110