本文整理汇总了Java中java.util.concurrent.LinkedTransferQueue.add方法的典型用法代码示例。如果您正苦于以下问题:Java LinkedTransferQueue.add方法的具体用法?Java LinkedTransferQueue.add怎么用?Java LinkedTransferQueue.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.LinkedTransferQueue
的用法示例。
在下文中一共展示了LinkedTransferQueue.add方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: traversalOperationsCollapseRandomNodes
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* Checks that traversal operations collapse a random pattern of
* dead nodes as could normally only occur with a race.
*/
@Test(dataProvider = "traversalActions")
public void traversalOperationsCollapseRandomNodes(
Consumer<LinkedTransferQueue> traversalAction) {
LinkedTransferQueue q = new LinkedTransferQueue();
int n = rnd.nextInt(6);
for (int i = 0; i < n; i++) q.add(i);
ArrayList nulledOut = new ArrayList();
for (Object p = head(q); p != null; p = next(p))
if (rnd.nextBoolean()) {
nulledOut.add(item(p));
ITEM.setVolatile(p, null);
}
traversalAction.accept(q);
int c = nodeCount(q);
assertEquals(q.size(), c - (q.contains(n - 1) ? 0 : 1));
for (int i = 0; i < n; i++)
assertTrue(nulledOut.contains(i) ^ q.contains(i));
}
示例2: pollActionsOneNodeSlack
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
@Test(dataProvider = "pollActions")
public void pollActionsOneNodeSlack(
Consumer<LinkedTransferQueue> pollAction) {
LinkedTransferQueue q = new LinkedTransferQueue();
int n = 1 + rnd.nextInt(5);
for (int i = 0; i < n; i++) q.add(i);
assertEquals(nodeCount(q), n + 1);
for (int i = 0; i < n; i++) {
int c = nodeCount(q);
boolean slack = item(head(q)) == null;
if (slack) assertNotNull(item(next(head(q))));
pollAction.accept(q);
assertEquals(nodeCount(q), q.isEmpty() ? 1 : c - (slack ? 2 : 0));
}
assertInvariants(q);
}
示例3: testIteratorRemove
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* 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());
}
示例4: testDrainTo
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* drainTo(c) empties queue into another collection c
*/
public void testDrainTo() {
LinkedTransferQueue q = populatedQueue(SIZE);
ArrayList l = new ArrayList();
q.drainTo(l);
assertEquals(0, q.size());
assertEquals(SIZE, l.size());
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, l.get(i));
}
q.add(zero);
q.add(one);
assertFalse(q.isEmpty());
assertTrue(q.contains(zero));
assertTrue(q.contains(one));
l.clear();
q.drainTo(l);
assertEquals(0, q.size());
assertEquals(2, l.size());
for (int i = 0; i < 2; ++i) {
assertEquals(i, l.get(i));
}
}
示例5: addRemove
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
@Test
public void addRemove() {
LinkedTransferQueue q = new LinkedTransferQueue();
assertInvariants(q);
assertNull(next(head(q)));
assertNull(item(head(q)));
q.add(1);
assertEquals(nodeCount(q), 2);
assertInvariants(q);
q.remove(1);
assertEquals(nodeCount(q), 1);
assertInvariants(q);
}
示例6: traversalOperationsCollapseLeadingNodes
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
@Test(dataProvider = "traversalActions")
public void traversalOperationsCollapseLeadingNodes(
Consumer<LinkedTransferQueue> traversalAction) {
LinkedTransferQueue q = new LinkedTransferQueue();
Object oldHead;
int n = 1 + rnd.nextInt(5);
for (int i = 0; i < n; i++) q.add(i);
assertEquals(nodeCount(q), n + 1);
oldHead = head(q);
traversalAction.accept(q);
assertInvariants(q);
assertEquals(nodeCount(q), n);
assertIsSelfLinked(oldHead);
}
示例7: bulkRemovalOperationsCollapseNodes
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
@Test(dataProvider = "bulkRemovalActions")
public void bulkRemovalOperationsCollapseNodes(
Consumer<LinkedTransferQueue> bulkRemovalAction) {
LinkedTransferQueue q = new LinkedTransferQueue();
int n = 1 + rnd.nextInt(5);
for (int i = 0; i < n; i++) q.add(i);
bulkRemovalAction.accept(q);
assertEquals(nodeCount(q), 1);
assertInvariants(q);
}
示例8: testClear
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* clear removes all elements
*/
public void testClear() throws InterruptedException {
LinkedTransferQueue q = populatedQueue(SIZE);
q.clear();
checkEmpty(q);
assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
q.add(one);
assertFalse(q.isEmpty());
assertEquals(1, q.size());
assertTrue(q.contains(one));
q.clear();
checkEmpty(q);
}
示例9: testContainsAll
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* containsAll(c) is true when c contains a subset of elements
*/
public void testContainsAll() {
LinkedTransferQueue<Integer> q = populatedQueue(SIZE);
LinkedTransferQueue<Integer> p = new LinkedTransferQueue<>();
for (int i = 0; i < SIZE; ++i) {
assertTrue(q.containsAll(p));
assertFalse(p.containsAll(q));
p.add(i);
}
assertTrue(p.containsAll(q));
}
示例10: testIteratorOrdering
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* iterator ordering is FIFO
*/
public void testIteratorOrdering() {
final LinkedTransferQueue<Integer> q = new LinkedTransferQueue<>();
assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
q.add(one);
q.add(two);
q.add(three);
assertEquals(Integer.MAX_VALUE, q.remainingCapacity());
int k = 0;
for (Integer n : q) {
assertEquals(++k, (int) n);
}
assertEquals(3, k);
}
示例11: testWeaklyConsistentIteration
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
/**
* 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());
}
示例12: traversalOperationsCollapseInteriorNodes
import java.util.concurrent.LinkedTransferQueue; //导入方法依赖的package包/类
@Test(dataProvider = "traversalActions")
public void traversalOperationsCollapseInteriorNodes(
Consumer<LinkedTransferQueue> traversalAction) {
LinkedTransferQueue q = new LinkedTransferQueue();
int n = 6;
for (int i = 0; i < n; i++) q.add(i);
// We must be quite devious to reliably create an interior dead node
Object p0 = findNode(q, 0);
Object p1 = findNode(q, 1);
Object p2 = findNode(q, 2);
Object p3 = findNode(q, 3);
Object p4 = findNode(q, 4);
Object p5 = findNode(q, 5);
Iterator it1 = iteratorAt(q, 1);
Iterator it2 = iteratorAt(q, 2);
it2.remove(); // causes it2's ancestor to advance to 1
assertSame(next(p1), p3);
assertSame(next(p2), p3);
assertNull(item(p2));
it1.remove(); // removes it2's ancestor
assertSame(next(p0), p3);
assertSame(next(p1), p3);
assertSame(next(p2), p3);
assertNull(item(p1));
assertEquals(it2.next(), 3);
it2.remove(); // it2's ancestor can't unlink
assertSame(next(p0), p3); // p3 is now interior dead node
assertSame(next(p1), p4); // it2 uselessly CASed p1.next
assertSame(next(p2), p3);
assertSame(next(p3), p4);
assertInvariants(q);
int c = nodeCount(q);
traversalAction.accept(q);
assertEquals(nodeCount(q), c - 1);
assertSame(next(p0), p4);
assertSame(next(p1), p4);
assertSame(next(p2), p3);
assertSame(next(p3), p4);
assertInvariants(q);
// trailing nodes are not unlinked
Iterator it5 = iteratorAt(q, 5); it5.remove();
traversalAction.accept(q);
assertSame(next(p4), p5);
assertNull(next(p5));
assertEquals(nodeCount(q), c - 1);
}