|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.collections4.collection.AbstractCollectionDecorator<E>
org.apache.commons.collections4.collection.PredicatedCollection<E>
org.apache.commons.collections4.queue.PredicatedQueue<E>
public class PredicatedQueue<E>
Decorates another 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);
Field Summary |
---|
Fields inherited from class org.apache.commons.collections4.collection.PredicatedCollection |
---|
predicate |
Constructor Summary | |
---|---|
protected |
PredicatedQueue(Queue<E> queue,
Predicate<? super E> predicate)
Constructor that wraps (not copies). |
Method Summary | ||
---|---|---|
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
|
predicatedQueue(Queue<E> Queue,
Predicate<? super E> predicate)
Factory method to create a predicated (validating) queue. |
|
E |
remove()
|
Methods inherited from class org.apache.commons.collections4.collection.PredicatedCollection |
---|
add, addAll, predicatedCollection, validate |
Methods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecorator |
---|
clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, setCollection, size, toArray, toArray, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
---|
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray |
Constructor Detail |
---|
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 null
IllegalArgumentException
- if Queue or predicate is null
IllegalArgumentException
- if the Queue contains invalid elementsMethod Detail |
---|
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 queueQueue
- the queue to decorate, must not be nullpredicate
- the predicate to use for validation, must not be null
IllegalArgumentException
- if queue or predicate is null
IllegalArgumentException
- 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 added
IllegalArgumentException
- if the add is invalidpublic E poll()
poll
in interface Queue<E>
public E peek()
peek
in interface Queue<E>
public E element()
element
in interface Queue<E>
public E remove()
remove
in interface Queue<E>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |