Class CollectionUtils

java.lang.Object
org.hisp.dhis.util.CollectionUtils

public class CollectionUtils extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> List<T>
    asList(T[] array)
    Converts the given array to an ArrayList.
    static <T> T
    firstMatch(Collection<T> collection, Predicate<T> predicate)
    Returns the first matching item in the given collection based on the given predicate.
    static <T> T
    get(List<T> list, int index)
    Returns the item at the given index in the given list.
    static <T> List<T>
    list(Collection<T> collection, Predicate<T> predicate)
    Returns a new mutable list of the items in the given collection which match the given predicate.
    static <T> List<T>
    list(T... items)
    Returns an immutable list containing the given items.
    static <T> List<T>
    mutableList(T... items)
    Returns a mutable list containing the given items.
    static <T> Set<T>
    mutableSet(T... items)
    Returns a mutable set containing the given items.
    static <T> boolean
    notEmpty(Collection<T> collection)
    Indicates if the given collection is not null and not empty.
    static <T> Set<T>
    set(T... items)
    Returns an immutable set containing the given items.

    Methods inherited from class java.lang.Object

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

    • CollectionUtils

      public CollectionUtils()
  • Method Details

    • set

      @SafeVarargs public static <T> Set<T> set(T... items)
      Returns an immutable set containing the given items. Accepts null items.
      Type Parameters:
      T - type.
      Parameters:
      items - the items.
      Returns:
      an immutable set.
    • mutableSet

      @SafeVarargs public static <T> Set<T> mutableSet(T... items)
      Returns a mutable set containing the given items. Accepts null items.
      Type Parameters:
      T - type.
      Parameters:
      items - the items.
      Returns:
      an immutable set.
    • list

      @SafeVarargs public static <T> List<T> list(T... items)
      Returns an immutable list containing the given items. Accepts null items.
      Type Parameters:
      T - type.
      Parameters:
      items - the items.
      Returns:
      an immutable list.
    • mutableList

      @SafeVarargs public static <T> List<T> mutableList(T... items)
      Returns a mutable list containing the given items. Accepts null items.
      Type Parameters:
      T - type.
      Parameters:
      items - the items.
      Returns:
      an immutable list.
    • asList

      public static <T> List<T> asList(T[] array)
      Converts the given array to an ArrayList.
      Type Parameters:
      T - type.
      Parameters:
      array - the array.
      Returns:
      a list.
    • firstMatch

      public static <T> T firstMatch(Collection<T> collection, Predicate<T> predicate)
      Returns the first matching item in the given collection based on the given predicate. Returns null if no match is found.
      Type Parameters:
      T - type.
      Parameters:
      collection - the collection.
      predicate - the predicate.
      Returns:
      the first matching item, or null if no match is found.
    • list

      public static <T> List<T> list(Collection<T> collection, Predicate<T> predicate)
      Returns a new mutable list of the items in the given collection which match the given predicate.
      Type Parameters:
      T - type.
      Parameters:
      collection - the collection.
      predicate - the predicate.
      Returns:
      a new mutable list.
    • notEmpty

      public static <T> boolean notEmpty(Collection<T> collection)
      Indicates if the given collection is not null and not empty.
      Type Parameters:
      T - type.
      Parameters:
      collection - the collection.
      Returns:
      true if the given collection is not null and not empty.
    • get

      public static <T> T get(List<T> list, int index)
      Returns the item at the given index in the given list. Returns null if the index is out of bounds.
      Type Parameters:
      T -
      Parameters:
      list - the list.
      index - the index.
      Returns:
      an item or null.