Java Code Examples for java.util.concurrent.ConcurrentSkipListSet#subSet()

The following examples show how to use java.util.concurrent.ConcurrentSkipListSet#subSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConcurrentSkipListSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a new set of given size containing consecutive
 * Integers 0 ... n - 1.
 */
private NavigableSet<Integer> populatedSet(int n) {
    ConcurrentSkipListSet<Integer> q =
        new ConcurrentSkipListSet<Integer>();
    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;
}
 
Example 2
Source File: ConcurrentSkipListSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void testSubSetContents2() {
    ConcurrentSkipListSet set = set5();
    SortedSet sm = set.subSet(two, three);
    assertEquals(1, sm.size());
    assertEquals(two, sm.first());
    assertEquals(two, sm.last());
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertFalse(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(two));
    assertEquals(4, set.size());
    assertEquals(0, sm.size());
    assertTrue(sm.isEmpty());
    assertFalse(sm.remove(three));
    assertEquals(4, set.size());
}
 
Example 3
Source File: ConcurrentSkipListSubSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new set of given size containing consecutive
 * Integers 0 ... n.
 */
private NavigableSet<Integer> populatedSet(int n) {
    ConcurrentSkipListSet<Integer> q =
        new ConcurrentSkipListSet<Integer>();
    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;
}
 
Example 4
Source File: ConcurrentSkipListSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testSubSetContents2() {
    ConcurrentSkipListSet set = set5();
    SortedSet sm = set.subSet(two, three);
    assertEquals(1, sm.size());
    assertEquals(two, sm.first());
    assertEquals(two, sm.last());
    assertFalse(sm.contains(one));
    assertTrue(sm.contains(two));
    assertFalse(sm.contains(three));
    assertFalse(sm.contains(four));
    assertFalse(sm.contains(five));
    Iterator i = sm.iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    assertFalse(i.hasNext());
    Iterator j = sm.iterator();
    j.next();
    j.remove();
    assertFalse(set.contains(two));
    assertEquals(4, set.size());
    assertEquals(0, sm.size());
    assertTrue(sm.isEmpty());
    assertFalse(sm.remove(three));
    assertEquals(4, set.size());
}
 
Example 5
Source File: ConcurrentSkipListSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a new set of first 5 ints.
 */
private NavigableSet set5() {
    ConcurrentSkipListSet q = new ConcurrentSkipListSet();
    assertTrue(q.isEmpty());
    q.add(one);
    q.add(two);
    q.add(three);
    q.add(four);
    q.add(five);
    q.add(zero);
    q.add(seven);
    NavigableSet s = q.subSet(one, true, seven, false);
    assertEquals(5, s.size());
    return s;
}
 
Example 6
Source File: ConcurrentSkipListSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * subSet returns set with keys in requested range
 */
public void testSubSetContents() {
    ConcurrentSkipListSet 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());
}
 
Example 7
Source File: ConcurrentSkipListSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new set of first 5 ints.
 */
private NavigableSet set5() {
    ConcurrentSkipListSet q = new ConcurrentSkipListSet();
    assertTrue(q.isEmpty());
    q.add(one);
    q.add(two);
    q.add(three);
    q.add(four);
    q.add(five);
    q.add(zero);
    q.add(seven);
    NavigableSet s = q.subSet(one, true, seven, false);
    assertEquals(5, s.size());
    return s;
}
 
Example 8
Source File: ConcurrentSkipListSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * subSet returns set with keys in requested range
 */
public void testSubSetContents() {
    ConcurrentSkipListSet 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());
}