public 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
Constructor that wraps (not copies).
|
| Modifier and Type | Method and Description |
|---|---|
protected Queue |
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 |
predicatedQueue(Queue
Factory method to create a predicated (validating) queue.
|
E |
remove()
|
add, addAll, builder, notNullBuilder, predicatedCollection, validateclear, contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, setCollection, size, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArrayprotected 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 null
predicate - the predicate to use for validation, must not be null
NullPointerException - if queue or predicate is null
IllegalArgumentException - if the Queue contains invalid elements
public 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 queue
Queue - the queue to decorate, must not be null
predicate - the predicate to use for validation, must not be null
NullPointerException - if queue or predicate is null
IllegalArgumentException - if the queue contains invalid elements
protected Queue<E> decorated()
decorated in class
AbstractCollectionDecorator<E>
public boolean offer(E object)
offer in interface
Queue<E>
object - the object being added
IllegalArgumentException - if the add is invalid
public E poll()
public E peek()
public E element()
public E remove()