@Test public void testOfferReturnsFalseIfNoSpace() { exchangingQueue = new ExchangingQueue<>(1); assertTrue(exchangingQueue.offer(1)); assertFalse(exchangingQueue.offer(2)); }
public boolean offer(final T element) { if (null == element) { throw new NullPointerException("Cannot put null in the queue"); } final int currentTail = tail.get(); final int wrapPoint = currentTail - capacity; if (head.get() <= wrapPoint) { return false; } queue[currentTail & mask] = element; tail.lazySet(currentTail + 1); if (waiter != null) { LockSupport.unpark(waiter); } return true; }
ExchangingQueue { public boolean offer(final T element) { if (null == element) { throw new NullPointerException("Cannot put null in the queue"); } final int currentTail = tail.get(); final int wrapPoint = currentTail - capacity; if (head.get() <= wrapPoint) { return false; } queue[currentTail & mask] = element; tail.lazySet(currentTail + 1); if (waiter != null) { LockSupport.unpark(waiter); } return true; } }
ExchangingQueue { public boolean offer(final T element) { if (null == element) { throw new NullPointerException("Cannot put null in the queue"); } final int currentTail = tail.get(); final int wrapPoint = currentTail - capacity; if (head.get() <= wrapPoint) { return false; } queue[currentTail & mask] = element; tail.lazySet(currentTail + 1); if (waiter != null) { LockSupport.unpark(waiter); } return true; } @SuppressWarnings("unchecked")  ExchangingQueue(final int capacity); }
ExchangingQueue { public boolean offer(final T element) { if (null == element) { throw new NullPointerException("Cannot put null in the queue"); } final int currentTail = tail.get(); final int wrapPoint = currentTail - capacity; if (head.get() <= wrapPoint) { return false; } queue[currentTail & mask] = element; tail.lazySet(currentTail + 1); if (waiter != null) { LockSupport.unpark(waiter); } return true; } @SuppressWarnings("unchecked")  ExchangingQueue(final int capacity); boolean offer(final T element); T poll(); T blockingPoll(); }
ExchangingQueue { public boolean offer(final T element) { if (null == element) { throw new NullPointerException("Cannot put null in the queue"); } final int currentTail = tail.get(); final int wrapPoint = currentTail - capacity; if (head.get() <= wrapPoint) { return false; } queue[currentTail & mask] = element; tail.lazySet(currentTail + 1); if (waiter != null) { LockSupport.unpark(waiter); } return true; } @SuppressWarnings("unchecked")  ExchangingQueue(final int capacity); boolean offer(final T element); T poll(); T blockingPoll();  }