Java Code Examples for java.util.concurrent.LinkedTransferQueue#iterator()

The following examples show how to use java.util.concurrent.LinkedTransferQueue#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: LinkedTransferQueueTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * iterator iterates through all elements
 */
public void testIterator() throws InterruptedException {
    LinkedTransferQueue q = populatedQueue(SIZE);
    Iterator it = q.iterator();
    int i;
    for (i = 0; it.hasNext(); i++)
        assertTrue(q.contains(it.next()));
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);

    it = q.iterator();
    for (i = 0; it.hasNext(); i++)
        assertEquals(it.next(), q.take());
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);
}
 
Example 2
Source File: LinkedTransferQueueTest.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 LinkedTransferQueue q = new LinkedTransferQueue();
    q.add(two);
    q.add(one);
    q.add(three);

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

    it = q.iterator();
    assertSame(it.next(), one);
    assertSame(it.next(), three);
    assertFalse(it.hasNext());
}
 
Example 3
Source File: LinkedTransferQueueTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * iterator iterates through all elements
 */
public void testIterator() throws InterruptedException {
    LinkedTransferQueue q = populatedQueue(SIZE);
    Iterator it = q.iterator();
    int i;
    for (i = 0; it.hasNext(); i++)
        assertTrue(q.contains(it.next()));
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);

    it = q.iterator();
    for (i = 0; it.hasNext(); i++)
        assertEquals(it.next(), q.take());
    assertEquals(i, SIZE);
    assertIteratorExhausted(it);
}
 
Example 4
Source File: LinkedTransferQueueTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * iterator.remove() removes current element
 */
public void testIteratorRemove() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    q.add(two);
    q.add(one);
    q.add(three);

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

    it = q.iterator();
    assertSame(it.next(), one);
    assertSame(it.next(), three);
    assertFalse(it.hasNext());
}
 
Example 5
Source File: LinkedTransferQueueTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Modifications do not cause iterators to fail
 */
public void testWeaklyConsistentIteration() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    q.add(one);
    q.add(two);
    q.add(three);
    for (Iterator it = q.iterator(); it.hasNext();) {
        q.remove();
        it.next();
    }
    assertEquals(0, q.size());
}
 
Example 6
Source File: LinkedTransferQueueTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Modifications do not cause iterators to fail
 */
public void testWeaklyConsistentIteration() {
    final LinkedTransferQueue q = new LinkedTransferQueue();
    q.add(one);
    q.add(two);
    q.add(three);
    for (Iterator it = q.iterator(); it.hasNext();) {
        q.remove();
        it.next();
    }
    assertEquals(0, q.size());
}
 
Example 7
Source File: WhiteBox.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
Iterator iteratorAt(LinkedTransferQueue q, Object e) {
    for (Iterator it = q.iterator(); it.hasNext(); )
        if (it.next().equals(e))
            return it;
    throw new AssertionError("not found");
}