Module ushiosan.jvm.utilities
Class UArraysGeneric
java.lang.Object
ushiosan.jvm.internal.collections.arrays.generic.UArraysGeneric
- All Implemented Interfaces:
UArraysConstants
- Direct Known Subclasses:
UArrayPrimitive
-
Field Summary
Fields inherited from interface ushiosan.jvm.internal.collections.arrays.UArraysConstants
BYTE_EMPTY, CHAR_EMPTY, DOUBLE_EMPTY, EMPTY_SIZE, FLOAT_EMPTY, INDEX_NOT_FOUND, INT_EMPTY, LONG_EMPTY, OBJ_EMPTY, SHORT_EMPTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks if the array contains the selected element.static <T> booleancontentEquals(T @NotNull [] ar1, T @NotNull [] ar2) Verify that the contents of two arrays are the samestatic intSearch elements in the arraystatic <T> T @NotNull []Merge two arrays into onestatic <T> T @NotNull []Merge two arrays into onestatic <T> T @NotNull []Combine multiple arrays into onestatic <T> T @NotNull []Combine multiple arrays into onelastElement(T @NotNull [] array) Returns the last element of the arraystatic intlastIndexOf(Object @NotNull [] array, @Nullable Object element) Search an element in the array.Generate an array from given values.static <T> T[]make(T... elements) Generate an array from given values.Converts one array to another but with a different data type.static <T,V> V @NotNull [] Converts one array to another but with a different data type.static <T> TunsafeLastElement(T @NotNull [] array) Returns the last element of the array
-
Constructor Details
-
UArraysGeneric
public UArraysGeneric()
-
-
Method Details
-
make
Generate an array from given values. If you want to use primitive arrays, you must use the classes that encapsulate those types. -
make
Generate an array from given values. If you want to use primitive arrays, you must use the classes that encapsulate those types. -
indexOf
@Contract(pure=true) public static int indexOf(Object @NotNull [] array, @Nullable @Nullable Object element) Search elements in the array- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if an element not exists
-
lastIndexOf
@Contract(pure=true) public static int lastIndexOf(Object @NotNull [] array, @Nullable @Nullable Object element) Search an element in the array. This method tries to search in reverse, first starting at the end of the array, to find the desired element.- Parameters:
array- base array to searchelement- the element to search- Returns:
- the first index element or
-1if an element not exists
-
contains
Checks if the array contains the selected element.- Parameters:
array- base array to searchelement- the element to search- Returns:
trueif the element exists orfalseotherwise
-
lastElement
Returns the last element of the array- Type Parameters:
T- generic array type- Parameters:
array- base array to search- Returns:
- the last element of the array or
Optional.empty()if array is empty
-
unsafeLastElement
Returns the last element of the array- Type Parameters:
T- generic array type- Parameters:
array- base array to search- Returns:
- the last element of the array or
nullif array is empty
-
contentEquals
Verify that the contents of two arrays are the sameThis method checks if two arrays have the same length and the same elements. It utilizes a labeled block and a conditional break to optimize the process and avoid redundant return statements. By using a single return statement outside the block, we achieve a more dynamic flow while minimizing code duplication.
- Type Parameters:
T- the data type of each array- Parameters:
ar1- the array to checkar2- the array to check- Returns:
trueif the content is the same orfalseif the size is different or the content is different
-
transform
public static <T,V> V @NotNull [] transform(@NotNull @NotNull T[] original, @NotNull @NotNull Function<T, V> mapper, @NotNull @NotNull IntFunction<V[]> arrFn) Converts one array to another but with a different data type.- Type Parameters:
T- the original data typeV- the target data type- Parameters:
original- the original array that you want to convertmapper- function in charge of transforming each element of the arrayarrFn- function that generates the required type of array- Returns:
- the new array with the converted data
-
transform
public static <T> Object @NotNull [] transform(@NotNull @NotNull T[] original, @NotNull @NotNull Function<T, Object> mapper) Converts one array to another but with a different data type.- Type Parameters:
T- the original data type- Parameters:
original- the original array that you want to convertmapper- function in charge of transforming each element of the array- Returns:
- the new array with the converted data
-
join
Merge two arrays into one- Type Parameters:
T- the type of array that the method will generate- Parameters:
a1- array you want to combinea2- array you want to combine- Returns:
- a new array with all the content of the two arrays passed as parameter
-
join
public static <T> T @NotNull [] join(@NotNull @NotNull Class<T> cls, @NotNull @NotNull T[] a1, @NotNull @NotNull T[] a2) Merge two arrays into one- Type Parameters:
T- the type of array that the method will generate- Parameters:
cls- the type of data to be processeda1- array you want to combinea2- array you want to combine- Returns:
- a new array with all the content of the two arrays passed as parameter
-
joinAll
@SafeVarargs public static <T> T @NotNull [] joinAll(@NotNull @NotNull Class<T> cls, T[] @NotNull ... arrays) Combine multiple arrays into one- Type Parameters:
T- the type of array that the method will generate- Parameters:
cls- the type of data to be processedarrays- all the arrays you want to combine- Returns:
- a new array with all the content of the arrays passed as parameter
-
joinAll
Combine multiple arrays into one- Type Parameters:
T- the type of array that the method will generate- Parameters:
arrays- all the arrays you want to combine- Returns:
- a new array with all the content of the arrays passed as parameter
-