Package panda.utilities
Class ArrayUtils
java.lang.Object
panda.utilities.ArrayUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCheck if the specified array contains the elementstatic booleancontainsNull(Object[] array) Check if the specified array contains nullstatic <T> panda.std.Option<T>Find value in array using the predicate conditionstatic <T> voidstatic <T,E extends Exception>
voidforEachThrowing(T[] array, panda.std.function.ThrowingConsumer<T, E> consumer) Iterable.forEach(java.util.function.Consumer)for arrays usingThrowingConsumerstatic <T> panda.std.Option<T>get(T[] array, int index) Get element of array at the given position without risk ofArrayIndexOutOfBoundsExceptionstatic <T> Tget(T[] array, int index, T defaultValue) Get element of array at the given position without risk ofArrayIndexOutOfBoundsExceptionstatic Class<?>getArrayClass(Class<?> clazz) Get array class for the specified typestatic Class<?>getBaseClass(Class<?> arrayClass) Get base class of any array, e.g.getBaseClassWithDimensions(Class<?> arrayClass) Get base class of any array, e.g.static Class<?>getDimensionalArrayType(Class<?> type, int dimensions) Get dimensional array for the specified typestatic <T> panda.std.Option<T>getFirst(T[] array) Get first element of the given arraystatic <T> intGet index of element that pass the conditionstatic <T> panda.std.Option<T>getLast(T[] array) Get last element of the given arraystatic <T> intindexOf(T[] array, T element) Get index of the given elementstatic booleanCheck if the given object is arraystatic booleanChecks if the specified array is null or emptystatic <T> intlength(T[]... arrays) Get length of all given arraysstatic <T> T[]Merge arrays into one arraystatic <T> T[]merge(T[]... arrays) Merge several arraysstatic <T> T[]Create a new array with the given element at the first position and copy the rest of arraystatic <T> T[]of(T... elements) Return array of the specified elements using varargs parameter
-
Method Details
-
forEach
- Type Parameters:
T- type of array- Parameters:
array- the array to iterateconsumer- array values consumer
-
forEachThrowing
public static <T,E extends Exception> void forEachThrowing(T[] array, panda.std.function.ThrowingConsumer<T, E> consumer) throws EIterable.forEach(java.util.function.Consumer)for arrays usingThrowingConsumer- Type Parameters:
T- type of arrayE- type of exception- Parameters:
array- the array to iterateconsumer- array values consumer with exceptions support- Throws:
E- if consumer will throw exception
-
merge
Merge several arrays- Parameters:
arrays- arrays to merge- Returns:
- array of merged arrays
-
merge
Merge arrays into one array- Type Parameters:
T- type of arrays- Parameters:
arrayFunction- array instance supplierarrays- arrays to merge- Returns:
- the merged array
-
merge
Create a new array with the given element at the first position and copy the rest of array- Type Parameters:
T- type of array- Parameters:
firstElement- the element to add at the first positionarray- the array to copyarrayFunction- array instance supplier with array size as an argument- Returns:
- the merged array
-
findIn
Find value in array using the predicate condition- Type Parameters:
T- type of array- Parameters:
array- the array to search incondition- the condition- Returns:
- the found element or null
-
containsNull
Check if the specified array contains null- Returns:
- the array to search
-
contains
Check if the specified array contains the element- Parameters:
array- the array to searchelement- the element to search for- Returns:
- true if the specified array contains the element, otherwise false
-
length
Get length of all given arrays- Type Parameters:
T- type of arrays- Parameters:
arrays- the arrays to sum up- Returns:
- arrays length
-
isArray
Check if the given object is array- Parameters:
object- the object to check- Returns:
- true if object is not null and its class represents array, otherwise false
-
isEmpty
Checks if the specified array is null or empty- Parameters:
array- the array to check- Returns:
- true if array is null or empty
-
getDimensionalArrayType
Get dimensional array for the specified type- Parameters:
type- the type of the arraydimensions- the amount of dimensions- Returns:
- the class of the dimensional array
-
getBaseClass
Get base class of any array, e.g. Integer from Integer[][][][][]- Parameters:
arrayClass- the array class- Returns:
- the base type
-
getBaseClassWithDimensions
Get base class of any array, e.g. Integer from Integer[][][][][]- Parameters:
arrayClass- the array class- Returns:
- the base type
-
getArrayClass
Get array class for the specified type- Parameters:
clazz- type of array- Returns:
- array of type
-
getIndex
Get index of element that pass the condition- Type Parameters:
T- type of array- Parameters:
array- the array to search incondition- the condition to test elements- Returns:
- index of element or -1 if element was not found
-
indexOf
public static <T> int indexOf(T[] array, @Nullable T element) Get index of the given element- Type Parameters:
T- type of array- Parameters:
array- the array to search inelement- element to search for- Returns:
- index of element or -1 if element was not found
-
getFirst
public static <T> panda.std.Option<T> getFirst(T[] array) Get first element of the given array- Type Parameters:
T- type of array- Parameters:
array- the array to search in- Returns:
- first element of the given array or empty option
-
getLast
public static <T> panda.std.Option<T> getLast(T[] array) Get last element of the given array- Type Parameters:
T- type of array- Parameters:
array- the array to search in- Returns:
- last element of the given array or empty option
-
get
public static <T> panda.std.Option<T> get(T[] array, int index) Get element of array at the given position without risk ofArrayIndexOutOfBoundsException- Type Parameters:
T- type of the array- Parameters:
array- the array to processindex- the index of element to get- Returns:
- the element at the index position, null if the index is less than 0 or greater than the size of the specified array
-
get
public static <T> T get(T[] array, int index, T defaultValue) Get element of array at the given position without risk ofArrayIndexOutOfBoundsException- Type Parameters:
T- type of the array- Parameters:
array- the array to processindex- the index of element to getdefaultValue- the default value to return when there is no such an index in the array- Returns:
- the element at the index position, null if the index is less than 0 or greater than the size of the specified array
-
of
Return array of the specified elements using varargs parameter- Type Parameters:
T- type of the array- Parameters:
elements- elements in array- Returns:
- the array of the specified elements
-