Class ListUtils

  • All Implemented Interfaces:

    
    public final class ListUtils
    
                        
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final static <L extends List<E>, E extends Any> Unit fastEach(L $self, Function1<E, Unit> func) no-alloc Iterable.forEach which utilizes RandomAccess to get the elements.
      final static <L extends List<E>, E extends Any> Unit fastEachIndexed(L $self, Function2<Integer, E, Unit> func) no-alloc Iterable.
      final static <L extends List<E>, E extends Any> Unit fastEachReversed(L $self, Function1<E, Unit> func) no-alloc List.forEach which utilizes RandomAccess to get the elements, backwards.
      final static <L extends MutableList<E>, E extends Any> Unit fastRemoveIf(L $self, Function1<E, Boolean> predicate) no-alloc MutableList.removeIf which utilizes RandomAccess to get the elements.
      final static <L extends MutableList<E>, E extends Any> Unit fastRemoveIfReversed(L $self, Function1<E, Boolean> predicate) no-alloc MutableList.removeIf which utilizes RandomAccess to get the elements.
      final static <L extends List<E>, E extends Any> Boolean fastAll(L $self, Function1<E, Boolean> predicate) Returns true if all elements match the given predicate.
      final static <L extends List<E>, E extends Any> Boolean fastAny(L $self, Function1<E, Boolean> predicate) Returns true if all elements match the given predicate.
      final static <L extends List<E>, E extends Any, R extends Any> Array<R> mapToArray(L $self, Function1<E, R> transform) Perform the given transform on every element in this list, and return a new array with the results.
      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.
      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.
      final static <L extends MutableList<E>, E extends Any> L cut(L $self, Integer from, Integer to) Returns this list, with all elements not in the range from..
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

    • Method Detail

      • fastEach

         final static <L extends List<E>, E extends Any> Unit fastEach(L $self, Function1<E, Unit> func)

        no-alloc Iterable.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_MODIFICATION to the console. This method is not thread safe.

        Since:

        1.2.0

      • fastEachIndexed

         final static <L extends List<E>, E extends Any> Unit fastEachIndexed(L $self, Function2<Integer, E, Unit> func)

        no-alloc Iterable.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_IDX to the console. This method is not thread safe.

        Since:

        1.2.0

      • fastEachReversed

         final static <L extends List<E>, 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_REV to the console. This method is not thread safe.

        Since:

        1.2.0

      • fastRemoveIf

         final static <L extends MutableList<E>, 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>, 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>, E extends Any> Boolean fastAll(L $self, Function1<E, Boolean> predicate)

        Returns true if all elements match the given predicate.

        Note this function will return true if 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>, E extends Any> Boolean fastAny(L $self, Function1<E, Boolean> predicate)

        Returns true if all elements match the given predicate.

        Note this function will return true if 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

      • mapToArray

         final static <L extends List<E>, E extends Any, R extends Any> Array<R> mapToArray(L $self, Function1<E, R> transform)

        Perform the given transform on every element in this list, and return a new array with the results.

        Equivalent to this.map { transform(it) }.toTypedArray(), but saves on the creation of an intermediate list.

        this method is no-alloc, like other methods in this family such as fastEach.

      • 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>, 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