Class Lists

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

public abstract class Lists extends Object
Library of constants and combinators for classes implementing List.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <A> List<A>
    concat(List<? extends A> first, List<? extends A> second)
    Returns a list that is a view of two other list concatenated.
    static <A, B> List<B>
    map(Function<? super A,? extends B> fun, List<? extends A> elems)
    Returns a list that is a view of another list with each element transformed by a function.
    static <A> List<A>
    reverse(List<A> list)
    Returns a list that is a view of another list with the element order reversed.
    static <A> List<A>
    snapshot(Collection<? extends A> elems)
    Makes a copy of the current content of a collection.
    static <A, B, C> List<C>
    zip(BiFunction<? super A,? super B,? extends C> fun, List<? extends A> left, List<? extends B> right)
    Returns a list that is a view of two other list with each pair of elements combined by a function.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • reverse

      public static <A> List<A> reverse(List<A> list)
      Returns a list that is a view of another list with the element order reversed.

      Changes to the underlying list are visible through the reversed list, and vice versa.

      Parameters:
      list - a list
      Returns:
      a list that has the same elements as the given list, but in opposite order
    • snapshot

      public static <A> List<A> snapshot(Collection<? extends A> elems)
      Makes a copy of the current content of a collection.

      The copy is an immutable list, and contains all elements that the given collection currently contains, in the order they would be returned by an Iterator.

      Subsequent changes to the given collection will not be reflected in the copy.

      Parameters:
      elems - a collection
      Returns:
      a list that has the same elements as the given collection currently has, in the order of iteration
    • map

      public static <A, B> List<B> map(Function<? super A,? extends B> fun, List<? extends A> elems)
      Returns a list that is a view of another list with each element transformed by a function.

      Changes to the underlying list are visible through the transformed list, but not vice versa; the transformed list is unmodifiable.

      The transformed elements are not stored in memory; they are computed anew on every access. This is only efficient if the transforming function is cheap, or if the list is iterated just once. For reusable transformed lists, consider making a snapshot.

      Parameters:
      fun - the element transformer function
      elems - the list to be transformed
      See Also:
    • concat

      public static <A> List<A> concat(List<? extends A> first, List<? extends A> second)
      Returns a list that is a view of two other list concatenated.

      Changes to the underlying lists are visible through the concatenated list, but not vice versa; the concatenated list is unmodifiable.

      The concatenated elements are not stored contigously in memory; which part an element comes from is determined on every access. This is only efficient if concatenation is not nested too deeply. For quick-access concatenated lists, consider making a snapshot.

      Parameters:
      first - the first list to concatenate
      second - the second list to concatenate
      Returns:
      a list that contains the elements of the first list followed by the elements of the second list
    • zip

      public static <A, B, C> List<C> zip(BiFunction<? super A,? super B,? extends C> fun, List<? extends A> left, List<? extends B> right)
      Returns a list that is a view of two other list with each pair of elements combined by a function.

      Changes to the underlying lists are visible through the combined list, but not vice versa; the combined list is unmodifiable.

      The combined elements are not stored in memory; they are computed anew on every access. This is only efficient if the combining function is cheap, or if the list is iterated just once. For reusable combined lists, consider making a snapshot.

      Parameters:
      fun - the element combiner function
      left - one list to be combined
      right - the other list to be combined
      Throws:
      IllegalArgumentException - if the two given lists are of different sizes
      See Also: