@Test public void offerShouldReturnFalseWhenFull() { Queue<Integer> queue = new FixedArrayQueue<>(1); assertTrue(queue.offer(1)); assertFalse(queue.offer(2)); }
@Override public boolean offer(final E e) { if (null == e) { throw new NullPointerException("item cannot be null"); } final long currentTail = tail; if (currentTail - head == limit) { return false; } buffer[(int) currentTail & mask] = e; tail = currentTail + 1; return true; }
FixedArrayQueue implements Queue<E> { @Override public boolean offer(final E e) { if (null == e) { throw new NullPointerException("item cannot be null"); } final long currentTail = tail; if (currentTail - head == limit) { return false; } buffer[(int) currentTail & mask] = e; tail = currentTail + 1; return true; } }
FixedArrayQueue implements Queue<E> { @Override public boolean offer(final E e) { if (null == e) { throw new NullPointerException("item cannot be null"); } final long currentTail = tail; if (currentTail - head == limit) { return false; } buffer[(int) currentTail & mask] = e; tail = currentTail + 1; return true; } @SuppressWarnings("unchecked")  FixedArrayQueue(final int capacity); }
FixedArrayQueue implements Queue<E> { @Override public boolean offer(final E e) { if (null == e) { throw new NullPointerException("item cannot be null"); } final long currentTail = tail; if (currentTail - head == limit) { return false; } buffer[(int) currentTail & mask] = e; tail = currentTail + 1; return true; } @SuppressWarnings("unchecked")  FixedArrayQueue(final int capacity); static int findNextPositivePowerOfTwo(final int size); @Override boolean add(final E e); @Override boolean offer(final E e); @Override E poll(); @Override E remove(); @Override E element(); @Override E peek(); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(final Object o); @Override Iterator<E> iterator(); @Override Object[] toArray(); @Override T[] toArray(final T[] a); @Override boolean remove(final Object o); @Override boolean containsAll(final Collection<?> c); @Override boolean addAll(final Collection<? extends E> c); @Override boolean removeAll(final Collection<?> c); @Override boolean retainAll(final Collection<?> c); @Override void clear(); }
FixedArrayQueue implements Queue<E> { @Override public boolean offer(final E e) { if (null == e) { throw new NullPointerException("item cannot be null"); } final long currentTail = tail; if (currentTail - head == limit) { return false; } buffer[(int) currentTail & mask] = e; tail = currentTail + 1; return true; } @SuppressWarnings("unchecked")  FixedArrayQueue(final int capacity); static int findNextPositivePowerOfTwo(final int size); @Override boolean add(final E e); @Override boolean offer(final E e); @Override E poll(); @Override E remove(); @Override E element(); @Override E peek(); @Override int size(); @Override boolean isEmpty(); @Override boolean contains(final Object o); @Override Iterator<E> iterator(); @Override Object[] toArray(); @Override T[] toArray(final T[] a); @Override boolean remove(final Object o); @Override boolean containsAll(final Collection<?> c); @Override boolean addAll(final Collection<? extends E> c); @Override boolean removeAll(final Collection<?> c); @Override boolean retainAll(final Collection<?> c); @Override void clear();  }