Class CollectionUtils

java.lang.Object
org.jppf.utils.collections.CollectionUtils

public final class CollectionUtils extends Object
This class provides a set of utility methods for manipulating and converting collections and arrays.
Author:
Laurent Cohen
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T[]
    array(T... elts)
    Return the parameters as an array.
    static <T> T[]
    concatArrays(Class<T> clazz, T[]... arrays)
    Concatenate a set of array into a single array.
    static <T> T[]
    concatArrays(T[]... arrays)
    Concatenate a set of array into a single array.
    static <T, U> String
    Format a string with size information about a map whose values are lists of elements.
    static <T> List<T>
    getAllElements(List<T> source, int start, int size)
    Generate a list that contains the specified number of elements of the specified list, starting at the specified position in the specified list.
    static <T> List<T>
    list(T... array)
    Convert an array into a List.
    static Object[]
    objects(Object... elts)
    Return the parameters as an array of Objects.
    static <K, V> String
    Print the content of a collection map in an easily readable way.
    static <T> Set<T>
    set(T... array)
    Convert an array into a Set.
    static <T> Set<T>
    setOf(Class<T> clazz, T... array)
    Convert an array into a Set.

    Methods inherited from class java.lang.Object

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

    • set

      @SafeVarargs public static <T> Set<T> set(T... array)
      Convert an array into a Set.
      Type Parameters:
      T - the type of the elements in the array.
      Parameters:
      array - the array to convert.
      Returns:
      a set of elements with the same type as that of the array element type.
    • setOf

      @SafeVarargs public static <T> Set<T> setOf(Class<T> clazz, T... array)
      Convert an array into a Set.
      Type Parameters:
      T - the type of the elements in the array.
      Parameters:
      clazz - the class of the elements of the set to produce.
      array - the array to convert.
      Returns:
      a set of elements with the same type as that of the array element type.
    • list

      @SafeVarargs public static <T> List<T> list(T... array)
      Convert an array into a List.
      Type Parameters:
      T - the type of the elements in the array.
      Parameters:
      array - the array to convert.
      Returns:
      a list of elements with the same type as that of the array element type.
    • concatArrays

      public static <T> T[] concatArrays(T[]... arrays)
      Concatenate a set of array into a single array.
      Type Parameters:
      T - the element type of the arrays to concatenate.
      Parameters:
      arrays - the arrays to concatenate.
      Returns:
      an array whose size is the sum of the sizes of all the input arrays, and whose elements are all the elements found in all the input arrays.
    • concatArrays

      public static <T> T[] concatArrays(Class<T> clazz, T[]... arrays)
      Concatenate a set of array into a single array.
      Type Parameters:
      T - the element type of the arrays to concatenate.
      Parameters:
      clazz - the class of the elements of the array.
      arrays - the arrays to concatenate.
      Returns:
      an array whose size is the sum of the sizes of all the input arrays, and whose elements are all the elements found in all the input arrays.
    • formatSizeMapInfo

      public static <T, U> String formatSizeMapInfo(String name, CollectionMap<T,U> map)
      Format a string with size information about a map whose values are lists of elements.
      Type Parameters:
      T - the type of the keys in the map.
      U - the type of the values in the map.
      Parameters:
      name - an arbitrary name given to the map.
      map - the map from which to get size information.
      Returns:
      a string containing information about the number of elements in the map.
    • getAllElements

      public static <T> List<T> getAllElements(List<T> source, int start, int size)
      Generate a list that contains the specified number of elements of the specified list, starting at the specified position in the specified list.
      Type Parameters:
      T - the type of the elements in the list.
      Parameters:
      source - the list from which to get the elements.
      start - the start position in the source list.
      size - the number of elements to get from the source list.
      Returns:
      the resulting list.
    • array

      @SafeVarargs public static <T> T[] array(T... elts)
      Return the parameters as an array.
      Type Parameters:
      T - the ytpe of the elements in the array. Inferred as the common supertype of all the elements.
      Parameters:
      elts - the elements of the array.
      Returns:
      an array of the specified type.
    • objects

      public static Object[] objects(Object... elts)
      Return the parameters as an array of Objects.
      Parameters:
      elts - the elements of the array.
      Returns:
      an array of Object instances.
    • prettyPrint

      public static <K, V> String prettyPrint(CollectionMap<K,V> map)
      Print the content of a collection map in an easily readable way.
      Type Parameters:
      K - the type of the keys in the map.
      V - the type of the values in the map.
      Parameters:
      map - the map to print.
      Returns:
      a string with the map elements properly indented and formatted.