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);
| Modifier and Type | Field and Description |
|---|---|
| private static final long | serialVersionUID
Hides org. |
| Access | Constructor and Description |
|---|---|
| protected | PredicatedQueue(final Queue<E>
the queue to decorate, must not be null queue, final Predicate<? super E> the predicate to use for validation, must not be null predicate)Constructor that wraps (not copies). |
| Modifier and Type | Method and Description |
|---|---|
| protected Queue | Returns: the decorated queueOverrides org. |
| public E | element()
Implements java. |
| public boolean | Returns: the result of adding to the underlying queuethe object being added object)Implements java. |
| public E | peek()
Implements java. null if this queue is empty.
|
| public E | poll()
Implements java. null if this queue is empty.
|
| public static < the type of the elements in the queue E> PredicatedQueue | Returns: a new predicated queuethe queue to decorate, must not be null Queue, final Predicate<? super E> the predicate to use for validation, must not be null predicate)Factory method to create a predicated (validating) queue. |
| public E |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides org. Serialization version | |
| PredicatedQueue | back to summary |
|---|---|
| protected PredicatedQueue(final Queue<E> queue, final Predicate<? super E> predicate) Constructor that wraps (not copies). If there are any elements already in the collection being decorated, they are validated.
| |
| decorated | back to summary |
|---|---|
| protected Queue Overrides org. Gets the queue being decorated. | |
| element | back to summary |
|---|---|
| public E element() Implements java. Doc from java. Retrieves, but does not remove, the head of this queue. This method
differs from
| |
| offer | back to summary |
|---|---|
| public boolean offer(final E object) Implements java. Override to validate the object being added to ensure it matches the predicate.
| |
| peek | back to summary |
|---|---|
| public E peek() Implements java. Doc from java. Retrieves, but does not remove, the head of this queue,
or returns
| |
| poll | back to summary |
|---|---|
| public E poll() Implements java. Doc from java. Retrieves and removes the head of this queue,
or returns
| |
| predicatedQueue | back to summary |
|---|---|
| public static <E> PredicatedQueue Factory method to create a predicated (validating) queue. If there are any elements already in the queue being decorated, they are validated.
| |
| remove | back to summary |
|---|---|
| public E remove() Implements java. Doc from java. Retrieves and removes the head of this queue. This method differs
from
| |