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

public Class TransformedCollection<E>

extends AbstractCollectionDecorator<E>
Class Inheritance
Known Direct Subclasses
org.apache.commons.collections4.list.TransformedList, org.apache.commons.collections4.queue.TransformedQueue, org.apache.commons.collections4.set.TransformedSet, org.apache.commons.collections4.bag.TransformedBag
Type Parameters
<E>
the type of the elements in the collection
Imports
java.util.ArrayList, .Collection, .List, org.apache.commons.collections4.Transformer

Decorates another Collection to transform objects that are added.

The add 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.

This class is Serializable from Commons Collections 3.1.

Since
3.0

Field Summary

Modifier and TypeField and Description
private static final long
protected final Transformer<? super E, ? extends E>
transformer

The transformer to use

Constructor Summary

AccessConstructor and Description
protected
TransformedCollection(final Collection<E>
the collection to decorate, must not be null
coll
,
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 boolean
add(final E
element whose presence in this collection is to be ensured
object
)

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

Implements java.util.Collection.add.

Ensures that this collection contains the specified element (optional operation).
public boolean
addAll(final Collection<? extends E>
collection containing elements to be added to this collection
coll
)

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

Implements java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation).
protected E

Returns:

a transformed object
transform
(final E
the object to transform
object
)

Transforms an object.

protected Collection<E>

Returns:

a transformed object
transform
(final Collection<? extends E>
the collection to transform
coll
)

Transforms a collection.

public static <
the type of the elements in the collection
E
>
TransformedCollection<E>

Returns:

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

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

public static <
the type of the elements in the collection
E
>
TransformedCollection<E>

Returns:

a new transformed collection
transformingCollection
(final Collection<E>
the collection to decorate, must not be null
coll
,
final Transformer<? super E, ? extends E>
the transformer to use for conversion, must not be null
transformer
)

Factory method to create a transforming collection.

Inherited from org.apache.commons.collections4.collection.AbstractCollectionDecorator:
clearcontainscontainsAlldecoratedisEmptyiteratorremoveremoveAllremoveIfretainAllsetCollectionsizetoArraytoArraytoString

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

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

Serialization version

transformerback to summary
protected final Transformer<? super E, ? extends E> transformer

The transformer to use

Constructor Detail

TransformedCollectionback to summary
protected TransformedCollection(final Collection<E> coll, final Transformer<? super E, ? extends E> transformer)

Constructor that wraps (not copies).

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

Parameters
coll:Collection<E>

the collection 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 collection or transformer is null

Method Detail

addback to summary
public boolean add(final E object)

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

Implements java.util.Collection.add.

Doc from java.util.Collection.add.

Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Parameters
object:E

element whose presence in this collection is to be ensured

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
addAllback to summary
public boolean addAll(final Collection<? extends E> coll)

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

Implements java.util.Collection.addAll.

Doc from java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.) If the specified collection has a defined encounter order, processing of its elements generally occurs in that order.

Parameters
coll:Collection<? extends E>

collection containing elements to be added to this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
transformback to summary
protected E transform(final E object)

Transforms an object.

The transformer itself may throw an exception if necessary.

Parameters
object:E

the object to transform

Returns:E

a transformed object

transformback to summary
protected Collection<E> transform(final Collection<? extends E> coll)

Transforms a collection.

The transformer itself may throw an exception if necessary.

Parameters
coll:Collection<? extends E>

the collection to transform

Returns:Collection<E>

a transformed object

transformedCollectionback to summary
public static <E> TransformedCollection<E> transformedCollection(final Collection<E> collection, final Transformer<? super E, ? extends E> transformer)

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

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

Parameters
<E>
the type of the elements in the collection
collection:Collection<E>

the collection to decorate, must not be null

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

the transformer to use for conversion, must not be null

Returns:TransformedCollection<E>

a new transformed Collection

Exceptions
NullPointerException:
if collection or transformer is null
Since
4.0
transformingCollectionback to summary
public static <E> TransformedCollection<E> transformingCollection(final Collection<E> coll, final Transformer<? super E, ? extends E> transformer)

Factory method to create a transforming collection.

If there are any elements already in the collection being decorated, they are NOT transformed. Contrast this with transformedCollection(Collection, Transformer).

Parameters
<E>
the type of the elements in the collection
coll:Collection<E>

the collection to decorate, must not be null

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

the transformer to use for conversion, must not be null

Returns:TransformedCollection<E>

a new transformed collection

Exceptions
NullPointerException:
if collection or transformer is null
Since
4.0