use of java.util.NavigableSet in project mapdb by jankotek.
the class ConcurrentSkipListSubSetTest method populatedSet.
/**
* Returns a new set of given size containing consecutive
* Integers 0 ... n.
*/
private NavigableSet<Integer> populatedSet(int n) {
NavigableSet<Integer> q = emptySet();
assertTrue(q.isEmpty());
for (int i = n - 1; i >= 0; i -= 2) assertTrue(q.add(new Integer(i)));
for (int i = (n & 1); i < n; i += 2) assertTrue(q.add(new Integer(i)));
assertTrue(q.add(new Integer(-n)));
assertTrue(q.add(new Integer(n)));
NavigableSet s = q.subSet(new Integer(0), true, new Integer(n), false);
assertFalse(s.isEmpty());
assertEquals(n, s.size());
return s;
}
use of java.util.NavigableSet in project mapdb by jankotek.
the class ConcurrentSkipListSubSetTest method testContainsAll.
/**
* containsAll(c) is true when c contains a subset of elements
*/
public void testContainsAll() {
NavigableSet q = populatedSet(SIZE);
NavigableSet p = set0();
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.containsAll(p));
assertFalse(p.containsAll(q));
p.add(new Integer(i));
}
assertTrue(p.containsAll(q));
}
use of java.util.NavigableSet in project mapdb by jankotek.
the class ConcurrentSkipListSubSetTest method testSubSetContents.
//
// /**
// * A deserialized serialized set has same elements
// */
// TODO treeSet serialization
// public void testSerialization() throws Exception {
// NavigableSet x = populatedSet(SIZE);
// NavigableSet y = serialClone(x);
//
// assertNotSame(y, x);
// assertEquals(x.size(), y.size());
// assertEquals(x, y);
// assertEquals(y, x);
// while (!x.isEmpty()) {
// assertFalse(y.isEmpty());
// assertEquals(x.pollFirst(), y.pollFirst());
// }
// assertTrue(y.isEmpty());
// }
/**
* subSet returns set with keys in requested range
*/
public void testSubSetContents() {
NavigableSet set = set5();
SortedSet sm = set.subSet(two, four);
assertEquals(two, sm.first());
assertEquals(three, sm.last());
assertEquals(2, sm.size());
assertFalse(sm.contains(one));
assertTrue(sm.contains(two));
assertTrue(sm.contains(three));
assertFalse(sm.contains(four));
assertFalse(sm.contains(five));
Iterator i = sm.iterator();
Object k;
k = (Integer) (i.next());
assertEquals(two, k);
k = (Integer) (i.next());
assertEquals(three, k);
assertFalse(i.hasNext());
Iterator j = sm.iterator();
j.next();
j.remove();
assertFalse(set.contains(two));
assertEquals(4, set.size());
assertEquals(1, sm.size());
assertEquals(three, sm.first());
assertEquals(three, sm.last());
assertTrue(sm.remove(three));
assertTrue(sm.isEmpty());
assertEquals(3, set.size());
}
use of java.util.NavigableSet in project mapdb by jankotek.
the class ConcurrentSkipListSubSetTest method testDescendingAddAll2.
/**
* addAll of a collection with null elements throws NPE
*/
public void testDescendingAddAll2() {
NavigableSet q = dset0();
Integer[] ints = new Integer[SIZE];
try {
q.addAll(Arrays.asList(ints));
shouldThrow();
} catch (NullPointerException success) {
}
}
use of java.util.NavigableSet in project mapdb by jankotek.
the class ConcurrentSkipListSubSetTest method testRemoveAll.
/**
* removeAll(c) removes only those elements of c and reports true if changed
*/
public void testRemoveAll() {
for (int i = 1; i < SIZE; ++i) {
NavigableSet q = populatedSet(SIZE);
NavigableSet p = populatedSet(i);
assertTrue(q.removeAll(p));
assertEquals(SIZE - i, q.size());
for (int j = 0; j < i; ++j) {
Integer x = (Integer) (p.pollFirst());
assertFalse(q.contains(x));
}
}
}
Aggregations