java.lang.Object
org.eclipse.persistence.jpa.jpql.utility.CollectionTools

public final class CollectionTools extends Object
This utility class provides utility methods related to collections, iterators and arrays.

Provisional API: This interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.

Since:
2.4
Version:
2.5
  • Method Details

    • addAll

      public static <T extends Collection<E>, E> T addAll(T collection, E[] array)
      Adds to the given Collection the items contained in the array.
      Type Parameters:
      T - The type of the collection
      E - The type of the element
      Parameters:
      collection - The Collection that will receive the items returned by the Iterator
      array - The array to add to the given Collection
      Returns:
      The given Collection
      Since:
      2.4.1
    • addAll

      public static <T extends Collection<E>, E> T addAll(T collection, Iterable<? extends E> iterable)
      Adds to the given Collection the items contained in the Iterable.
      Type Parameters:
      T - The type of the collection
      E - The type of the element
      Parameters:
      collection - The Collection that will receive the items returned by the Iterator
      iterable - The Iterable to add to the given Collection
      Returns:
      The given Collection
      Since:
      2.5
    • addAll

      public static <T extends Collection<E>, E> T addAll(T collection, Iterator<? extends E> iterator)
      Adds to the given Collection the items returned by the given Iterator.
      Type Parameters:
      T - The type of the collection
      E - The type of the element
      Parameters:
      collection - The Collection that will receive the items returned by the Iterator
      iterator - The Iterator that will return the items to add to the Collection
      Returns:
      The given Collection
    • array

      public static <T> T[] array(Class<T> componentType, Iterable<? extends T> iterable)
      Creates a new array and adds the items returned by the given Iterable.
      Parameters:
      componentType - The type of the array
      iterable - The Iterable that will iterate over the collection of items to add into the new array in the same order they are returned
      Returns:
      A new array filled with the items returned by the given iterator
      Since:
      2.5
    • array

      public static <T> T[] array(Class<T> componentType, Iterator<? extends T> iterator)
      Creates a new array and adds the items returned by the given Iterator.
      Parameters:
      componentType - The type of the array
      iterator - The Iterator that will iterate over the collection of items to add into the new array in the same order they are returned
      Returns:
      A new array filled with the items returned by the given iterator
    • list

      @SafeVarargs public static <E> List<E> list(E... array)
      Returns a list corresponding to the specified array. Unlike Arrays.asList(Object[]), the list is modifiable and is not backed by the array.
      Parameters:
      array - The array to convert into a List
      Returns:
      An instance of a List containing the elements of the given array
      Since:
      2.5
    • list

      public static <T> List<T> list(Iterator<? extends T> iterator)
      Creates a new List and adds the items returned by the given ListIterator.
      Parameters:
      iterator - The ListIterator to iterate over items to add into a list in the same order they are returned
      Returns:
      A new List