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

public Class TransformedSet<E>

extends TransformedCollection<E>
implements Set<E>
Class Inheritance
All Implemented Interfaces
java.util.Set, java.util.Collection, java.lang.Iterable
Known Direct Subclasses
org.apache.commons.collections4.set.TransformedSortedSet
Type Parameters
<E>
the type of the elements in this set
Imports
java.util.Set, org.apache.commons.collections4.Transformer, org.apache.commons.collections4.collection.TransformedCollection

Decorates another Set 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
Inherited from org.apache.commons.collections4.collection.TransformedCollection:
transformer

Constructor Summary

AccessConstructor and Description
protected
TransformedSet(final Set<E>
the set to decorate, must not be null
set
,
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
equals(final Object
object to be compared for equality with this set
object
)

Overrides java.lang.Object.equals.

Implements java.util.Set.equals, java.util.Collection.equals.

Compares the specified object with this set for equality.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Set.hashCode, java.util.Collection.hashCode.

Returns the hash code value for this set.
public static <
the element type
E
>
Set<E>

Returns:

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

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

public static <
the element type
E
>
TransformedSet<E>

Returns:

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

Factory method to create a transforming set.

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

TransformedSetback to summary
protected TransformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer)

Constructor that wraps (not copies).

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

Parameters
set:Set<E>

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

Method Detail

equalsback to summary
public boolean equals(final Object object)

Overrides java.lang.Object.equals.

Implements java.util.Set.equals, java.util.Collection.equals.

Doc from java.util.Set.equals.

Compares the specified object with this set for equality. Returns true if the specified object is also a set, the two sets have the same size, and every member of the specified set is contained in this set (or equivalently, every member of this set is contained in the specified set). This definition ensures that the equals method works properly across different implementations of the set interface.

Parameters
object:Object

object to be compared for equality with this set

Returns:boolean

true if the specified object is equal to this set

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Set.hashCode, java.util.Collection.hashCode.

Doc from java.util.Set.hashCode.

Returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set, where the hash code of a null element is defined to be zero. This ensures that s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for any two sets s1 and s2, as required by the general contract of Object#hashCode.

Returns:int

the hash code value for this set

Annotations
@Override
transformedSetback to summary
public static <E> Set<E> transformedSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer)

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

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

Parameters
<E>
the element type
set:Set<E>

the set to decorate, must not be null

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

the transformer to use for conversion, must not be null

Returns:Set<E>

a new transformed set

Exceptions
NullPointerException:
if set or transformer is null
Since
4.0
transformingSetback to summary
public static <E> TransformedSet<E> transformingSet(final Set<E> set, final Transformer<? super E, ? extends E> transformer)

Factory method to create a transforming set.

If there are any elements already in the set being decorated, they are NOT transformed. Contrast this with transformedSet(Set, Transformer).

Parameters
<E>
the element type
set:Set<E>

the set to decorate, must not be null

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

the transformer to use for conversion, must not be null

Returns:TransformedSet<E>

a new transformed set

Exceptions
NullPointerException:
if set or transformer is null
Since
4.0