Top Description Fields Constructors Methods
org.apache.commons.collections4.queue

public Class PredicatedQueue<E>

extends PredicatedCollection<E>
implements Queue<E>
Class Inheritance
All Implemented Interfaces
java.util.Queue, java.util.Collection, java.lang.Iterable
Type Parameters
<E>
the type of elements held in this queue
Imports
java.util.Queue, org.apache.commons.collections4.Predicate, org.apache.commons.collections4.collection.PredicatedCollection

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

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from org.apache.commons.collections4.collection.PredicatedCollection:
predicate

Constructor Summary

AccessConstructor 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).

Method Summary

Modifier and TypeMethod and Description
protected Queue<E>

Returns:

the decorated queue
decorated
()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.decorated.

Gets the queue being decorated.
public E
element()

Implements java.util.Queue.element.

Retrieves, but does not remove, the head of this queue.
public boolean

Returns:

the result of adding to the underlying queue
offer
(final E
the object being added
object
)

Implements java.util.Queue.offer.

Override to validate the object being added to ensure it matches the predicate.
public E
peek()

Implements java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
public E
poll()

Implements java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.
public static <
the type of the elements in the queue
E
>
PredicatedQueue<E>

Returns:

a new predicated queue
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
)

Factory method to create a predicated (validating) queue.

public E
remove()

Implements java.util.Queue.remove.

Retrieves and removes the head of this queue.
Inherited from org.apache.commons.collections4.collection.PredicatedCollection:
addaddAllbuildernotNullBuilderpredicatedCollectionvalidate

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.collection.PredicatedCollection.serialVersionUID.

Serialization version

Constructor Detail

PredicatedQueueback 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.

Parameters
queue:Queue<E>

the queue to decorate, must not be null

predicate:Predicate<? super E>

the predicate to use for validation, must not be null

Exceptions
NullPointerException:
if queue or predicate is null
IllegalArgumentException:
if the Queue contains invalid elements

Method Detail

decoratedback to summary
protected Queue<E> decorated()

Overrides org.apache.commons.collections4.collection.AbstractCollectionDecorator.decorated.

Gets the queue being decorated.

Returns:Queue<E>

the decorated queue

Annotations
@Override
elementback to summary
public E element()

Implements java.util.Queue.element.

Doc from java.util.Queue.element.

Retrieves, but does not remove, the head of this queue. This method differs from peek only in that it throws an exception if this queue is empty.

Returns:E

the head of this queue

Annotations
@Override
offerback to summary
public boolean offer(final E object)

Implements java.util.Queue.offer.

Override to validate the object being added to ensure it matches the predicate.

Parameters
object:E

the object being added

Returns:boolean

the result of adding to the underlying queue

Annotations
@Override
Exceptions
IllegalArgumentException:
if the add is invalid
peekback to summary
public E peek()

Implements java.util.Queue.peek.

Doc from java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Returns:E

the head of this queue, or null if this queue is empty

Annotations
@Override
pollback to summary
public E poll()

Implements java.util.Queue.poll.

Doc from java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Returns:E

the head of this queue, or null if this queue is empty

Annotations
@Override
predicatedQueueback to summary
public static <E> PredicatedQueue<E> predicatedQueue(final Queue<E> Queue, final 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.

Parameters
<E>
the type of the elements in the queue
Queue:Queue<E>

the queue to decorate, must not be null

predicate:Predicate<? super E>

the predicate to use for validation, must not be null

Returns:PredicatedQueue<E>

a new predicated queue

Exceptions
NullPointerException:
if queue or predicate is null
IllegalArgumentException:
if the queue contains invalid elements
removeback to summary
public E remove()

Implements java.util.Queue.remove.

Doc from java.util.Queue.remove.

Retrieves and removes the head of this queue. This method differs from poll() only in that it throws an exception if this queue is empty.

Returns:E

the head of this queue

Annotations
@Override