Package org.eclipse.handly.util

# Class ArrayUtil

java.lang.Object
org.eclipse.handly.util.ArrayUtil

public class ArrayUtil extends Object
Provides static utility methods for manipulating arrays. These utilities supplement those found in `Arrays`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T, C extends Collection<? super T>>
  C`
  `collectMatching(T[] a, Predicate<? super T> p, C c)`
  Appends all of the elements in the given array that match the given predicate to the end of the given collection, in the order they follow in the array.
  `static <T> List<T>`
  `concat(T[] a, Collection<? extends T> b)`
  Returns a list that represents the concatenation of the given collection to the end of the given array.
  `static boolean`
  `contains(Object[] a, Object o)`
  Returns whether the given array contains the given element.
  `static <T> boolean`
  `containsMatching(T[] a, Predicate<? super T> p)`
  Returns whether the given array contains an element matching the given predicate.
  `static <T> List<T>`
  `elementsOfType(Object[] a, Class<? extends T>... types)`
  Returns a list of all of the elements in the given array that have any of the given types, in the order the elements follow in the given array.
  `static boolean`
  `hasElementsNotOfType(Object[] a, Class<?>... types)`
  Returns whether the given array contains an element that has none of the given types.
  `static boolean`
  `hasElementsOfType(Object[] a, Class<?>... types)`
  Returns whether the given array contains an element that has any of the given types.
  `static boolean`
  `hasOnlyElementsOfType(Object[] a, Class<?>... types)`
  Returns whether all of the elements in the given array have any of the given types.
  `static int`
  `indexOf(Object[] a, Object o)`
  Returns the index of the first occurrence of the given element in the given array, or -1 if the array does not contain the element.
  `static <T> int`
  `indexOfMatching(T[] a, Predicate<? super T> p)`
  Returns the index of the first occurrence of an element matching the given predicate in the given array, or -1 if the array does not contain an element matching the predicate.
  `static int`
  `lastIndexOf(Object[] a, Object o)`
  Returns the index of the last occurrence of the given element in the given array, or -1 if the array does not contain the element.
  `static <T> int`
  `lastIndexOfMatching(T[] a, Predicate<? super T> p)`
  Returns the index of the last occurrence of an element matching the given predicate in the given array, or -1 if the array does not contain an element matching the predicate.
  `static <T> Set<T>`
  `setMinus(T[] a, Collection<?> b)`
  Returns a set of elements that are present in the given array but are absent in the given collection.
  `static <T> Set<T>`
  `union(T[] a, Collection<? extends T> b)`
  Returns a set of elements that are present in either the given array or the given collection.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### contains

    public static boolean contains(Object[] a, Object o)
    Returns whether the given array contains the given element. More formally, returns `true` iff the array contains at least one element `e` such that `Objects.equals(e, o)`.
    Parameters:
      `a` - the array (not `null`)
      `o` - the element whose presence in the given array is to be tested (may be `null`)
    Returns:
      `true` if the given array contains the given element, and `false` otherwise

  - ### indexOf

    public static int indexOf(Object[] a, Object o)
    Returns the index of the first occurrence of the given element in the given array, or -1 if the array does not contain the element. More formally, returns the lowest index `i` such that `Objects.equals(o, a[i])`, or -1 if there is no such index.
    Parameters:
      `a` - the array (not `null`)
      `o` - the element to search for in the given array (may be `null`)
    Returns:
      the index of the first occurrence of the given element in the given array, or -1 if the array does not contain the element

  - ### lastIndexOf

    public static int lastIndexOf(Object[] a, Object o)
    Returns the index of the last occurrence of the given element in the given array, or -1 if the array does not contain the element. More formally, returns the highest index `i` such that `Objects.equals(o, a[i])`, or -1 if there is no such index.
    Parameters:
      `a` - the array (not `null`)
      `o` - the element to search for in the given array (may be `null`)
    Returns:
      the index of the last occurrence of the given element in the given array, or -1 if the array does not contain the element

  - ### containsMatching

    public static <T> boolean containsMatching(T[] a, Predicate<? super T> p)
    Returns whether the given array contains an element matching the given predicate. More formally, returns `true` iff the array contains at least one element `e` such that `p.test(e)`.
    Parameters:
      `a` - the array (not `null`)
      `p` - the predicate to match (not `null`)
    Returns:
      `true` if the given array contains an element matching the given predicate, and `false` otherwise

  - ### indexOfMatching

    public static <T> int indexOfMatching(T[] a, Predicate<? super T> p)
    Returns the index of the first occurrence of an element matching the given predicate in the given array, or -1 if the array does not contain an element matching the predicate. More formally, returns the lowest index `i` such that `p.test(a[i])`, or -1 if there is no such index.
    Parameters:
      `a` - the array (not `null`)
      `p` - the predicate to match (not `null`)
    Returns:
      the index of the first occurrence of an element matching the given predicate in the given array, or -1 if the array does not contain an element matching the predicate

  - ### lastIndexOfMatching

    public static <T> int lastIndexOfMatching(T[] a, Predicate<? super T> p)
    Returns the index of the last occurrence of an element matching the given predicate in the given array, or -1 if the array does not contain an element matching the predicate. More formally, returns the highest index `i` such that `p.test(a[i])`, or -1 if there is no such index.
    Parameters:
      `a` - the array (not `null`)
      `p` - the predicate to match (not `null`)
    Returns:
      the index of the last occurrence of an element matching the given predicate in the given array, or -1 if the array does not contain an element matching the predicate

  - ### collectMatching

    public static <T, C extends Collection<? super T>> C collectMatching(T[] a, Predicate<? super T> p, C c)
    Appends all of the elements in the given array that match the given predicate to the end of the given collection, in the order they follow in the array.
    Parameters:
      `a` - the array (not `null`)
      `p` - the predicate to match (not `null`)
      `c` - the collection to add matching elements to (not `null`)
    Returns:
      the given collection instance, `c`

  - ### elementsOfType

    @SafeVarargs public static <T> List<T> elementsOfType(Object[] a, Class<? extends T>... types)
    Returns a list of all of the elements in the given array that have any of the given types, in the order the elements follow in the given array. Clients are free to modify the returned list.
    Parameters:
      `a` - the array (not `null`)
      `types` - at least one type (each type not `null`)
    Returns:
      a list of all of the elements in the given array that have any of the given types (never `null`)

  - ### hasElementsOfType

    public static boolean hasElementsOfType(Object[] a, Class<?>... types)
    Returns whether the given array contains an element that has any of the given types.
    Parameters:
      `a` - the array (not `null`)
      `types` - at least one type (each type not `null`)
    Returns:
      `true` if the given array contains an element that has any of the given types, and `false` otherwise

  - ### hasElementsNotOfType

    public static boolean hasElementsNotOfType(Object[] a, Class<?>... types)
    Returns whether the given array contains an element that has none of the given types.
    Parameters:
      `a` - the array (not `null`)
      `types` - at least one type (each type not `null`)
    Returns:
      `true` if the given array contains an element that has none of the given types, and `false` otherwise

  - ### hasOnlyElementsOfType

    public static boolean hasOnlyElementsOfType(Object[] a, Class<?>... types)
    Returns whether all of the elements in the given array have any of the given types.
    Parameters:
      `a` - the array (not `null`)
      `types` - at least one type (each type not `null`)
    Returns:
      `true` if all of the elements in the given array have any of the given types, and `false` otherwise

  - ### concat

    public static <T> List<T> concat(T[] a, Collection<? extends T> b)
    Returns a list that represents the concatenation of the given collection to the end of the given array. Clients are free to modify the returned list.
    Parameters:
      `a` - the array (not `null`)
      `b` - the collection that is concatenated to the end of the given array (not `null`)
    Returns:
      a list that represents the concatenation (never `null`)

  - ### union

    public static <T> Set<T> union(T[] a, Collection<? extends T> b)
    Returns a set of elements that are present in either the given array or the given collection. Effectively, models the mathematical set-theoretic union operation. The returned set has predictable iteration order determined by those of the given array and the given collection. Clients are free to modify the returned set.
    Parameters:
      `a` - the array to "add" elements to (not `null`)
      `b` - the collection of elements to "add" (not `null`)
    Returns:
      a set of elements that are present in either the given array or the given collection (never `null`)

  - ### setMinus

    public static <T> Set<T> setMinus(T[] a, Collection<?> b)
    Returns a set of elements that are present in the given array but are absent in the given collection. Effectively, models the mathematical set-theoretic difference operation. The returned set has predictable iteration order determined by that of the given array. Clients are free to modify the returned set.
    Parameters:
      `a` - the array to "subtract" elements from (not `null`)
      `b` - the collection of elements to "subtract" (not `null`)
    Returns:
      a set of elements that are present in the given array but are absent in the given collection (never `null`)