Class CollectionViews
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 live view on a given collection that transforms each element by a given function.static <A,B> List <B> Returns a live view on a given list that transforms each element by a given function.static <A,B, C> Map <A, C> Returns a live view on a given map that transforms each entry value by 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 live view on a given collection that transforms each element by a given function.Changes to the backing collection are reflected by the resulting view.
removeoperations through an iterator of the resulting collection are reflected by the backing collection, if allowed. Conversely, mutating iterator operations may indirectly throwUnsupportedOperationExceptionif the backing collections does not allow them.Creating an iterator for the view implies creating an iterator for the underlying collection. Thus view iterators are fail-fast with respect to concurrent modification of the underlying 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
Returns a live view on a given list that transforms each element by a given function.Changes to the backing collection are reflected by the resulting view.
removeoperations through the iterator of the resulting collection are reflected by the backing collection, if allowed.addandsetoperations through a list iterator are forbidden. Conversely, mutating iterator operations may indirectly throwUnsupportedOperationExceptionif the backing collections does not allow them.Creating an iterator for the view implies creating an iterator for the underlying collection. Thus view iterators are fail-fast with respect to concurrent modification of the underlying 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 - Since:
- 1.3
-
map
Returns a live view on a given map that transforms each entry value by a given function.Changes to the backing map are reflected by the resulting view.
removeoperations through an entry set iterator of the resulting map are reflected by the backing map, if allowed.setValueoperations on entries of the view are forbidden. Conversely, mutating iterator operations may throwUnsupportedOperationExceptionif the backing map does not allow them.Creating an iterator for the view implies creating an iterator for the entry set of the underlying map. Thus view iterators are fail-fast with respect to concurrent modification of the underlying map.
- 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
-