Class ArrayUtils
-
- All Implemented Interfaces:
public final class ArrayUtils
-
-
Method Summary
Modifier and Type Method Description final static <L extends List<E>, RandomAccess, E extends Any> UnitfastEach(L $self, Integer beginAt, Function1<E, Unit> f)forEach re-implementation that doesn't allocate any memory. final static <L extends List<E>, RandomAccess, E extends Any> UnitfastEachReversed(L $self, Integer beginAt, Function1<E, Unit> f)forEach re-implementation that doesn't allocate any memory, but it traverses the list backwards. final static <L extends List<E>, RandomAccess, E extends Any> UnitfastEachIndexed(L $self, Integer beginAt, Function2<Integer, E, Unit> f)forEachIndexed re-implementation that doesn't allocate any memory. final static <L extends List<E>, RandomAccess, E extends Any> UnitfastEachIndexedReversed(L $self, Integer beginAt, Function2<Integer, E, Unit> f)forEachIndexed re-implementation that doesn't allocate any memory, but it traverses the list backwards. final static <L extends MutableList<E>, RandomAccess, E extends Any> UnitfastRemoveIf(L $self, Function1<E, Boolean> f)removeIf re-implementation that doesn't allocate any memory. final static <L extends MutableList<E>, RandomAccess, E extends Any> UnitfastRemoveIfReversed(L $self, Function1<E, Boolean> f)removeIf re-implementation that doesn't allocate any memory, but it traverses the list backwards. final static <L extends List<E>, RandomAccess, E extends Any> BooleananyAre(L $self, Function1<E, Boolean> f)Returns trueif at least one element matches the given predicate.final static <L extends List<E>, RandomAccess, E extends Any> BooleannoneAre(L $self, Function1<E, Boolean> f)Returns trueif no elements match the given predicate.final static <L extends List<E>, RandomAccess, E extends Any> BooleanallAre(L $self, Function1<E, Boolean> f)Returns trueif all elements match the given predicate.final static <L extends MutableList<E>, RandomAccess, E extends Any, R extends Comparable<R>> LsortedByDescending(L $self, Function1<E, R> selector)Returns a list of all elements sorted descending according to natural sort order of the value returned by specified selector function. final static <L extends List<E>, RandomAccess, E extends Any> FloatsumOf(L $self, Function1<E, Float> selector)Returns the sum of all values produced by selector function applied to each element in the collection, for floats. final static <L extends MutableList<E>, RandomAccess, E extends Any> Vec2<Unit>maxOf(L $self, Function1<E, Vec2<Unit>> selector)Returns the largest Vec2 produced by selector function applied to each element in the collection. final static <E extends Any> EaddOrReplace(List<E> $self, E item, Integer index)This function will add the given item to the end of the list if it doesn't exist, or replace it if it does. final static <E extends Any> EputIfAbsent(List<E> $self, E item)If the specified item is not already present, appends it to the end of this list, and returns null. final static <E extends Any> UnitmoveElement(Array<E> $self, Integer from, Integer to)Moves the given element from the from index to the to index. final static <E extends Any> Array<E>append(Array<E> $self, E element, Boolean stillPutOnFail)Append element to the end of this array, that is, the first empty index. final static <T extends Any> ArrayList<T>asArrayList(Iterable<T> $self)Return this iterable as an ArrayList. final static <T extends Any> ArrayList<T>asArrayList(Array<T> $self)final static <E extends Any> UnitclearUsing(Collection<E> $self, Function1<E, Unit> action)Clears the collection using the action, avoiding ConcurrentModificationException. final static <E extends Any> IntegerindexOfOrDie(List<E> $self, E element, Function0<Void> or)Returns the index of the element in the list or runs the or parameter if the element is not found. final static <A extends Any, B extends Any, C extends Any> MutableTriple<A, B, C>toMutableTriple(Triple<A, B, C> $self)convert this triple to a mutable triple. final static <A extends Any, B extends Any> MutablePair<A, B>toMutablePair(Pair<A, B> $self)convert this pair to a mutable pair. -
-
Method Detail
-
fastEach
final static <L extends List<E>, RandomAccess, E extends Any> Unit fastEach(L $self, Integer beginAt, Function1<E, Unit> f)
forEach re-implementation that doesn't allocate any memory.
Utilizes the RandomAccess trait.
- Parameters:
f- The function to apply to each element.
-
fastEachReversed
final static <L extends List<E>, RandomAccess, E extends Any> Unit fastEachReversed(L $self, Integer beginAt, Function1<E, Unit> f)
forEach re-implementation that doesn't allocate any memory, but it traverses the list backwards.
Utilizes the RandomAccess trait.
- Parameters:
f- The function to apply to each element.- Since:
0.18.5
-
fastEachIndexed
final static <L extends List<E>, RandomAccess, E extends Any> Unit fastEachIndexed(L $self, Integer beginAt, Function2<Integer, E, Unit> f)
forEachIndexed re-implementation that doesn't allocate any memory.
Utilizes the RandomAccess trait.
- Parameters:
f- The function to apply to each element.
-
fastEachIndexedReversed
final static <L extends List<E>, RandomAccess, E extends Any> Unit fastEachIndexedReversed(L $self, Integer beginAt, Function2<Integer, E, Unit> f)
forEachIndexed re-implementation that doesn't allocate any memory, but it traverses the list backwards.
Utilizes the RandomAccess trait.
- Parameters:
f- The function to apply to each element.- Since:
0.18.5
-
fastRemoveIf
final static <L extends MutableList<E>, RandomAccess, E extends Any> Unit fastRemoveIf(L $self, Function1<E, Boolean> f)
removeIf re-implementation that doesn't allocate any memory.
Utilizes the RandomAccess trait.
-
fastRemoveIfReversed
final static <L extends MutableList<E>, RandomAccess, E extends Any> Unit fastRemoveIfReversed(L $self, Function1<E, Boolean> f)
removeIf re-implementation that doesn't allocate any memory, but it traverses the list backwards.
Can be faster as MutableList.removeAt works better with fewer elements to the right of the current.
Utilizes the RandomAccess trait.
- Since:
0.23.2
-
anyAre
final static <L extends List<E>, RandomAccess, E extends Any> Boolean anyAre(L $self, Function1<E, Boolean> f)
Returns
trueif at least one element matches the given predicate.
-
noneAre
final static <L extends List<E>, RandomAccess, E extends Any> Boolean noneAre(L $self, Function1<E, Boolean> f)
Returns
trueif no elements match the given predicate.Note this function will return
trueif the list is empty, according to the principle of Vacuous truth, because there are no elements that match the given predicate.
-
allAre
final static <L extends List<E>, RandomAccess, E extends Any> Boolean allAre(L $self, Function1<E, Boolean> f)
Returns
trueif all elements match the given predicate.Note this function will return
trueif the list is empty, according to the principle of Vacuous truth, and the fact that there are no elements that don't match the given predicate.
-
sortedByDescending
final static <L extends MutableList<E>, RandomAccess, E extends Any, R extends Comparable<R>> L sortedByDescending(L $self, Function1<E, R> selector)
Returns a list of all elements sorted descending according to natural sort order of the value returned by specified selector function.
The sort is stable. It means that equal elements preserve their order relative to each other after sorting.
-
sumOf
final static <L extends List<E>, RandomAccess, E extends Any> Float sumOf(L $self, Function1<E, Float> selector)
Returns the sum of all values produced by selector function applied to each element in the collection, for floats.
- Parameters:
selector- a function that extracts a Float property of an element- Returns:
the sum of all values produced by selector
-
maxOf
final static <L extends MutableList<E>, RandomAccess, E extends Any> Vec2<Unit> maxOf(L $self, Function1<E, Vec2<Unit>> selector)
Returns the largest Vec2 produced by selector function applied to each element in the collection.
-
addOrReplace
final static <E extends Any> E addOrReplace(List<E> $self, E item, Integer index)
This function will add the given item to the end of the list if it doesn't exist, or replace it if it does.
- Returns:
the old value if it was replaced, or
nullif it was added.
-
putIfAbsent
final static <E extends Any> E putIfAbsent(List<E> $self, E item)
If the specified item is not already present, appends it to the end of this list, and returns null. Else, returns the item in this list.
- Parameters:
item- the item to add- Returns:
the previous value associated in this list, or null if was not found and added successfully.
- Since:
0.23.2
-
moveElement
final static <E extends Any> Unit moveElement(Array<E> $self, Integer from, Integer to)
Moves the given element from the from index to the to index.
Note: this method makes absolutely no attempt to verify if the given indices are valid.
- Parameters:
from- the index of the element to moveto- the index to move the element to
-
append
final static <E extends Any> Array<E> append(Array<E> $self, E element, Boolean stillPutOnFail)
Append element to the end of this array, that is, the first empty index.
- Parameters:
element- the element to appendstillPutOnFail- set this totrueif you want it to add the element (causes a reallocation!) even if the array is full.
-
asArrayList
final static <T extends Any> ArrayList<T> asArrayList(Iterable<T> $self)
Return this iterable as an ArrayList. Note: if it is already an ArrayList, it will be returned as-is.
-
asArrayList
final static <T extends Any> ArrayList<T> asArrayList(Array<T> $self)
-
clearUsing
final static <E extends Any> Unit clearUsing(Collection<E> $self, Function1<E, Unit> action)
Clears the collection using the action, avoiding ConcurrentModificationException.
This works by allocating a new list and iterating over it, removing each element from the original collection.
- Parameters:
action- should be used to directly remove itself from the collection.
-
indexOfOrDie
final static <E extends Any> Integer indexOfOrDie(List<E> $self, E element, Function0<Void> or)
Returns the index of the element in the list or runs the or parameter if the element is not found.
This returns Nothing, and is used by default to throw an exception; hence why it's called "or die".
-
toMutableTriple
final static <A extends Any, B extends Any, C extends Any> MutableTriple<A, B, C> toMutableTriple(Triple<A, B, C> $self)
convert this triple to a mutable triple.
-
toMutablePair
final static <A extends Any, B extends Any> MutablePair<A, B> toMutablePair(Pair<A, B> $self)
convert this pair to a mutable pair.
-
-
-
-