Class CollectionViews

java.lang.Object
eu.bandm.tools.util.java.CollectionViews

public abstract class CollectionViews extends Object
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 Type
    Method
    Description
    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.
    static <A, B> List<B>
    map(Function<? super A,? extends B> fun, List<? extends A> things)
     
    static <A, B, C> Map<A,C>
    map(Function<? super B,? extends C> fun, Map<A,B> things)
    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>
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 elements
      B - the type of transformed elements
      Parameters:
      fun - the transformer function
      things - the collection to transform
      Returns:
      an collection that has, for each current element of things, a corresponding element transformed by fun
    • map

      public static <A, B> List<B> map(Function<? super A,? extends B> fun, List<? extends A> things)
      Since:
      1.3
    • map

      public static <A, B, C> Map<A,C> map(Function<? super B,? extends C> fun, Map<A,B> things)
      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 keys
      B - the type of given values
      C - the type of transformed values
      Parameters:
      fun - the transformer function
      things - the map to transform
      Returns:
      an unmodifiable map (beside removes) that has, for each current value of things, a corresponding value ad-hoc transformed by fun, for the same key
    • mapValue

      public static <A, B, C> Map.Entry<A,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 key
      B - the type of the given value
      C - the type of the transformed value
      Parameters:
      fun - the transformer function
      e - a map entry
      Returns:
      a map entry that has the same key as e and a value resulting from applying fun to the value of e