Java Code Examples for java.util.concurrent.ArrayBlockingQueue#remove()
The following examples show how to use
java.util.concurrent.ArrayBlockingQueue#remove() .
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: ArrayBlockingQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Returns a new queue of given size containing consecutive * Integers 0 ... n - 1, with given capacity range and fairness. */ static ArrayBlockingQueue<Integer> populatedQueue( int size, int minCapacity, int maxCapacity, boolean fair) { ThreadLocalRandom rnd = ThreadLocalRandom.current(); int capacity = rnd.nextInt(minCapacity, maxCapacity + 1); ArrayBlockingQueue<Integer> q = new ArrayBlockingQueue<>(capacity); assertTrue(q.isEmpty()); // shuffle circular array elements so they wrap { int n = rnd.nextInt(capacity); for (int i = 0; i < n; i++) q.add(42); for (int i = 0; i < n; i++) q.remove(); } for (int i = 0; i < size; i++) assertTrue(q.offer((Integer) i)); assertEquals(size == 0, q.isEmpty()); assertEquals(capacity - size, q.remainingCapacity()); assertEquals(size, q.size()); if (size > 0) assertEquals((Integer) 0, q.peek()); return q; }
Example 2
Source File: ArrayBlockingQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { ArrayBlockingQueue q = populatedQueue(SIZE); ArrayBlockingQueue p = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { boolean changed = q.retainAll(p); if (i == 0) assertFalse(changed); else assertTrue(changed); assertTrue(q.containsAll(p)); assertEquals(SIZE - i, q.size()); p.remove(); } }
Example 3
Source File: ArrayBlockingQueueTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * retainAll(c) retains only those elements of c and reports true if changed */ public void testRetainAll() { ArrayBlockingQueue q = populatedQueue(SIZE); ArrayBlockingQueue p = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { boolean changed = q.retainAll(p); if (i == 0) assertFalse(changed); else assertTrue(changed); assertTrue(q.containsAll(p)); assertEquals(SIZE - i, q.size()); p.remove(); } }
Example 4
Source File: ccrcrc.java From letv with Apache License 2.0 | 5 votes |
public String remove() { try { ArrayBlockingQueue arrayBlockingQueue = this.b0414ДД0414ДД; int i = bХ0425ХХ04250425; switch ((i * (b04250425ХХ04250425 + i)) % b0425ХХ042504250425()) { case 0: break; default: bХ0425ХХ04250425 = b0425Х0425Х04250425(); bХ04250425Х04250425 = 94; break; } String str = (String) arrayBlockingQueue.remove(); while (true) { switch (1) { case null: break; case 1: return str; default: while (true) { switch (1) { case null: break; case 1: return str; default: } } } } } catch (NoSuchElementException e) { return null; } }
Example 5
Source File: ArrayBlockingQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * remove removes next element, or throws NSEE if empty */ public void testRemove() { ArrayBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.remove()); } try { q.remove(); shouldThrow(); } catch (NoSuchElementException success) {} }
Example 6
Source File: ArrayBlockingQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * removeAll(c) removes only those elements of c and reports true if changed */ public void testRemoveAll() { for (int i = 1; i < SIZE; ++i) { ArrayBlockingQueue q = populatedQueue(SIZE); ArrayBlockingQueue p = populatedQueue(i); assertTrue(q.removeAll(p)); assertEquals(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { Integer x = (Integer)(p.remove()); assertFalse(q.contains(x)); } } }
Example 7
Source File: ArrayBlockingQueueTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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()); }
Example 8
Source File: WhiteBox.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Instead of having putIndex (and takeIndex) at the initial * default of 0, move them to a random location. */ void randomizePutIndex(ArrayBlockingQueue q) { assertTrue(q.isEmpty()); int capacity = q.remainingCapacity(); int n = rnd.nextInt(capacity + 1); int putIndex = putIndex(q); for (int i = n; i-->0; ) q.add(Boolean.TRUE); for (int i = n; i-->0; ) q.remove(); assertEquals(putIndex(q), (putIndex + n) % items(q).length); }
Example 9
Source File: ArrayBlockingQueueTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * remove removes next element, or throws NSEE if empty */ public void testRemove() { ArrayBlockingQueue q = populatedQueue(SIZE); for (int i = 0; i < SIZE; ++i) { assertEquals(i, q.remove()); } try { q.remove(); shouldThrow(); } catch (NoSuchElementException success) {} }
Example 10
Source File: ArrayBlockingQueueTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * removeAll(c) removes only those elements of c and reports true if changed */ public void testRemoveAll() { for (int i = 1; i < SIZE; ++i) { ArrayBlockingQueue q = populatedQueue(SIZE); ArrayBlockingQueue p = populatedQueue(i); assertTrue(q.removeAll(p)); assertEquals(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { Integer x = (Integer)(p.remove()); assertFalse(q.contains(x)); } } }
Example 11
Source File: ArrayBlockingQueueTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * 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()); }