E
- the type of elements held in this queuepublic class PredicatedQueue<E> extends PredicatedCollection<E> implements 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>
predicate
Modifier | Constructor and Description |
---|---|
protected |
PredicatedQueue(Queue<E> queue,
Predicate<? super E> predicate)
Constructor that wraps (not copies).
|
Modifier and Type | Method and Description |
---|---|
protected 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(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, removeIf, retainAll, setCollection, size, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
protected PredicatedQueue(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 nullNullPointerException
- if queue or predicate is nullIllegalArgumentException
- if the Queue contains invalid elementspublic static <E> PredicatedQueue<E> predicatedQueue(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 nullNullPointerException
- if queue or predicate is nullIllegalArgumentException
- if the queue contains invalid elementsprotected Queue<E> decorated()
decorated
in class AbstractCollectionDecorator<E>
public boolean offer(E object)
offer
in interface Queue<E>
object
- the object being addedIllegalArgumentException
- if the add is invalidCopyright © 2001–2019 The Apache Software Foundation. All rights reserved.