org.apache.commons.collections4
Class QueueUtils

java.lang.Object
  extended by org.apache.commons.collections4.QueueUtils

public class QueueUtils
extends Object

Provides utility methods and decorators for Queue instances.

Since:
4.0
Version:
$Id: QueueUtils.java 1477779 2013-04-30 18:55:24Z tn $

Field Summary
static Queue<Object> EMPTY_QUEUE
          An empty unmodifiable queue.
 
Method Summary
static
<E> Queue<E>
emptyQueue()
          Get an empty Queue.
static
<E> Queue<E>
predicatedQueue(Queue<E> queue, Predicate<? super E> predicate)
          Returns a predicated (validating) queue backed by the given queue.
static
<E> Queue<E>
transformingQueue(Queue<E> queue, Transformer<? super E,? extends E> transformer)
          Returns a transformed queue backed by the given queue.
static
<E> Queue<E>
unmodifiableQueue(Queue<E> queue)
          Returns an unmodifiable queue backed by the given queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_QUEUE

public static final Queue<Object> EMPTY_QUEUE
An empty unmodifiable queue.

Method Detail

unmodifiableQueue

public static <E> Queue<E> unmodifiableQueue(Queue<E> queue)
Returns an unmodifiable queue backed by the given queue.

Type Parameters:
E - the type of the elements in the queue
Parameters:
queue - the queue to make unmodifiable, must not be null
Returns:
an unmodifiable queue backed by that queue
Throws:
IllegalArgumentException - if the Queue is null

predicatedQueue

public static <E> Queue<E> predicatedQueue(Queue<E> queue,
                                           Predicate<? super E> predicate)
Returns a predicated (validating) queue backed by the given queue.

Only objects that pass the test in the given predicate can be added to the queue. Trying to add an invalid object results in an IllegalArgumentException. It is important not to use the original queue after invoking this method, as it is a backdoor for adding invalid objects.

Type Parameters:
E - the type of the elements in the queue
Parameters:
queue - the queue to predicate, must not be null
predicate - the predicate used to evaluate new elements, must not be null
Returns:
a predicated queue
Throws:
IllegalArgumentException - if the Queue or Predicate is null

transformingQueue

public static <E> Queue<E> transformingQueue(Queue<E> queue,
                                             Transformer<? super E,? extends E> transformer)
Returns a transformed queue backed by the given queue.

Each object is passed through the transformer as it is added to the Queue. It is important not to use the original queue after invoking this method, as it is a backdoor for adding untransformed objects.

Existing entries in the specified queue will not be transformed. If you want that behaviour, see TransformedQueue.transformedQueue(java.util.Queue, org.apache.commons.collections4.Transformer).

Type Parameters:
E - the type of the elements in the queue
Parameters:
queue - the queue to predicate, must not be null
transformer - the transformer for the queue, must not be null
Returns:
a transformed queue backed by the given queue
Throws:
IllegalArgumentException - if the Queue or Transformer is null

emptyQueue

public static <E> Queue<E> emptyQueue()
Get an empty Queue.

Type Parameters:
E - the type of the elements in the queue
Returns:
an empty Queue


Copyright © 2001–2013 The Apache Software Foundation. All rights reserved.