Class PredicatedQueue<E>
java.lang.Object
org.apache.commons.collections4.collection.AbstractCollectionDecorator<E>
org.apache.commons.collections4.collection.PredicatedCollection<E>
org.apache.commons.collections4.queue.PredicatedQueue<E>
- Type Parameters:
- E- the type of elements held in this queue
- All Implemented Interfaces:
- Serializable,- Iterable<E>,- Collection<E>,- Queue<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);
- Since:
- 4.0
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class org.apache.commons.collections4.collection.PredicatedCollectionPredicatedCollection.Builder<E>
- 
Field SummaryFields inherited from class org.apache.commons.collections4.collection.PredicatedCollectionpredicate
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedPredicatedQueue(Queue<E> queue, Predicate<? super E> predicate) Constructor that wraps (not copies).
- 
Method SummaryModifier and TypeMethodDescriptionGets the queue being decorated.element()booleanOverride to validate the object being added to ensure it matches the predicate.peek()poll()static <E> PredicatedQueue<E> predicatedQueue(Queue<E> Queue, Predicate<? super E> predicate) Factory method to create a predicated (validating) queue.remove()Methods inherited from class org.apache.commons.collections4.collection.PredicatedCollectionadd, addAll, builder, notNullBuilder, predicatedCollection, validateMethods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecoratorclear, contains, containsAll, isEmpty, iterator, remove, removeAll, removeIf, retainAll, setCollection, size, toArray, toArray, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionaddAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
- 
Constructor Details- 
PredicatedQueueConstructor that wraps (not copies).If there are any elements already in the collection being decorated, they are validated. - Parameters:
- queue- the queue to decorate, must not be null
- predicate- the predicate to use for validation, must not be null
- Throws:
- NullPointerException- if queue or predicate is null
- IllegalArgumentException- if the Queue contains invalid elements
 
 
- 
- 
Method Details- 
predicatedQueuepublic static <E> PredicatedQueue<E> predicatedQueue(Queue<E> Queue, Predicate<? super E> predicate) Factory method to create a predicated (validating) queue.If there are any elements already in the queue being decorated, they are validated. - Type Parameters:
- E- the type of the elements in the queue
- Parameters:
- Queue- the queue to decorate, must not be null
- predicate- the predicate to use for validation, must not be null
- Returns:
- a new predicated queue
- Throws:
- NullPointerException- if queue or predicate is null
- IllegalArgumentException- if the queue contains invalid elements
 
- 
decorated
- 
element
- 
offerOverride to validate the object being added to ensure it matches the predicate.- Specified by:
- offerin interface- Queue<E>
- Parameters:
- object- the object being added
- Returns:
- the result of adding to the underlying queue
- Throws:
- IllegalArgumentException- if the add is invalid
 
- 
peek
- 
poll
- 
remove
 
-