Class CollectionUtils

java.lang.Object
de.iip_ecosphere.platform.support.CollectionUtils

public class CollectionUtils extends Object
Some useful additional collection methods.
Author:
Holger Eichelberger, SSE
  • Constructor Details

    • CollectionUtils

      public CollectionUtils()
  • Method Details

    • toList

      @SafeVarargs public static <T> List<T> toList(T... elements)
      Turns given elements into a list.
      Type Parameters:
      T - the element type
      Parameters:
      elements - the elements
      Returns:
      the list containing all elements
    • toSet

      @SafeVarargs public static <T> Set<T> toSet(T... elements)
      Turns given elements into a list.
      Type Parameters:
      T - the element type
      Parameters:
      elements - the elements
      Returns:
      the list containing all elements
    • addAll

      @SafeVarargs public static <T> List<T> addAll(List<T> list, T... elements)
      Turns given elements to list.
      Type Parameters:
      T - the element type
      Parameters:
      list - the list to be modified as a side effect
      elements - the elements
      Returns:
      the list with all elements added
    • addAll

      @SafeVarargs public static <T> Set<T> addAll(Set<T> set, T... elements)
      Turns given elements to set.
      Type Parameters:
      T - the element type
      Parameters:
      set - the set to be modified as a side effect
      elements - the elements
      Returns:
      the set with all elements added
    • toList

      public static <T> List<T> toList(Iterable<T> iterable)
      Turns the elements in the iterable into a list.
      Type Parameters:
      T - the element type
      Parameters:
      iterable - the iterable
      Returns:
      the list with all elements in iterable
    • toList

      public static <T> List<T> toList(Iterator<T> iterator)
      Turns the elements in the iterator into a list.
      Type Parameters:
      T - the element type
      Parameters:
      iterator - the iterator
      Returns:
      the list with all elements in iterator
    • toList

      public static <T> List<T> toList(Enumeration<T> en)
      Turns the elements in the enumeration into a list.
      Type Parameters:
      T - the element type
      Parameters:
      en - the enumeration
      Returns:
      the list with all elements in en
    • toSet

      public static <T> Set<T> toSet(Iterable<T> iterable)
      Turns the elements in the iterable into a set.
      Type Parameters:
      T - the element type
      Parameters:
      iterable - the iterable
      Returns:
      the set with all elements in iterable
    • toSet

      public static <T> Set<T> toSet(Iterator<T> iterator)
      Turns the elements in the iterator into a set.
      Type Parameters:
      T - the element type
      Parameters:
      iterator - the iterator
      Returns:
      the set with all elements in iterator
    • toSet

      public static <T> Set<T> toSet(Enumeration<T> en)
      Turns the elements in the enumeration into a set.
      Type Parameters:
      T - the element type
      Parameters:
      en - the enumeration
      Returns:
      the set with all elements in en
    • toString

      public static String toString(Collection<?> collection, String leadIn, String leadOut, String separator)
      Turns a collection into a string with configurable lead-in, separator and lead-out.
      Parameters:
      collection - the collection
      leadIn - the lead-in
      leadOut - the lead-out
      separator - the separator
      Returns:
      the string representation
    • toStringSpaceSeparated

      public static String toStringSpaceSeparated(Collection<?> collection)
      Turns a collection into a string with no lead-in, one space as separator and no lead-out.
      Parameters:
      collection - the collection
      Returns:
      the string representation
    • reverse

      public static void reverse(Object[] array)
      Reverses the order of the given array. There is no special handling for multi-dimensional arrays. This method does nothing for a null input array.
      Parameters:
      array - the array to reverse, may be null