The set is immutable, and designed to provide a set implementation that is only used to iterate over its elements. Each element in this set is dynamically generated from the undelying set.
Any method that is not the iterator(), forEach(
Important: Implementations should ensure that the transformed elements still stay unique in the set, as they was in the subject set. Violating this may result in undefined behaviour in some implementations.
An use-case for this kind of set is to create a new Set or Collection with the given elements without pre-allocating the transformed elements beforehand.
Example:
A new set that is created from a set of integers, which have the original integer elements squared.
Set<Integer> ints = ...; Set<Integer> squares = new TreeSet<>(new TransformingSet<Integer, Integer>(ints) { @Override protected Integer transform(Integer e) { return e * e; } });Constructing a collection in this way instead of calling Collection.add(
public | TransformingSet( Creates a new instance with the given set. |
public void | Performs the given action for each element of the Iterable until all elements have been processed or the
action throws an exception. |
public boolean | isEmpty() Returns true if this set contains no elements. |
public Iterator< | iterator() Returns an iterator over the elements in this set. |
public int | size() Returns the number of elements in this set (its cardinality). |
protected abstract E | transform( Transforms the source set element to the actual element. |
From: AbstractSet< |
From: AbstractCollection< |
From: Set< |
From: Object |
From: Collection< |
null
.Iterable
until all elements have been processed or the
action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the
order of iteration (if an iteration order is specified). Exceptions thrown by the action are relayed to the
caller.