org.apache.commons.collections4.queue

## Class TransformedQueue<E>

- java.lang.Object
- - org.apache.commons.collections4.collection.AbstractCollectionDecorator<E>
  - - org.apache.commons.collections4.collection.TransformedCollection<E>
    - - org.apache.commons.collections4.queue.TransformedQueue<E>

- All Implemented Interfaces:
    Serializable, Iterable<E>, Collection<E>, Queue<E>

      public class TransformedQueue<E>
      extends TransformedCollection<E>
      implements Queue<E>

  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
  Version:
    $Id: TransformedQueue.java 1494280 2013-06-18 20:07:04Z tn $
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from class org.apache.commons.collections4.collection.TransformedCollection

      `transformer`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `TransformedQueue(Queue<E> queue, Transformer<? super E,? extends E> transformer)` Constructor that wraps (not copies).

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `E` | `element()`
    `protected Queue<E>` | `getQueue()` Gets the decorated queue.
    `boolean` | `offer(E obj)`
    `E` | `peek()`
    `E` | `poll()`
    `E` | `remove()`
    `static <E> TransformedQueue<E>` | `transformedQueue(Queue<E> queue, Transformer<? super E,? extends E> transformer)` Factory method to create a transforming queue that will transform existing contents of the specified queue.
    `static <E> TransformedQueue<E>` | `transformingQueue(Queue<E> queue, Transformer<? super E,? extends E> transformer)` Factory method to create a transforming queue.

    - ### Methods inherited from class org.apache.commons.collections4.collection.TransformedCollection

      `add, addAll, transform, transform, transformedCollection, transformingCollection`

    - ### Methods inherited from class org.apache.commons.collections4.collection.AbstractCollectionDecorator

      `clear, contains, containsAll, decorated, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, setCollection, size, toArray, toArray, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.util.Queue

      `add`

    - ### Methods inherited from interface java.util.Collection

      `addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray`

- - ### Constructor Detail

    - #### TransformedQueue

          protected TransformedQueue(Queue<E> queue,
                          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` - the queue to decorate, must not be null
        `transformer` - the transformer to use for conversion, must not be null
      Throws:
        `IllegalArgumentException` - if queue or transformer is null

  - ### Method Detail

    - #### transformingQueue

          public static <E> TransformedQueue<E> transformingQueue(Queue<E> queue,
                                                  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)`.

      Type Parameters:
        `E` - the type of the elements in the queue
      Parameters:
        `queue` - the queue to decorate, must not be null
        `transformer` - the transformer to use for conversion, must not be null
      Returns:
        a new transformed Queue
      Throws:
        `IllegalArgumentException` - if queue or transformer is null

    - #### transformedQueue

          public static <E> TransformedQueue<E> transformedQueue(Queue<E> queue,
                                                 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)`.

      Type Parameters:
        `E` - the type of the elements in the queue
      Parameters:
        `queue` - the queue to decorate, must not be null
        `transformer` - the transformer to use for conversion, must not be null
      Returns:
        a new transformed Queue
      Throws:
        `IllegalArgumentException` - if queue or transformer is null
      Since:
        4.0

    - #### getQueue

          protected Queue<E> getQueue()

      Gets the decorated queue.
      Returns:
        the decorated queue

    - #### offer

          public boolean offer(E obj)

      Specified by:
        `offer` in interface `Queue<E>`

    - #### poll

          public E poll()

      Specified by:
        `poll` in interface `Queue<E>`

    - #### peek

          public E peek()

      Specified by:
        `peek` in interface `Queue<E>`

    - #### element

          public E element()

      Specified by:
        `element` in interface `Queue<E>`

    - #### remove

          public E remove()

      Specified by:
        `remove` in interface `Queue<E>`

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