当前位置: 首页>>代码示例>>Java>>正文


Java ArrayBlockingQueue.iterator方法代码示例

本文整理汇总了Java中java.util.concurrent.ArrayBlockingQueue.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayBlockingQueue.iterator方法的具体用法?Java ArrayBlockingQueue.iterator怎么用?Java ArrayBlockingQueue.iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ArrayBlockingQueue的用法示例。


在下文中一共展示了ArrayBlockingQueue.iterator方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testIteratorRemove

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * iterator.remove removes current element
 */
public void testIteratorRemove() {
    final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
    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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ArrayBlockingQueueTest.java

示例2: testIterator

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * iterator iterates through all elements
 */
public void testIterator() throws InterruptedException {
    ArrayBlockingQueue 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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:ArrayBlockingQueueTest.java

示例3: interiorRemovalOfElementsUsedByIterator

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * Interior removal of elements used by an iterator will cause it
 * to be untracked.
 */
public void interiorRemovalOfElementsUsedByIterator() {
    boolean fair = rnd.nextBoolean();
    int capacity = rnd.nextInt(10, 20);
    ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
    randomizePutIndex(q);
    q.add(0);
    for (int i = 1; i < 2 * capacity; i++) {
        q.add(i);
        Integer[] elts = { -1, -2, -3 };
        for (Integer elt : elts) q.add(elt);
        assertEquals(q.remove(), i - 1);
        Iterator it = q.iterator();
        assertEquals(it.next(), i);
        assertEquals(it.next(), elts[0]);
        Collections.shuffle(Arrays.asList(elts));
        assertTrue(q.remove(elts[0]));
        assertTrue(q.remove(elts[1]));
        assertEquals(trackedIterators(q), Collections.singletonList(it));
        assertTrue(q.remove(elts[2]));
        assertNull(itrs(q));
        assertEquals(it.next(), -2);
        assertIteratorExhausted(it);
        assertTrue(isDetached(it));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:WhiteBox.java

示例4: garbageCollectionOfUnreachableIterators

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
public void garbageCollectionOfUnreachableIterators() {
    boolean fair = rnd.nextBoolean();
    int capacity = rnd.nextInt(1, 10);
    ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
    randomizePutIndex(q);
    List<Iterator> its = new ArrayList<>();
    for (int i = 0; i < capacity; i++) q.add(i);
    for (int i = 0; i < capacity; i++) its.add(q.iterator());
    assertEquals(attachedIterators(q), its);
    its = null;
    gcAwait(() -> {
        List<Iterator> trackedIterators = trackedIterators(q);
        assertEquals(trackedIterators.size(), capacity);
        for (Iterator x : trackedIterators)
            if (x != null) return false;
        return true;
    });
    Iterator it = q.iterator(); //
    assertEquals(trackedIterators(q), Collections.singletonList(it));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:WhiteBox.java

示例5: iteratorsDetachedWhenExhaustedAndLastRetRemoved

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
public void iteratorsDetachedWhenExhaustedAndLastRetRemoved() {
    boolean fair = rnd.nextBoolean();
    int capacity = rnd.nextInt(2, 10);
    ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
    randomizePutIndex(q);
    int size = rnd.nextInt(1, capacity + 1);
    for (int i = 0; i < size; i++) q.add(i);
    Iterator it = q.iterator();
    for (int i = 0; i < size - 1; i++) assertEquals(i, it.next());
    assertEquals(trackedIterators(q), Collections.singletonList(it));
    assertFalse(isDetached(it));
    switch (rnd.nextInt(2)) {
    case 0: assertTrue(q.remove(size - 1)); break;
    case 1: assertTrue(q.removeIf(e -> e.equals(size - 1))); break;
    default: throw new AssertionError();
    }
    assertEquals(size - 1, it.next()); // should trigger detach
    assertNull(itrs(q));
    assertTrue(isDetached(it));
    assertRemoveHasNoEffect(it, q);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:WhiteBox.java

示例6: testIteratorOrdering

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * iterator ordering is FIFO
 */
public void testIteratorOrdering() {
    final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
    q.add(one);
    q.add(two);
    q.add(three);

    assertEquals("queue should be full", 0, q.remainingCapacity());

    int k = 0;
    for (Iterator it = q.iterator(); it.hasNext();) {
        assertEquals(++k, it.next());
    }
    assertEquals(3, k);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ArrayBlockingQueueTest.java

示例7: testWeaklyConsistentIteration

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
/**
 * Modifications do not cause iterators to fail
 */
public void testWeaklyConsistentIteration() {
    final ArrayBlockingQueue q = new ArrayBlockingQueue(3);
    q.add(one);
    q.add(two);
    q.add(three);
    for (Iterator it = q.iterator(); it.hasNext();) {
        q.remove();
        it.next();
    }
    assertEquals(0, q.size());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:ArrayBlockingQueueTest.java

示例8: iteratorsOnEmptyQueue

import java.util.concurrent.ArrayBlockingQueue; //导入方法依赖的package包/类
public void iteratorsOnEmptyQueue() {
    boolean fair = rnd.nextBoolean();
    int capacity = rnd.nextInt(1, 10);
    ArrayBlockingQueue q = new ArrayBlockingQueue(capacity, fair);
    randomizePutIndex(q);
    for (int i = 0; i < 4; i++) {
        Iterator it = q.iterator();
        assertNull(itrs(q));
        assertIteratorExhausted(it);
        assertTrue(isDetached(it));
        assertRemoveThrowsISE(it);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:WhiteBox.java


注:本文中的java.util.concurrent.ArrayBlockingQueue.iterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。