public class PredicatedQueue<E> extends PredicatedCollection<E> implements java.util.Queue<E>
Queue
to validate that additions
match a specified predicate.
This queue exists to provide validation for the decorated queue. It is normally created to decorate an empty queue. If an object cannot be added to the queue, an IllegalArgumentException is thrown.
One usage would be to ensure that no null entries are added to the queue.
Queue queue = PredicatedQueue.predicatedQueue(new UnboundedFifoQueue(), NotNullPredicate.INSTANCE);
PredicatedCollection.Builder<E>
Modifier and Type | Method and Description |
---|---|
E |
element() |
boolean |
offer(E object)
Override to validate the object being added to ensure it matches
the predicate.
|
E |
peek() |
E |
poll() |
static <E> PredicatedQueue<E> |
predicatedQueue(java.util.Queue<E> Queue,
Predicate<? super E> predicate)
Factory method to create a predicated (validating) queue.
|
E |
remove() |
add, addAll, builder, notNullBuilder, predicatedCollection
clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
public static <E> PredicatedQueue<E> predicatedQueue(java.util.Queue<E> Queue, Predicate<? super E> predicate)
If there are any elements already in the queue being decorated, they are validated.
E
- the type of the elements in the queueQueue
- the queue to decorate, must not be nullpredicate
- the predicate to use for validation, must not be nulljava.lang.NullPointerException
- if queue or predicate is nulljava.lang.IllegalArgumentException
- if the queue contains invalid elementspublic boolean offer(E object)
offer
in interface java.util.Queue<E>
object
- the object being addedjava.lang.IllegalArgumentException
- if the add is invalid"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"