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

public Class TransformedQueue<E>

extends TransformedCollection<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.Transformer, org.apache.commons.collections4.collection.TransformedCollection

Decorates another Queue to transform objects that are added.

The add/offer methods are affected by this class. Thus objects must be removed or searched for using their transformed form. For example, if the transformation converts Strings to Integers, you must use the Integer form to remove objects.

Since
4.0

Field Summary

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

Constructor Summary

AccessConstructor and Description
protected
TransformedQueue(final Queue<E>
the queue to decorate, must not be null
queue
,
final Transformer<? super E, ? extends E>
the transformer to use for conversion, must not be null
transformer
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
public E
element()

Implements java.util.Queue.element.

Retrieves, but does not remove, the head of this queue.
protected Queue<E>

Returns:

the decorated queue
getQueue
()

Gets the decorated queue.

public boolean
offer(final E
the element to add
obj
)

Implements java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
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 E
remove()

Implements java.util.Queue.remove.

Retrieves and removes the head of this queue.
public static <
the type of the elements in the queue
E
>
TransformedQueue<E>

Returns:

a new transformed Queue
transformedQueue
(final Queue<E>
the queue to decorate, must not be null
queue
,
final Transformer<? super E, ? extends E>
the transformer to use for conversion, must not be null
transformer
)

Factory method to create a transforming queue that will transform existing contents of the specified queue.

public static <
the type of the elements in the queue
E
>
TransformedQueue<E>

Returns:

a new transformed Queue
transformingQueue
(final Queue<E>
the queue to decorate, must not be null
queue
,
final Transformer<? super E, ? extends E>
the transformer to use for conversion, must not be null
transformer
)

Factory method to create a transforming queue.

Inherited from org.apache.commons.collections4.collection.TransformedCollection:
addaddAlltransformtransformtransformedCollectiontransformingCollection

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

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

Serialization version

Constructor Detail

TransformedQueueback to summary
protected TransformedQueue(final Queue<E> queue, final Transformer<? super E, ? extends E> transformer)

Constructor that wraps (not copies).

If there are any elements already in the queue being decorated, they are NOT transformed.

Parameters
queue:Queue<E>

the queue to decorate, must not be null

transformer:Transformer<? super E, ? extends E>

the transformer to use for conversion, must not be null

Exceptions
NullPointerException:
if queue or transformer is null

Method Detail

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
getQueueback to summary
protected Queue<E> getQueue()

Gets the decorated queue.

Returns:Queue<E>

the decorated queue

offerback to summary
public boolean offer(final E obj)

Implements java.util.Queue.offer.

Doc from java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. When using a capacity-restricted queue, this method is generally preferable to add, which can fail to insert an element only by throwing an exception.

Parameters
obj:E

the element to add

Returns:boolean

true if the element was added to this queue, else false

Annotations
@Override
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
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
transformedQueueback to summary
public static <E> TransformedQueue<E> transformedQueue(final Queue<E> queue, final Transformer<? super E, ? extends E> transformer)

Factory method to create a transforming queue that will transform existing contents of the specified queue.

If there are any elements already in the queue being decorated, they will be transformed by this method. Contrast this with transformingQueue(Queue, Transformer).

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

the queue to decorate, must not be null

transformer:Transformer<? super E, ? extends E>

the transformer to use for conversion, must not be null

Returns:TransformedQueue<E>

a new transformed Queue

Exceptions
NullPointerException:
if queue or transformer is null
Since
4.0
transformingQueueback to summary
public static <E> TransformedQueue<E> transformingQueue(final Queue<E> queue, final Transformer<? super E, ? extends E> transformer)

Factory method to create a transforming queue.

If there are any elements already in the queue being decorated, they are NOT transformed. Contrast this with transformedQueue(Queue, Transformer).

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

the queue to decorate, must not be null

transformer:Transformer<? super E, ? extends E>

the transformer to use for conversion, must not be null

Returns:TransformedQueue<E>

a new transformed Queue

Exceptions
NullPointerException:
if queue or transformer is null