use of java.util.NavigableMap in project mapdb by jankotek.
the class TreeSubMapTest method testContainsValue.
/**
* containsValue returns true for held values
*/
public void testContainsValue() {
NavigableMap map = map5();
assertTrue(map.containsValue("A"));
assertFalse(map.containsValue("Z"));
}
use of java.util.NavigableMap 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());
}
use of java.util.NavigableMap in project mapdb by jankotek.
the class TreeSubMapTest method testDescendingPutAll.
/**
* putAll adds all key-value pairs from the given map
*/
public void testDescendingPutAll() {
NavigableMap empty = dmap0();
NavigableMap map = dmap5();
empty.putAll(map);
assertEquals(5, empty.size());
assertTrue(empty.containsKey(m1));
assertTrue(empty.containsKey(m2));
assertTrue(empty.containsKey(m3));
assertTrue(empty.containsKey(m4));
assertTrue(empty.containsKey(m5));
}
use of java.util.NavigableMap in project mapdb by jankotek.
the class TreeSubMapTest method testDescendingPollFirstEntry.
/**
* pollFirstEntry returns entries in order
*/
public void testDescendingPollFirstEntry() {
NavigableMap map = dmap5();
Map.Entry e = map.pollFirstEntry();
assertEquals(m1, e.getKey());
assertEquals("A", e.getValue());
e = map.pollFirstEntry();
assertEquals(m2, e.getKey());
map.put(m1, "A");
e = map.pollFirstEntry();
assertEquals(m1, e.getKey());
assertEquals("A", e.getValue());
e = map.pollFirstEntry();
assertEquals(m3, e.getKey());
map.remove(m4);
e = map.pollFirstEntry();
assertEquals(m5, e.getKey());
try {
e.setValue("A");
shouldThrow();
} catch (UnsupportedOperationException success) {
}
e = map.pollFirstEntry();
assertNull(e);
}
use of java.util.NavigableMap in project mapdb by jankotek.
the class TreeSubMapTest method testContainsKey.
/**
* containsKey returns true for contained key
*/
public void testContainsKey() {
NavigableMap map = map5();
assertTrue(map.containsKey(one));
assertFalse(map.containsKey(zero));
}
Aggregations