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> EaddOrReplace(L $self, E item)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> UnitmoveElement(Array<E> $self, Integer from, Integer to)Moves the given element from the from index to the to 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)-
-
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.
-
addOrReplace
final static <L extends MutableList<E>, RandomAccess, E extends Any> E addOrReplace(L $self, E item)
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.
-
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
-
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)
-
-
-
-