Package eu.bandm.tools.util.java
Class CollectionViews
java.lang.Object
eu.bandm.tools.util.java.CollectionViews
Library of view collections, which allow a transformed access to
a collection.
These features should not be used deeply nested, because the
freqency and time of the evaluation of the contained operations
soon may appear confusing.
When a collection shall be processed element by element,
the genuine Java streams framework
is often preferable.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <A,B> Collection <B> map(Function<? super A, ? extends B> fun, Collection<? extends A> things) Returns a life view on a given collection that transforms each element by a given function.static <A,B> List <B> static <A,B, C> Map <A, C> Returns a life view on a given map that transforms for each key the value with a given function.static <A,B, C> Map.Entry <A, C> Returns a new map entry with an immutable value from the transformed value of the given entry.
-
Method Details
-
map
public static <A,B> Collection<B> map(Function<? super A, ? extends B> fun, Collection<? extends A> things) Returns a life view on a given collection that transforms each element by a given function.Changes to the backing collection are reflected by the resulting view. Removes through the iterator of the resulting collection are reflected by the backing collection.
- Type Parameters:
A- the type of given elementsB- the type of transformed elements- Parameters:
fun- the transformer functionthings- the collection to transform- Returns:
- an collection that has, for each current element of
things, a corresponding element transformed byfun
-
map
- Since:
- 1.3
-
map
Returns a life view on a given map that transforms for each key the value with a given function.Changes to the backing collection are reflected by the resulting view. Removes through the iterator of the resulting collection are reflected by the backing collection. Assignments to the values of an entry from the entry set of the resulting collection are not allowed.
- Type Parameters:
A- the type of keysB- the type of given valuesC- the type of transformed values- Parameters:
fun- the transformer functionthings- the map to transform- Returns:
- an unmodifiable map (beside removes)
that has, for each current value of
things, a corresponding value ad-hoc transformed byfun, for the same key
-
mapValue
public static <A,B, Map.Entry<A,C> C> mapValue(Function<? super B, ? extends C> fun, Map.Entry<A, B> e) Returns a new map entry with an immutable value from the transformed value of the given entry.- Type Parameters:
A- the type of the keyB- the type of the given valueC- the type of the transformed value- Parameters:
fun- the transformer functione- a map entry- Returns:
- a map entry that has the same key as
eand a value resulting from applyingfunto the value ofe
-