Class ArrayUtils
java.lang.Object
org.springframework.data.gemfire.util.ArrayUtils
ArrayUtils is an abstract utility class used to work with Object arrays.-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]asArray(T... elements) Returns the given varargselementas an array.static <T> T[]defaultIfEmpty(T[] array, T[] defaultArray) Returns the givenarrayif not null or empty, otherwise returns thedefaultArray.static <T> TgetFirst(T[] array) Null-safe method to return the first element in the array or null if the array is null or empty.static <T> TgetFirst(T[] array, T defaultValue) Null-safe method to return the first element in the array or thedefaultValueif the array is null or empty.static Object[]Insert an element into the given array at position (index).static booleanDetermines whether the given array is empty or not.static booleanisNotEmpty(Object[] array) Determines whether the given array is empty or not.static intNull-safe operation to determine an array's length.static <T> T[]nullSafeArray(T[] array, Class<T> componentType) Null-safe, empty array operation returning the given object array if not null or an empty object array if the array argument is null.static Object[]Remove an element from the given array at position (index).static <T extends Comparable<T>>
T[]sort(T[] array) Sort the array of elements according to the elements natural ordering.static <T> Iterable<T>toIterable(T... array) Converts the given array into anIterableobject.
-
Constructor Details
-
ArrayUtils
public ArrayUtils()
-
-
Method Details
-
asArray
Returns the given varargselementas an array.- Type Parameters:
T- Class type of the elements.- Parameters:
elements- variable list of arguments to return as an array.- Returns:
- an arry for the given varargs
elements.
-
defaultIfEmpty
public static <T> T[] defaultIfEmpty(T[] array, T[] defaultArray) Returns the givenarrayif not null or empty, otherwise returns thedefaultArray.- Type Parameters:
T-Classtype of the array elements.- Parameters:
array- array to evaluate.defaultArray- array to return if the givenarrayis null or empty.- Returns:
- the given
arrayif not null or empty otherwise return thedefaultArray.
-
getFirst
public static <T> T getFirst(T[] array) Null-safe method to return the first element in the array or null if the array is null or empty.- Type Parameters:
T- Class type of the array elements.- Parameters:
array- the array from which to extract the first element.- Returns:
- the first element in the array or null if the array is null or empty.
- See Also:
-
getFirst
public static <T> T getFirst(T[] array, T defaultValue) Null-safe method to return the first element in the array or thedefaultValueif the array is null or empty.- Type Parameters:
T- Class type of the array elements.- Parameters:
array- the array from which to extract the first element.defaultValue- value to return if the array is null or empty.- Returns:
- the first element in the array or
defaultValueif the array is null or empty. - See Also:
-
insert
Insert an element into the given array at position (index). The element is inserted at the given position and all elements afterwards are moved to the right.- Parameters:
originalArray- the array in which to insert the element.position- an integer index (position) at which to insert the element in the array.element- the element to insert into the array.- Returns:
- a new array with the element inserted at position.
- See Also:
-
isEmpty
Determines whether the given array is empty or not.- Parameters:
array- the array to evaluate for emptiness.- Returns:
- a boolean value indicating whether the given array is empty.
- See Also:
-
isNotEmpty
Determines whether the given array is empty or not.- Parameters:
array- the array to evaluate for emptiness.- Returns:
- a boolean value indicating whether the given array is empty.
- See Also:
-
length
Null-safe operation to determine an array's length.- Parameters:
array- the array to determine it's length.- Returns:
- the length of the given array or 0 if the array reference is null.
-
nullSafeArray
Null-safe, empty array operation returning the given object array if not null or an empty object array if the array argument is null.- Type Parameters:
T- Class type of the array elements.- Parameters:
array- array of objects on which a null check is performed.componentType- Class type of the array elements.- Returns:
- the given object array if not null, otherwise return an empty object array.
- See Also:
-
remove
Remove an element from the given array at position (index). The element is removed at the specified position and all remaining elements are shifted to the left.- Parameters:
originalArray- the array from which to remove the element.position- the integer index (position) indicating the element to remove from the array.- Returns:
- a new array with the element at position in the originalArray removed.
- See Also:
-
sort
Sort the array of elements according to the elements natural ordering.- Type Parameters:
T-Comparableclass type of the array elements.- Parameters:
array- array of elements to sort.- Returns:
- the sorted array of elements.
- See Also:
-
toIterable
Converts the given array into anIterableobject.- Type Parameters:
T-typeof the array elements; mut not be null.- Parameters:
array- array to convert to anIterable.- Returns:
- an
Iterableobject from the given array. - Throws:
IllegalArgumentException- if the array is null.- See Also:
-