java.lang.Object
no.mnemonic.commons.utilities.collections.ListUtils

public class ListUtils extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> List<T>
    addToList(List<T> list, T element)
    Adds an element to a list unless the element is null.
    static <T> List<T>
    concatenate(List<T>... lists)
    Concatenates multiple lists into one new list.
    static <T> List<T>
    list(Collection<T> collection)
    Creates a list from another collection.
    static <T, V> List<V>
    list(Collection<T> collection, Function<T,V> mapping)
    Creates a list from another collection using a mapping function converting all values.
    static <T, V> List<V>
    list(Function<T,V> mapping, T... values)
    Creates a list from its arguments using a mapping function converting all values.
    static <T> List<T>
    list(Iterator<T> iterator)
    Creates a list from an iterator.
    static <T, V> List<V>
    list(Iterator<T> iterator, Function<T,V> mapping)
    Creates a list from an iterator using a mapping function converting all values.
    static <T> List<T>
    list(T... values)
    Creates a list from its arguments.

    Methods inherited from class java.lang.Object

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

    • list

      @SafeVarargs public static <T> List<T> list(T... values)
      Creates a list from its arguments.
      Type Parameters:
      T - Type of value parameters.
      Parameters:
      values - Values to be added to the list.
      Returns:
      A list containing all values.
    • list

      public static <T> List<T> list(Iterator<T> iterator)
      Creates a list from an iterator.
      Type Parameters:
      T - Type of iterator values.
      Parameters:
      iterator - An iterator which values are added to the list.
      Returns:
      A list containing all values supplied by the given iterator.
    • list

      public static <T> List<T> list(Collection<T> collection)
      Creates a list from another collection.
      Type Parameters:
      T - Type of collection values.
      Parameters:
      collection - A collection which values are added to the list.
      Returns:
      A list containing all values contained in the given collection, omitting null elements.
    • list

      @SafeVarargs public static <T, V> List<V> list(Function<T,V> mapping, T... values)
      Creates a list from its arguments using a mapping function converting all values.
      Type Parameters:
      T - Type of value parameters before conversion.
      V - Type of values in the returned list after conversion.
      Parameters:
      mapping - A mapping function applied to all values.
      values - Values to be added to the list.
      Returns:
      A list containing all values converted using the mapping function.
    • list

      public static <T, V> List<V> list(Iterator<T> iterator, Function<T,V> mapping)
      Creates a list from an iterator using a mapping function converting all values.
      Type Parameters:
      T - Type of iterator values before conversion.
      V - Type of values in the returned list after conversion.
      Parameters:
      iterator - An iterator which values are added to the list.
      mapping - A mapping function applied to all values.
      Returns:
      A list containing all values supplied by the given iterator and converted using the mapping function.
    • list

      public static <T, V> List<V> list(Collection<T> collection, Function<T,V> mapping)
      Creates a list from another collection using a mapping function converting all values.
      Type Parameters:
      T - Type of collection values before conversion.
      V - Type of values in the returned list after conversion.
      Parameters:
      collection - A collection which values are added to the list.
      mapping - A mapping function applied to all values.
      Returns:
      A list containing all values contained in the given collection and converted using the mapping function, omitting null elements.
    • addToList

      public static <T> List<T> addToList(List<T> list, T element)
      Adds an element to a list unless the element is null.

      A new list is created if the provided list is null.

      Type Parameters:
      T - Type of elements.
      Parameters:
      list - List to which the element will be added.
      element - Element to add.
      Returns:
      List including added element.
    • concatenate

      @SafeVarargs public static <T> List<T> concatenate(List<T>... lists)
      Concatenates multiple lists into one new list.
      Type Parameters:
      T - Type of list values.
      Parameters:
      lists - Multiple lists which will be concatenated.
      Returns:
      A list containing all values from the given lists.