@Test public void testOfferTailDropToCapacity() { CapacityQueue<Integer> queue = new CapacityQueue<>( DEFAULT_CAPACITY, CapacityQueue.DROP_POLICY_TAIL); for (int i = 0; i < DEFAULT_CAPACITY; i++) { assertThat(queue.offer(i)).isTrue(); } }
@Override public boolean offer(E e) { if (mDropPolicy == DROP_POLICY_TAIL) { return mDeque.size() < mMaxCapacity && mDeque.offerLast(e); } if (mDeque.size() >= mMaxCapacity) { Log.d(TAG, "Dropping from head"); mDeque.removeFirst(); } return mDeque.offerLast(e); }
CapacityQueue extends AbstractQueue<E> { @Override public boolean offer(E e) { if (mDropPolicy == DROP_POLICY_TAIL) { return mDeque.size() < mMaxCapacity && mDeque.offerLast(e); } if (mDeque.size() >= mMaxCapacity) { Log.d(TAG, "Dropping from head"); mDeque.removeFirst(); } return mDeque.offerLast(e); } }
CapacityQueue extends AbstractQueue<E> { @Override public boolean offer(E e) { if (mDropPolicy == DROP_POLICY_TAIL) { return mDeque.size() < mMaxCapacity && mDeque.offerLast(e); } if (mDeque.size() >= mMaxCapacity) { Log.d(TAG, "Dropping from head"); mDeque.removeFirst(); } return mDeque.offerLast(e); } CapacityQueue(int maxCapacity, @DropPolicy int dropPolicy); }
CapacityQueue extends AbstractQueue<E> { @Override public boolean offer(E e) { if (mDropPolicy == DROP_POLICY_TAIL) { return mDeque.size() < mMaxCapacity && mDeque.offerLast(e); } if (mDeque.size() >= mMaxCapacity) { Log.d(TAG, "Dropping from head"); mDeque.removeFirst(); } return mDeque.offerLast(e); } CapacityQueue(int maxCapacity, @DropPolicy int dropPolicy); @Override int size(); @Override boolean offer(E e); @Override E poll(); @Override E peek(); @Override @NonNull Iterator<E> iterator(); }
CapacityQueue extends AbstractQueue<E> { @Override public boolean offer(E e) { if (mDropPolicy == DROP_POLICY_TAIL) { return mDeque.size() < mMaxCapacity && mDeque.offerLast(e); } if (mDeque.size() >= mMaxCapacity) { Log.d(TAG, "Dropping from head"); mDeque.removeFirst(); } return mDeque.offerLast(e); } CapacityQueue(int maxCapacity, @DropPolicy int dropPolicy); @Override int size(); @Override boolean offer(E e); @Override E poll(); @Override E peek(); @Override @NonNull Iterator<E> iterator();  }