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:
java.io.Serializable
,java.lang.Iterable<E>
,java.util.Collection<E>
,java.util.Queue<E>
public class PredicatedQueue<E> extends PredicatedCollection<E> implements java.util.Queue<E>
Decorates anotherQueue
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:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.commons.collections4.collection.PredicatedCollection
PredicatedCollection.Builder<E>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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(java.util.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, builder, notNullBuilder, predicatedCollection
-
Methods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecorator
clear, contains, containsAll, isEmpty, iterator, remove, removeAll, removeIf, retainAll, size, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Method Detail
-
predicatedQueue
public static <E> PredicatedQueue<E> predicatedQueue(java.util.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 nullpredicate
- the predicate to use for validation, must not be null- Returns:
- a new predicated queue
- Throws:
java.lang.NullPointerException
- if queue or predicate is nulljava.lang.IllegalArgumentException
- if the queue contains invalid elements
-
offer
public boolean offer(E object)
Override to validate the object being added to ensure it matches the predicate.- Specified by:
offer
in interfacejava.util.Queue<E>
- Parameters:
object
- the object being added- Returns:
- the result of adding to the underlying queue
- Throws:
java.lang.IllegalArgumentException
- if the add is invalid
-
-