Package dev.quantumfusion.hyphen.util
Class ArrayUtil
java.lang.Object
dev.quantumfusion.hyphen.util.ArrayUtil
T lot of very useful code that helps with handling Arrays for better code readability.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T[]combine(T[] a1, T[] a2)Combines 2 arrays into 1.static <T> T[]combine(T[] a1, T[] a2, IntFunction<T[]> creator)Combines 2 arrays into 1.static <T> T[]copyAndAppend(T[] oldArray, T newEntry)static <A, B> voiddualFor(A[] a, B[] b, BiConsumer<? super A,? super B> dualFor)Same as above but with the index excluded.static <A, B> voiddualForEach(A[] a, B[] b, ArrayUtil.DualForEach<? super A,? super B> dualForEach)Loops over 2 arrays at the same time.static <T> T[]Filters the array's content.static <A, B> B[]map(A[] a, IntFunction<B[]> creator, ArrayUtil.IndexedMap<? super A,? extends B> mapper)Map a given array to another type or something else.static <A, B, D> B[]map(A[] a, IntFunction<B[]> creator, D data, BiFunction<? super A,? super D,? extends B> mapper)static <A, B> B[]map(A[] a, IntFunction<B[]> creator, Function<? super A,? extends B> mapper)Same asmap(Object[], IntFunction, IndexedMap)but with the index excluded.
-
Constructor Details
-
ArrayUtil
public ArrayUtil()
-
-
Method Details
-
dualForEach
public static <A, B> void dualForEach(A[] a, B[] b, ArrayUtil.DualForEach<? super A,? super B> dualForEach)Loops over 2 arrays at the same time.
So if you have to array's that have linked content, and you want to combine the values or do something else you can use this method.
This is the version with the index included.
To exclude the index use the method below instead- Type Parameters:
A- Array 1 TypeB- Array 2 Type- Parameters:
a- Array 1b- Array 2dualForEach- The Consumer that iterates.- See Also:
dualFor(Object[], Object[], BiConsumer)
-
dualFor
Same as above but with the index excluded. -
map
public static <A, B> B[] map(A[] a, IntFunction<B[]> creator, ArrayUtil.IndexedMap<? super A,? extends B> mapper)Map a given array to another type or something else.
Equivalent toArrays.stream(Object[])and thenStream.map(Function)
This method is however much faster and cleaner.
This version has the index included. If you want to exclude the index use
map(Object[], IntFunction, Function)instead. -
map
public static <A, B> B[] map(A[] a, IntFunction<B[]> creator, Function<? super A,? extends B> mapper)Same asmap(Object[], IntFunction, IndexedMap)but with the index excluded. -
map
public static <A, B, D> B[] map(A[] a, IntFunction<B[]> creator, D data, BiFunction<? super A,? super D,? extends B> mapper) -
combine
Combines 2 arrays into 1.- Type Parameters:
T- The Array Type- Parameters:
a1- Array 1a2- Array ycreator- Creates the resulting array.- Returns:
- The combined array.
-
combine
public static <T> T[] combine(T[] a1, T[] a2)Combines 2 arrays into 1.- Type Parameters:
T- The Array Type- Parameters:
a1- Array 1a2- Array y- Returns:
- The combined array.
-
filter
Filters the array's content.- Type Parameters:
T- The Array Elements.- Parameters:
array- The Arraypredicate- The Predicate. Matching entries will be included.- Returns:
- The Filtered array.
-
copyAndAppend
public static <T> T[] copyAndAppend(T[] oldArray, T newEntry)
-