Class ListUtils

  • All Implemented Interfaces:

    
    public final class ListUtils
    
                        
    • Constructor Detail

    • Method Detail

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