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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]
asArray
(T... elements) Returns the given varargselement
as an array.static <T> T[]
defaultIfEmpty
(T[] array, T[] defaultArray) Returns the givenarray
if not null or empty, otherwise returns thedefaultArray
.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.static <T> T
getFirst
(T[] array, T defaultValue) Null-safe method to return the first element in the array or thedefaultValue
if the array is null or empty.static Object[]
Insert an element into the given array at position (index).static boolean
Determines whether the given array is empty or not.static boolean
isNotEmpty
(Object[] array) Determines whether the given array is empty or not.static int
Null-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 anIterable
object.
-
Constructor Details
-
ArrayUtils
public ArrayUtils()
-
-
Method Details
-
asArray
Returns the given varargselement
as 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
@Nullable public static <T> T[] defaultIfEmpty(@Nullable T[] array, @Nullable T[] defaultArray) Returns the givenarray
if not null or empty, otherwise returns thedefaultArray
.- Type Parameters:
T
-Class
type of the array elements.- Parameters:
array
- array to evaluate.defaultArray
- array to return if the givenarray
is null or empty.- Returns:
- the given
array
if not null or empty otherwise return thedefaultArray
.
-
getFirst
@Nullable public static <T> T getFirst(@Nullable 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
@Nullable public static <T> T getFirst(@Nullable T[] array, @Nullable T defaultValue) Null-safe method to return the first element in the array or thedefaultValue
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.defaultValue
- value to return if the array is null or empty.- Returns:
- the first element in the array or
defaultValue
if the array is null or empty. - See Also:
-
insert
@NonNull public static Object[] insert(@NonNull Object[] originalArray, int position, Object element) 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
-Comparable
class 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 anIterable
object.- Type Parameters:
T
-type
of the array elements; mut not be null.- Parameters:
array
- array to convert to anIterable
.- Returns:
- an
Iterable
object from the given array. - Throws:
IllegalArgumentException
- if the array is null.- See Also:
-