Class ListUtil


  • public final class ListUtil
    extends java.lang.Object
    This class provides some utility-methods for generic lists.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  ListUtil.Mapper<IN,​OUT>
      this interface just defines one method to convert one object into another.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.List<T> createDefaultValueList​(int size, T defaultValue)
      creates a new list of the given size, containing the same element in every item
      static <T> java.util.List<T> createOneElementList​(T element)
      creates an array list with the one given element.
      static <T> java.util.List<T> createOneElementOrEmptyList​(T element)
      creates an array list with the one given element, or an empty list if the element is null.
      static java.util.List<java.lang.Double> diff​(java.util.List<java.lang.Double> doublesA, java.util.List<java.lang.Double> doublesB)
      returns a list with the values difference values doublesA-doublesB
      static java.util.List<java.lang.Double> divide​(java.util.List<java.lang.Double> doublesA, java.util.List<java.lang.Double> doublesB)
      performs an element wise devision of the lists (doublesA / doublesB).
      static <IN,​OUT>
      java.util.List<OUT>
      map​(java.util.List<IN> inlist, ListUtil.Mapper<IN,​OUT> mapper)
      converts a list of one tye into a list of another type using the provided mapper
      static java.util.List<java.lang.String> toString​(java.util.List<? extends java.lang.Object> objects)
      this method converts any List to a list of strings.
      • Methods inherited from class java.lang.Object

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

      • map

        public static <IN,​OUT> java.util.List<OUT> map​(java.util.List<IN> inlist,
                                                             ListUtil.Mapper<IN,​OUT> mapper)
        converts a list of one tye into a list of another type using the provided mapper
        Type Parameters:
        IN - the type of the input-list items
        OUT - the type of the output-list items
        Parameters:
        inlist - the list of items to convert
        mapper - the mapper which converts the types
        Returns:
        the new list.
      • toString

        public static java.util.List<java.lang.String> toString​(java.util.List<? extends java.lang.Object> objects)
        this method converts any List to a list of strings.
        Parameters:
        objects - the objects that shall be converted to strings
        Returns:
        the list of strings
      • createOneElementList

        public static <T> java.util.List<T> createOneElementList​(T element)
        creates an array list with the one given element.
        Type Parameters:
        T - the type of objects for the list
        Parameters:
        element - the single element that shall be contained in the new list
        Returns:
        a list containing the given element
      • createOneElementOrEmptyList

        public static <T> java.util.List<T> createOneElementOrEmptyList​(T element)
        creates an array list with the one given element, or an empty list if the element is null.
        Type Parameters:
        T - the type of objects for the list
        Parameters:
        element - the single element that shall be contained in the new list
        Returns:
        a list containing the given element, or an empty list
      • createDefaultValueList

        public static <T> java.util.List<T> createDefaultValueList​(int size,
                                                                   T defaultValue)
        creates a new list of the given size, containing the same element in every item
        Type Parameters:
        T - the type of the list items
        Parameters:
        size - the size of the new list
        defaultValue - the value that shall be contained in all items
        Returns:
        the new list, containing the defaultValue in all items
      • diff

        public static java.util.List<java.lang.Double> diff​(java.util.List<java.lang.Double> doublesA,
                                                            java.util.List<java.lang.Double> doublesB)
        returns a list with the values difference values doublesA-doublesB
        Parameters:
        doublesA - the values from which to subtract
        doublesB - the values which shall be subtracted
        Returns:
        a list of differences
      • divide

        public static java.util.List<java.lang.Double> divide​(java.util.List<java.lang.Double> doublesA,
                                                              java.util.List<java.lang.Double> doublesB)
        performs an element wise devision of the lists (doublesA / doublesB).
        Parameters:
        doublesA - the list of values that act as dividends
        doublesB - the list of values that act as divisors
        Returns:
        element wise doublesA / doublesB