Class ListUtils
-
- All Implemented Interfaces:
public final class ListUtils
-
-
Method Summary
Modifier and Type Method Description final static <L extends List<E>, RandomAccess, E extends Any> UnitfastEach(L $self, Function1<E, Unit> func)no-alloc List.forEach which utilizes RandomAccess to get the elements. final static <L extends List<E>, RandomAccess, E extends Any> UnitfastEachIndexed(L $self, Function2<Integer, E, Unit> func)no-alloc List.forEachIndexed which utilizes RandomAccess to get the elements. final static <L extends List<E>, RandomAccess, E extends Any> UnitfastEachReversed(L $self, Function1<E, Unit> func)no-alloc List.forEach which utilizes RandomAccess to get the elements, backwards. final static <L extends MutableList<E>, RandomAccess, E extends Any> UnitfastRemoveIf(L $self, Function1<E, Boolean> predicate)no-alloc MutableList.removeIf which utilizes RandomAccess to get the elements. final static <L extends MutableList<E>, RandomAccess, E extends Any> UnitfastRemoveIfReversed(L $self, Function1<E, Boolean> predicate)no-alloc MutableList.removeIf which utilizes RandomAccess to get the elements. final static <L extends List<E>, RandomAccess, E extends Any> BooleanfastAll(L $self, Function1<E, Boolean> predicate)Returns trueif all elements match the given predicate.final static <L extends List<E>, RandomAccess, E extends Any> BooleanfastAny(L $self, Function1<E, Boolean> predicate)Returns trueif all elements match the given predicate.final static <E extends Any> UnitaddIfAbsent(List<E> $self, E element)Add the given element to this list if it is not in it already. final static <E extends Any> EaddOrReplace(List<E> $self, E element)Replace this given element if it already exists in this list using Any.equals, or append it to the end if it does not. final static <L extends MutableList<E>, RandomAccess, E extends Any> Lcut(L $self, Integer from, Integer to)Returns this list, with all elements not in the range from.. final static <E extends Any> ArrayList<E>copy(ArrayList<E> $self)-
-
Method Detail
-
fastEach
final static <L extends List<E>, RandomAccess, E extends Any> Unit fastEach(L $self, Function1<E, Unit> func)
no-alloc List.forEach which utilizes RandomAccess to get the elements.
note: this method contains a simple check for ConcurrentModificationException. if concurrent modification is detected, it will not throw an exception and simply print
FAST_WARN_CONCURRENT_MODIFICATIONto the console. This method is not thread safe.- Since:
1.2.0
-
fastEachIndexed
final static <L extends List<E>, RandomAccess, E extends Any> Unit fastEachIndexed(L $self, Function2<Integer, E, Unit> func)
no-alloc List.forEachIndexed which utilizes RandomAccess to get the elements.
note: this method contains a simple check for ConcurrentModificationException. if concurrent modification is detected, it will not throw an exception and simply print
WARN_CONCURRENT_MODIFICATION_IDXto the console. This method is not thread safe.- Since:
1.2.0
-
fastEachReversed
final static <L extends List<E>, RandomAccess, E extends Any> Unit fastEachReversed(L $self, Function1<E, Unit> func)
no-alloc List.forEach which utilizes RandomAccess to get the elements, backwards.
note: this method contains a simple check for ConcurrentModificationException. if concurrent modification is detected, it will not throw an exception and simply print
WARN_CONCURRENT_MODIFICATION_REVto the console. This method is not thread safe.- Since:
1.2.0
-
fastRemoveIf
final static <L extends MutableList<E>, RandomAccess, E extends Any> Unit fastRemoveIf(L $self, Function1<E, Boolean> predicate)
no-alloc MutableList.removeIf which utilizes RandomAccess to get the elements.
This method is not thread safe. if the list is modified while this loop is running by an external source, the behavior is undefined.
- Since:
1.2.0
-
fastRemoveIfReversed
final static <L extends MutableList<E>, RandomAccess, E extends Any> Unit fastRemoveIfReversed(L $self, Function1<E, Boolean> predicate)
no-alloc MutableList.removeIf which utilizes RandomAccess to get the elements.
This method is not thread safe. if the list is modified while this loop is running by an external source, the behavior is undefined.
this method should be used in preference to fastRemoveIf as it is more efficient with the removal operations.
- Since:
1.2.0
-
fastAll
final static <L extends List<E>, RandomAccess, E extends Any> Boolean fastAll(L $self, Function1<E, Boolean> predicate)
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.This method is not thread safe. This function may fail with ConcurrentModificationException in case of illegal access between threads.
this method is no-alloc, like other methods in this family such as fastEach.
- Since:
1.2.0
-
fastAny
final static <L extends List<E>, RandomAccess, E extends Any> Boolean fastAny(L $self, Function1<E, Boolean> predicate)
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.This method is not thread safe. This function may fail with ConcurrentModificationException in case of illegal access between threads.
this method is no-alloc, like other methods in this family such as fastEach.
- Since:
1.2.0
-
addIfAbsent
final static <E extends Any> Unit addIfAbsent(List<E> $self, E element)
Add the given element to this list if it is not in it already.
Used when the performance hit of a Set is not worth it, such as if this operation is rare.
- Since:
1.2.0
-
addOrReplace
final static <E extends Any> E addOrReplace(List<E> $self, E element)
Replace this given element if it already exists in this list using Any.equals, or append it to the end if it does not. This method is very strange and has one specific use case, which is for cases where referential equality is needed as well as structural equality. See more here.
- Since:
1.2.0
-
cut
final static <L extends MutableList<E>, RandomAccess, E extends Any> L cut(L $self, Integer from, Integer to)
Returns this list, with all elements not in the range from..to removed.
Functionally equivalent to MutableList.subList but effects this list, not returning a copy with the specified elements.
this method is no-alloc, like other methods in this family such as fastEach.
This method is not thread safe. If the original list is being iterated over when this method is called, it will probably blow up.
- Since:
1.2.0
-
-
-
-