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);
}
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);
}
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()));
}
}
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);
}
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);
}
Aggregations