Java Code Examples for java.util.NavigableSet#iterator()

The following examples show how to use java.util.NavigableSet#iterator() . 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: ConcurrentSkipListSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
void mutateSet(NavigableSet<Integer> set, int min, int max, BitSet bs) {
    int size = set.size();
    int rangeSize = max - min + 1;

    // Remove a bunch of entries directly
    for (int i = 0, n = rangeSize / 2; i < n; i++) {
        remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs);
    }

    // Remove a bunch of entries with iterator
    for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
        if (rnd.nextBoolean()) {
            bs.clear(it.next());
            it.remove();
        }
    }

    // Add entries till we're back to original size
    while (set.size() < size) {
        int element = min + rnd.nextInt(rangeSize);
        assertTrue(element >= min && element <= max);
        put(set, element, bs);
    }
}
 
Example 2
Source File: Chapter07Concurrency02.java    From Java-11-Cookbook-Second-Edition with MIT License 6 votes vote down vote up
private static void demoNavigableSetIterRemove(NavigableSet<Integer> set) {
    System.out.println("set: " + set);
    try {
        Iterator iter = set.iterator();
        while (iter.hasNext()) {
            Integer e = (Integer) iter.next();
            System.out.println(e);
            if (e == 2) {
                System.out.println("Calling iter.remove()...");
                iter.remove();
            }
        }
    } catch (Exception ex) {
        System.out.println(ex.getClass().getName());
    }
    System.out.println("set: " + set);
}
 
Example 3
Source File: TreeSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * iterator.remove removes current element
 */
public void testIteratorRemove() {
    final NavigableSet q = set0();
    q.add(new Integer(2));
    q.add(new Integer(1));
    q.add(new Integer(3));

    Iterator it = q.iterator();
    it.next();
    it.remove();

    it = q.iterator();
    assertEquals(2, it.next());
    assertEquals(3, it.next());
    assertFalse(it.hasNext());
}
 
Example 4
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * iterator.remove removes current element
 */
public void testDescendingIteratorRemove() {
    final NavigableSet q = dset0();
    q.add(new Integer(2));
    q.add(new Integer(1));
    q.add(new Integer(3));

    Iterator it = q.iterator();
    it.next();
    it.remove();

    it = q.iterator();
    assertEquals(2, it.next());
    assertEquals(3, it.next());
    assertFalse(it.hasNext());
}
 
Example 5
Source File: BTreeSet2Test.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
void mutateSet(NavigableSet<Integer> set, int min, int max, BitSet bs) {
    int size = set.size();
    int rangeSize = max - min + 1;

    // Remove a bunch of entries directly
    for (int i = 0, n = rangeSize / 2; i < n; i++) {
        remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs);
    }

    // Remove a bunch of entries with iterator
    for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
        if (rnd.nextBoolean()) {
            int val = it.next();
            bs.clear(val);
            it.remove();
        }
    }

    // Add entries till we're back to original size
    while (set.size() < size) {
        int element = min + rnd.nextInt(rangeSize);
        assertTrue(element >= min && element<= max);
        put(set, element, bs);
    }
}
 
Example 6
Source File: BTreeMapSubSetTest.java    From scava with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * iterator.remove removes current element
 */
public void testDescendingIteratorRemove() {
    final NavigableSet q = dset0();
    q.add(new Integer(2));
    q.add(new Integer(1));
    q.add(new Integer(3));

    Iterator it = q.iterator();
    it.next();
    it.remove();

    it = q.iterator();
    assertEquals(it.next(), new Integer(2));
    assertEquals(it.next(), new Integer(3));
    assertFalse(it.hasNext());
}
 
Example 7
Source File: EmptyNavigableSet.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests that the iterator is empty.
 */
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testEmptyIterator(String description, NavigableSet<?> navigableSet) {
    Iterator emptyIterator = navigableSet.iterator();

    assertFalse((emptyIterator != null) && (emptyIterator.hasNext()),
        "The iterator is not empty.");
}
 
Example 8
Source File: EmptyNavigableSet.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests that the iterator is empty.
 */
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testEmptyIterator(String description, NavigableSet<?> navigableSet) {
    Iterator emptyIterator = navigableSet.iterator();

    assertFalse((emptyIterator != null) && (emptyIterator.hasNext()),
        "The iterator is not empty.");
}
 
Example 9
Source File: BTreeMapSubSetTest.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * iterator iterates through all elements
 */
public void testDescendingIterator() {
    NavigableSet q = populatedSet(SIZE);
    int i = 0;
    Iterator it = q.iterator();
    while (it.hasNext()) {
        assertTrue(q.contains(it.next()));
        ++i;
    }
    assertEquals(i, SIZE);
}
 
Example 10
Source File: BTreeMapSubSetTest.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * iterator iterates through all elements
 */
public void testIterator() {
    NavigableSet q = populatedSet(SIZE);
    int i = 0;
    Iterator it = q.iterator();
    while (it.hasNext()) {
        assertTrue(q.contains(it.next()));
        ++i;
    }
    assertEquals(i, SIZE);
}
 
Example 11
Source File: TreeSubSetTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * iterator iterates through all elements
 */
public void testDescendingIterator() {
    NavigableSet q = populatedSet(SIZE);
    int i = 0;
    Iterator it = q.iterator();
    while (it.hasNext()) {
        assertTrue(q.contains(it.next()));
        ++i;
    }
    assertEquals(i, SIZE);
}
 
Example 12
Source File: BTreeSet2Test.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * iterator iterates through all elements
 */
public void testIterator() {
    NavigableSet q = populatedSet(SIZE);
    int i = 0;
    Iterator it = q.iterator();
    while (it.hasNext()) {
        assertTrue(q.contains(it.next()));
        ++i;
    }
    assertEquals(i, SIZE);
}
 
Example 13
Source File: BTreeMapSubSetTest.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * iterator of empty set has no elements
 */
public void testDescendingEmptyIterator() {
    NavigableSet q = dset0();
    int i = 0;
    Iterator it = q.iterator();
    while (it.hasNext()) {
        assertTrue(q.contains(it.next()));
        ++i;
    }
    assertEquals(0, i);
}
 
Example 14
Source File: EmptyNavigableSet.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests that the iterator is empty.
 */
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testEmptyIterator(String description, NavigableSet<?> navigableSet) {
    Iterator emptyIterator = navigableSet.iterator();

    assertFalse((emptyIterator != null) && (emptyIterator.hasNext()),
        "The iterator is not empty.");
}
 
Example 15
Source File: ConcurrentSkipListSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * iterator of empty set has no elements
 */
public void testDescendingEmptyIterator() {
    NavigableSet q = dset0();
    int i = 0;
    Iterator it = q.iterator();
    while (it.hasNext()) {
        assertTrue(q.contains(it.next()));
        ++i;
    }
    assertEquals(0, i);
}
 
Example 16
Source File: TreeSubSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * iterator of empty set has no elements
 */
public void testDescendingEmptyIterator() {
    NavigableSet q = dset0();
    int i = 0;
    Iterator it = q.iterator();
    while (it.hasNext()) {
        assertTrue(q.contains(it.next()));
        ++i;
    }
    assertEquals(0, i);
}
 
Example 17
Source File: EmptyNavigableSet.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests that the iterator is empty.
 */
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testEmptyIterator(String description, NavigableSet<?> navigableSet) {
    Iterator emptyIterator = navigableSet.iterator();

    assertFalse((emptyIterator != null) && (emptyIterator.hasNext()),
        "The iterator is not empty.");
}
 
Example 18
Source File: EmptyNavigableSet.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests that the iterator is empty.
 */
@Test(dataProvider = "NavigableSet<?>", dataProviderClass = EmptyNavigableSet.class)
public void testEmptyIterator(String description, NavigableSet<?> navigableSet) {
    Iterator emptyIterator = navigableSet.iterator();

    assertFalse((emptyIterator != null) && (emptyIterator.hasNext()),
        "The iterator is not empty.");
}
 
Example 19
Source File: ConcurrentSkipListSubSetJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * iterator of empty set has no elements
 */
public void testDescendingEmptyIterator() {
    NavigableSet q = dset0();
    int i = 0;
    Iterator it = q.iterator();
    while (it.hasNext()) {
        assertTrue(q.contains(it.next()));
        ++i;
    }
    assertEquals(0, i);
}
 
Example 20
Source File: ConcurrentSkipListSetTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
void mutateSubSet(NavigableSet<Integer> set, int min, int max,
                  BitSet bs) {
    int size = set.size();
    int rangeSize = max - min + 1;

    // Remove a bunch of entries directly
    for (int i = 0, n = rangeSize / 2; i < n; i++) {
        remove(set, min - 5 + rnd.nextInt(rangeSize + 10), bs);
    }

    // Remove a bunch of entries with iterator
    for (Iterator<Integer> it = set.iterator(); it.hasNext(); ) {
        if (rnd.nextBoolean()) {
            bs.clear(it.next());
            it.remove();
        }
    }

    // Add entries till we're back to original size
    while (set.size() < size) {
        int element = min - 5 + rnd.nextInt(rangeSize + 10);
        if (element >= min && element <= max) {
            put(set, element, bs);
        } else {
            try {
                set.add(element);
                shouldThrow();
            } catch (IllegalArgumentException success) {}
        }
    }
}