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 | Field and Description |
---|---|
private static long |
serialVersionUID
Serialization version
|
predicate
Modifier | Constructor and Description |
---|---|
protected |
PredicatedQueue(java.util.Queue<E> queue,
Predicate<? super E> predicate)
Constructor that wraps (not copies).
|
Modifier and Type | Method and Description |
---|---|
protected java.util.Queue<E> |
decorated()
Gets the queue being decorated.
|
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, validate
clear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, setCollection, size, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
private static final long serialVersionUID
protected PredicatedQueue(java.util.Queue<E> queue, Predicate<? super E> predicate)
If there are any elements already in the collection being decorated, they are validated.
queue
- 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 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 elementsprotected java.util.Queue<E> decorated()
decorated
in class AbstractCollectionDecorator<E>
public boolean offer(E object)
offer
in interface java.util.Queue<E>
object
- the object being addedjava.lang.IllegalArgumentException
- if the add is invalid