Search in sources :

Example 6 with NavigableSet

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

the class ConcurrentSkipListSetTest method testTailSetContents.

/**
     * tailSet returns set with keys in requested range
     */
public void testTailSetContents() {
    NavigableSet set = set5();
    SortedSet sm = set.tailSet(two);
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertTrue(sm.contains(three));
    assertTrue(sm.contains(four));
    assertTrue(sm.contains(five));
    Iterator i = sm.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());
    SortedSet ssm = sm.tailSet(four);
    assertEquals(four, ssm.first());
    assertEquals(five, ssm.last());
    assertTrue(ssm.remove(four));
    assertEquals(1, ssm.size());
    assertEquals(3, sm.size());
    assertEquals(4, set.size());
}
Also used : NavigableSet(java.util.NavigableSet) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 7 with NavigableSet

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

the class ConcurrentSkipListSetTest method testSubSetContents.

/**
     * A deserialized serialized set has same elements
     */
// TODO serialization on BTreeSet
//    public void testSerialization() throws Exception {
//        NavigableSet x = populatedSet(SIZE);
//        NavigableSet y = serialClone(x);
//
//        assertNotSame(x, y);
//        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());
}
Also used : NavigableSet(java.util.NavigableSet) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 8 with NavigableSet

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

the class ConcurrentSkipListSetTest method testAddAll2.

/**
     * addAll of a collection with null elements throws NPE
     */
public void testAddAll2() {
    NavigableSet q = emptySet();
    Integer[] ints = new Integer[SIZE];
    try {
        q.addAll(Arrays.asList(ints));
        shouldThrow();
    } catch (NullPointerException success) {
    }
}
Also used : NavigableSet(java.util.NavigableSet)

Example 9 with NavigableSet

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

the class ConcurrentSkipListSetTest method testAdd.

/**
     * Add of comparable element succeeds
     */
public void testAdd() {
    NavigableSet q = emptySet();
    assertTrue(q.add(zero));
    assertTrue(q.add(one));
}
Also used : NavigableSet(java.util.NavigableSet)

Example 10 with NavigableSet

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

the class ConcurrentSkipListSetTest method testLower.

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

Aggregations

NavigableSet (java.util.NavigableSet)195 Iterator (java.util.Iterator)36 SortedSet (java.util.SortedSet)25 Map (java.util.Map)11 TreeSet (java.util.TreeSet)9 HashMap (java.util.HashMap)7 TimeRange (org.apache.hadoop.hbase.io.TimeRange)6 Set (java.util.Set)5 TestSuite (junit.framework.TestSuite)5 Scan (org.apache.hadoop.hbase.client.Scan)5 Test (org.testng.annotations.Test)5 List (java.util.List)4 TreeMap (java.util.TreeMap)4 ByteString (com.google.protobuf.ByteString)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Get (org.apache.hadoop.hbase.client.Get)3 GwtIncompatible (com.google.common.annotations.GwtIncompatible)2 SampleElements (com.google.common.collect.testing.SampleElements)2 TestStringSetGenerator (com.google.common.collect.testing.TestStringSetGenerator)2