/** * Returns true if this queue is empty; false otherwise. * * @return true if this queue is empty */ @Override public boolean isEmpty() { return size() == 0; }
/** * Adds the given element to this queue. If the queue is full, the least recently added * element is discarded so that a new element can be inserted. * * @param element the element to add * @return true, always * @throws NullPointerException if the given element is null */ @Override public boolean offer(final E element) { return add(element); }
@Override public E peek() { if (isEmpty()) { return null; } return elements[start]; }
/** * Constructor that creates a queue from the specified collection. * The collection size also sets the queue size. * * @param coll the collection to copy into the queue, may not be null * @throws NullPointerException if the collection is null */ public CircularFifoQueue(final Collection<? extends E> coll) { this(coll.size()); addAll(coll); }
@Override public E next() { if (!hasNext()) { throw new NoSuchElementException(); } isFirst = false; lastReturnedIndex = index; index = increment(index); return elements[lastReturnedIndex]; }
@Override public int hashCode() { synchronized (lock) { return decorated().hashCode(); } }
/** * Gets the decorated queue. * * @return the decorated queue */ protected Queue<E> getQueue() { return (Queue<E>) decorated(); }
/** * Returns an unmodifiable queue backed by the given queue. * * @param <E> the type of the elements in the queue * @param queue the queue to make unmodifiable, must not be null * @return an unmodifiable queue backed by that queue * @throws NullPointerException if the queue is null */ public static <E> Queue<E> unmodifiableQueue(final Queue<? extends E> queue) { return UnmodifiableQueue.unmodifiableQueue(queue); }
/** * Factory method to create a synchronized queue. * * @param <E> * the type of the elements in the queue * @param queue * the queue to decorate, must not be null * @return a new synchronized Queue * @throws NullPointerException * if queue is null */ public static <E> SynchronizedQueue<E> synchronizedQueue(final Queue<E> queue) { return new SynchronizedQueue<>(queue); }
/** * Factory method to create a predicated (validating) queue. * <p> * If there are any elements already in the queue being decorated, they * are validated. * * @param <E> the type of the elements in the queue * @param Queue the queue to decorate, must not be null * @param predicate the predicate to use for validation, must not be null * @return a new predicated queue * @throws NullPointerException if queue or predicate is null * @throws IllegalArgumentException if the queue contains invalid elements */ public static <E> PredicatedQueue<E> predicatedQueue(final Queue<E> Queue, final Predicate<? super E> predicate) { return new PredicatedQueue<>(Queue, predicate); }
/** * Factory method to create a transforming queue. * <p> * If there are any elements already in the queue being decorated, they * are NOT transformed. * Contrast this with {@link #transformedQueue(Queue, Transformer)}. * * @param <E> the type of the elements in the queue * @param queue the queue to decorate, must not be null * @param transformer the transformer to use for conversion, must not be null * @return a new transformed Queue * @throws NullPointerException if queue or transformer is null */ public static <E> TransformedQueue<E> transformingQueue(final Queue<E> queue, final Transformer<? super E, ? extends E> transformer) { return new TransformedQueue<>(queue, transformer); }
/** * Returns a predicated (validating) queue backed by the given queue. * <p> * Only objects that pass the test in the given predicate can be added to the queue. * Trying to add an invalid object results in an IllegalArgumentException. * It is important not to use the original queue after invoking this method, * as it is a backdoor for adding invalid objects. * * @param <E> the type of the elements in the queue * @param queue the queue to predicate, must not be null * @param predicate the predicate used to evaluate new elements, must not be null * @return a predicated queue * @throws NullPointerException if the queue or predicate is null */ public static <E> Queue<E> predicatedQueue(final Queue<E> queue, final Predicate<? super E> predicate) { return PredicatedQueue.predicatedQueue(queue, predicate); }
/** * Write the collection out using a custom routine. * * @param out the output stream * @throws IOException if an I/O error occurs while writing to the output stream */ private void writeObject(final ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeObject(decorated()); }
@Override public synchronized void update(final Bulletin bulletin) { ringBuffer.add(bulletin); }
/** * Returns {@code true} if the capacity limit of this queue has been reached, * i.e. the number of elements stored in the queue equals its maximum size. * * @return {@code true} if the capacity limit has been reached, {@code false} otherwise * @since 4.1 */ public boolean isAtFullCapacity() { return size() == maxElements; }
@Override public E poll() { synchronized (lock) { return decorated().poll(); } }
@Override protected int getAvailableDataPointEvents() { return m_memoryQueue.size(); }
@Override public E element() { synchronized (lock) { return decorated().element(); } }