Package com.aliucord

Class CollectionUtils

  • All Implemented Interfaces:

    
    public class CollectionUtils
    
                        

    Utility class to work with collections, inspired by Javascript array methods

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Constructor Detail

      • CollectionUtils

        CollectionUtils()
    • Method Detail

      • some

         static <E> boolean some(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)

        Check whether any element of the collection passes the filter

        Returns:

        True if condition is true for any element in the collection

      • every

         static <E> boolean every(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)

        Check whether all elements of the collection pass the filter

        Returns:

        True if condition is true for all elements in the collection

      • findIndex

         static <E> int findIndex(@NonNull() List<E> list, @NonNull() Function1<E, Boolean> filter)

        Find the index of the first element which passes the filter

        Returns:

        Index if found, otherwise -1

      • findLastIndex

         static <E> int findLastIndex(@NonNull() List<E> list, @NonNull() Function1<E, Boolean> filter)

        Find the index of the last element which passes the filter

        Returns:

        Index if found, otherwise -1

      • map

        @NonNull() static <E, R> List<R> map(@NonNull() Collection<E> collection, @NonNull() Function1<E, R> transform)

        Returns a new Array containing the results of the transform function for all elements

        Returns:

        Filtered Collection

      • removeIf

         static <E> boolean removeIf(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)

        Removes all elements from the collection which pass the filter

        Returns:

        Whether an element was removed

      • partition

         static <E> Pair<List<E>, List<E>> partition(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)

        Partition the collection into two Arrays. The first array has all elements which passed the filter, the second one has the rest

        Returns:

        A Pair containing the two arrays

      • splice

         static <E> List<E> splice(List<E> list, int start)

        Removes all elements after the specified start index

        Returns:

        The removed elements

      • splice

        @SafeVarargs() static <E> List<E> splice(List<E> list, int start, int deleteCount, Array<E> items)

        Removes the specified amount of elements after the specified start index and inserts the specified items

        Parameters:
        list - The list of splice
        start - The start index
        deleteCount - The amount of items to remove
        items - The items to insert
        Returns:

        The removed elements