Package org.opensearch.core.common.util
Class CollectionUtils
java.lang.Object
org.opensearch.core.common.util.CollectionUtils
Collections-related utility methods.
- Opensearch.internal:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> ArrayList<E> arrayAsArrayList(E... elements) static <E> ArrayList<E> asArrayList(E first, E... other) static <E> ArrayList<E> asArrayList(E first, E second, E... other) static <R,T> Map <R, T> Returns an unmodifiable copy of the given map.eagerPartition(List<E> list, int size) static voidensureNoSelfReferences(Object value, String messageHint) Deeply inspects a Map, Iterable, or Object array looking for references back to itself.static booleanChecks if the given array contains any elements.static <E> booleanisEmpty(Collection<E> collection) Checks if a collection is empty or not.static <E> ArrayList<E> iterableAsArrayList(Iterable<? extends E> elements) static <E> ArrayList<E> newSingletonArrayList(E element) static <T> List<T> Return a rotated view of the given list with the given distance.static <T> voidsortAndDedup(List<T> array, Comparator<T> comparator) In place de-duplicates items in a list Noop if the list is empty or has one item.static int[]toArray(Collection<Integer> ints) Converts a collection of Integers to an array of ints.
-
Constructor Details
-
CollectionUtils
public CollectionUtils()
-
-
Method Details
-
isEmpty
Checks if the given array contains any elements.- Parameters:
array- The array to check- Returns:
- false if the array contains an element, true if not or the array is null.
-
rotate
Return a rotated view of the given list with the given distance.- The distance can be negative, in which case the list is rotated to the left.
- The distance can be larger than the size of the list, in which case the list is rotated multiple times.
- The distance can be zero, in which case the list is not rotated.
- The list can be empty, in which case it remains empty.
- Parameters:
list- the list to rotatedistance- the distance to rotate (positive rotates right, negative rotates left)- Returns:
- a rotated view of the given list with the given distance
- See Also:
-
sortAndDedup
In place de-duplicates items in a list Noop if the list is empty or has one item.- Type Parameters:
T- the type of the items in the list- Parameters:
array- the list to de-duplicatecomparator- the comparator to use to compare items- Throws:
NullPointerException- if the list is `null` or comparator is `null`
-
toArray
Converts a collection of Integers to an array of ints.- Parameters:
ints- The collection of Integers to convert- Returns:
- The array of ints
- Throws:
NullPointerException- if ints is null
-
ensureNoSelfReferences
Deeply inspects a Map, Iterable, or Object array looking for references back to itself.- Parameters:
value- The object to evaluate looking for self referencesmessageHint- A string to be included in the exception message if the call fails, to provide more context to the handler of the exception- Throws:
IllegalArgumentException- if a self-reference is found
-
copyMap
Returns an unmodifiable copy of the given map.- Parameters:
map- Map to copy- Returns:
- unmodifiable copy of the map
-
iterableAsArrayList
- Type Parameters:
E- the type the elements- Parameters:
elements- The iterable to convert- Returns:
- an
ArrayList - Throws:
NullPointerException- if elements is null
-
arrayAsArrayList
-
asArrayList
-
asArrayList
-
newSingletonArrayList
-
eagerPartition
-
isEmpty
Checks if a collection is empty or not. Empty collection mean either it is null or it has no elements in it. If collection contains a null element it means it is not empty.- Type Parameters:
E- Element- Parameters:
collection-Collection- Returns:
- true if collection is null or
isEmpty(), false otherwise
-