Class CollectionUtils


  • @Deprecated
    public abstract class CollectionUtils
    extends java.lang.Object
    Deprecated.
    Will be removed in Gradle 9.0.
    This class is only here to maintain binary compatibility with existing plugins.

    Plugins should prefer external collection frameworks over this class. Internally, all code should use CollectionUtils.

    • Constructor Summary

      Constructors 
      Constructor Description
      CollectionUtils()
      Deprecated.
       
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static <T,​C extends java.util.Collection<? super T>>
      C
      addAll​(C t1, java.lang.Iterable<? extends T> t2)
      Deprecated.
      Utility for adding an iterable to a collection.
      static <T,​C extends java.util.Collection<? super T>>
      C
      addAll​(C t1, T... t2)
      Deprecated.
      Utility for adding an array to a collection.
      static <T> boolean any​(java.lang.Iterable<? extends T> source, Spec<? super T> filter)
      Deprecated.
       
      static <T> boolean any​(T[] source, Spec<? super T> filter)
      Deprecated.
       
      static java.lang.String asCommandLine​(java.lang.Iterable<java.lang.String> arguments)
      Deprecated.
       
      static <T> java.util.Collection<? extends T> checkedCast​(java.lang.Class<T> type, java.util.Collection<?> input)
      Deprecated.
       
      static <R,​I>
      java.util.List<R>
      collect​(I[] list, Transformer<? extends R,​? super I> transformer)
      Deprecated.
       
      static <R,​I,​C extends java.util.Collection<R>>
      C
      collect​(java.lang.Iterable<? extends I> source, C destination, Transformer<? extends R,​? super I> transformer)
      Deprecated.
       
      static <R,​I>
      java.util.List<R>
      collect​(java.lang.Iterable<? extends I> source, Transformer<? extends R,​? super I> transformer)
      Deprecated.
       
      static <R,​I>
      java.util.Set<R>
      collect​(java.util.Set<? extends I> set, Transformer<? extends R,​? super I> transformer)
      Deprecated.
       
      static <R,​I>
      R[]
      collectArray​(I[] list, java.lang.Class<R> newType, Transformer<? extends R,​? super I> transformer)
      Deprecated.
       
      static <R,​I>
      R[]
      collectArray​(I[] list, R[] destination, Transformer<? extends R,​? super I> transformer)
      Deprecated.
       
      static <K,​V>
      java.util.Map<K,​V>
      collectMap​(java.lang.Iterable<? extends V> items, Transformer<? extends K,​? super V> keyGenerator)
      Deprecated.
      Given a set of values, derive a set of keys and return a map
      static <K,​V>
      void
      collectMap​(java.util.Map<K,​V> destination, java.lang.Iterable<? extends V> items, Transformer<? extends K,​? super V> keyGenerator)
      Deprecated.
       
      static <K,​V>
      java.util.Map<K,​V>
      collectMapValues​(java.lang.Iterable<? extends K> keys, Transformer<? extends V,​? super K> keyGenerator)
      Deprecated.
      Given a set of keys, derive a set of values and return a map
      static <K,​V>
      void
      collectMapValues​(java.util.Map<K,​V> destination, java.lang.Iterable<? extends K> keys, Transformer<? extends V,​? super K> keyGenerator)
      Deprecated.
       
      static <E> java.util.List<E> compact​(java.util.List<E> list)
      Deprecated.
       
      static <T> CollectionUtils.SetDiff<T> diffSetsBy​(java.util.Set<? extends T> left, java.util.Set<? extends T> right, Transformer<?,​T> compareBy)
      Deprecated.
      Provides a “diff report” of how the two sets are similar and how they are different, comparing the entries by some aspect.
      static <T> boolean every​(java.lang.Iterable<? extends T> things, Spec<? super T> predicate)
      Deprecated.
       
      static <T,​C extends java.util.Collection<T>>
      C
      filter​(java.lang.Iterable<? extends T> source, C destination, Spec<? super T> filter)
      Deprecated.
       
      static <T> java.util.List<T> filter​(java.util.List<? extends T> list, Spec<? super T> filter)
      Deprecated.
       
      static <K,​V>
      java.util.Map<K,​V>
      filter​(java.util.Map<K,​V> map, java.util.Map<K,​V> destination, Spec<java.util.Map.Entry<K,​V>> filter)
      Deprecated.
       
      static <K,​V>
      java.util.Map<K,​V>
      filter​(java.util.Map<K,​V> map, Spec<java.util.Map.Entry<K,​V>> filter)
      Deprecated.
       
      static <T> java.util.Set<T> filter​(java.util.Set<? extends T> set, Spec<? super T> filter)
      Deprecated.
       
      static <T> java.util.List<T> filter​(T[] array, Spec<? super T> filter)
      Deprecated.
       
      static <T> T findFirst​(java.lang.Iterable<? extends T> source, Spec<? super T> filter)
      Deprecated.
       
      static <T> T findFirst​(T[] source, Spec<? super T> filter)
      Deprecated.
       
      static <T> T findSingle​(java.lang.Iterable<T> source)
      Deprecated.
      Returns null if the collection is empty otherwise expects a single(Iterable) element to be found.
      static <T> T first​(java.lang.Iterable<? extends T> source)
      Deprecated.
       
      static <T> java.util.List<T> flattenCollections​(java.lang.Class<T> type, java.lang.Object... things)
      Deprecated.
      Recursively unpacks all the given things into a flat list, ensuring they are of a certain type.
      static java.util.List<?> flattenCollections​(java.lang.Object... things)
      Deprecated.
      Recursively unpacks all the given things into a flat list.
      static <K,​V>
      java.util.Map<K,​java.util.Collection<V>>
      groupBy​(java.lang.Iterable<? extends V> iterable, Transformer<? extends K,​V> grouper)
      Deprecated.
       
      static <T,​I>
      T
      inject​(T target, java.lang.Iterable<? extends I> items, Action<CollectionUtils.InjectionStep<T,​I>> action)
      Deprecated.
       
      static <T> java.util.List<T> intersection​(java.util.Collection<? extends java.util.Collection<T>> availableValuesByDescriptor)
      Deprecated.
       
      static java.lang.String join​(java.lang.String separator, java.lang.Iterable<?> objects)
      Deprecated.
      Creates a string with toString() of each object with the given separator.
      static java.lang.String join​(java.lang.String separator, java.lang.Object[] objects)
      Deprecated.
      Creates a string with toString() of each object with the given separator.
      static <T> java.util.List<T> nonEmptyOrNull​(java.lang.Iterable<T> iterable)
      Deprecated.
       
      static <T> org.gradle.internal.Pair<java.util.Collection<T>,​java.util.Collection<T>> partition​(java.lang.Iterable<T> items, Spec<? super T> predicate)
      Deprecated.
      Partition given Collection into a Pair of Collections.
      static <E> boolean replace​(java.util.List<E> list, Spec<? super E> filter, Transformer<? extends E,​? super E> transformer)
      Deprecated.
       
      static <T> T single​(java.lang.Iterable<? extends T> source)
      Deprecated.
      Returns the single element in the collection or throws.
      static <T> java.util.List<T> sort​(java.lang.Iterable<? extends T> things, java.util.Comparator<? super T> comparator)
      Deprecated.
      Returns a sorted copy of the provided collection of things.
      static <T extends java.lang.Comparable<T>>
      java.util.List<T>
      sort​(java.lang.Iterable<T> things)
      Deprecated.
      Returns a sorted copy of the provided collection of things.
      static <C extends java.util.Collection<java.lang.String>>
      C
      stringize​(java.lang.Iterable<?> source, C destination)
      Deprecated.
       
      static java.util.List<java.lang.String> stringize​(java.util.Collection<?> source)
      Deprecated.
       
      static <T> java.util.List<T> toList​(java.lang.Iterable<? extends T> things)
      Deprecated.
       
      static <T> java.util.List<T> toList​(java.util.Enumeration<? extends T> things)
      Deprecated.
       
      static <T> java.util.List<T> toList​(T[] things)
      Deprecated.
       
      static <T> java.util.Set<T> toSet​(java.lang.Iterable<? extends T> things)
      Deprecated.
       
      static java.util.List<java.lang.String> toStringList​(java.lang.Iterable<?> iterable)
      Deprecated.
       
      static <T> java.lang.Iterable<? extends T> unpack​(java.lang.Iterable<? extends org.gradle.internal.Factory<? extends T>> factories)
      Deprecated.
       
      • Methods inherited from class java.lang.Object

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

      • CollectionUtils

        public CollectionUtils()
        Deprecated.
    • Method Detail

      • findSingle

        @Nullable
        public static <T> T findSingle​(java.lang.Iterable<T> source)
        Deprecated.
        Returns null if the collection is empty otherwise expects a single(Iterable) element to be found.
      • single

        public static <T> T single​(java.lang.Iterable<? extends T> source)
        Deprecated.
        Returns the single element in the collection or throws.
      • checkedCast

        public static <T> java.util.Collection<? extends T> checkedCast​(java.lang.Class<T> type,
                                                                        java.util.Collection<?> input)
        Deprecated.
      • findFirst

        @Nullable
        public static <T> T findFirst​(java.lang.Iterable<? extends T> source,
                                      Spec<? super T> filter)
        Deprecated.
      • findFirst

        @Nullable
        public static <T> T findFirst​(T[] source,
                                      Spec<? super T> filter)
        Deprecated.
      • first

        public static <T> T first​(java.lang.Iterable<? extends T> source)
        Deprecated.
      • any

        public static <T> boolean any​(java.lang.Iterable<? extends T> source,
                                      Spec<? super T> filter)
        Deprecated.
      • any

        public static <T> boolean any​(T[] source,
                                      Spec<? super T> filter)
        Deprecated.
      • filter

        public static <T> java.util.Set<T> filter​(java.util.Set<? extends T> set,
                                                  Spec<? super T> filter)
        Deprecated.
      • filter

        public static <T> java.util.List<T> filter​(java.util.List<? extends T> list,
                                                   Spec<? super T> filter)
        Deprecated.
      • filter

        public static <T> java.util.List<T> filter​(T[] array,
                                                   Spec<? super T> filter)
        Deprecated.
      • sort

        public static <T> java.util.List<T> sort​(java.lang.Iterable<? extends T> things,
                                                 java.util.Comparator<? super T> comparator)
        Deprecated.
        Returns a sorted copy of the provided collection of things. Uses the provided comparator to sort.
      • sort

        public static <T extends java.lang.Comparable<T>> java.util.List<T> sort​(java.lang.Iterable<T> things)
        Deprecated.
        Returns a sorted copy of the provided collection of things. Uses the natural ordering of the things.
      • filter

        public static <T,​C extends java.util.Collection<T>> C filter​(java.lang.Iterable<? extends T> source,
                                                                           C destination,
                                                                           Spec<? super T> filter)
        Deprecated.
      • filter

        public static <K,​V> java.util.Map<K,​V> filter​(java.util.Map<K,​V> map,
                                                                  Spec<java.util.Map.Entry<K,​V>> filter)
        Deprecated.
      • filter

        public static <K,​V> java.util.Map<K,​V> filter​(java.util.Map<K,​V> map,
                                                                  java.util.Map<K,​V> destination,
                                                                  Spec<java.util.Map.Entry<K,​V>> filter)
        Deprecated.
      • collectArray

        public static <R,​I> R[] collectArray​(I[] list,
                                                   java.lang.Class<R> newType,
                                                   Transformer<? extends R,​? super I> transformer)
        Deprecated.
      • collectArray

        public static <R,​I> R[] collectArray​(I[] list,
                                                   R[] destination,
                                                   Transformer<? extends R,​? super I> transformer)
        Deprecated.
      • collect

        public static <R,​I> java.util.List<R> collect​(I[] list,
                                                            Transformer<? extends R,​? super I> transformer)
        Deprecated.
      • collect

        public static <R,​I> java.util.Set<R> collect​(java.util.Set<? extends I> set,
                                                           Transformer<? extends R,​? super I> transformer)
        Deprecated.
      • collect

        public static <R,​I> java.util.List<R> collect​(java.lang.Iterable<? extends I> source,
                                                            Transformer<? extends R,​? super I> transformer)
        Deprecated.
      • collect

        public static <R,​I,​C extends java.util.Collection<R>> C collect​(java.lang.Iterable<? extends I> source,
                                                                                    C destination,
                                                                                    Transformer<? extends R,​? super I> transformer)
        Deprecated.
      • toStringList

        public static java.util.List<java.lang.String> toStringList​(java.lang.Iterable<?> iterable)
        Deprecated.
      • flattenCollections

        public static java.util.List<?> flattenCollections​(java.lang.Object... things)
        Deprecated.
        Recursively unpacks all the given things into a flat list. Nulls are not removed, they are left intact.
        Parameters:
        things - The things to flatten
        Returns:
        A flattened list of the given things
      • flattenCollections

        public static <T> java.util.List<T> flattenCollections​(java.lang.Class<T> type,
                                                               java.lang.Object... things)
        Deprecated.
        Recursively unpacks all the given things into a flat list, ensuring they are of a certain type. Nulls are not removed, they are left intact. If a non null object cannot be cast to the target type, a ClassCastException will be thrown.
        Type Parameters:
        T - The target type in the flattened list
        Parameters:
        things - The things to flatten
        Returns:
        A flattened list of the given things
      • toList

        public static <T> java.util.List<T> toList​(java.lang.Iterable<? extends T> things)
        Deprecated.
      • toList

        public static <T> java.util.List<T> toList​(java.util.Enumeration<? extends T> things)
        Deprecated.
      • intersection

        public static <T> java.util.List<T> intersection​(java.util.Collection<? extends java.util.Collection<T>> availableValuesByDescriptor)
        Deprecated.
      • toList

        public static <T> java.util.List<T> toList​(T[] things)
        Deprecated.
      • toSet

        public static <T> java.util.Set<T> toSet​(java.lang.Iterable<? extends T> things)
        Deprecated.
      • compact

        public static <E> java.util.List<E> compact​(java.util.List<E> list)
        Deprecated.
      • stringize

        public static <C extends java.util.Collection<java.lang.String>> C stringize​(java.lang.Iterable<?> source,
                                                                                     C destination)
        Deprecated.
      • stringize

        public static java.util.List<java.lang.String> stringize​(java.util.Collection<?> source)
        Deprecated.
      • replace

        public static <E> boolean replace​(java.util.List<E> list,
                                          Spec<? super E> filter,
                                          Transformer<? extends E,​? super E> transformer)
        Deprecated.
      • collectMap

        public static <K,​V> void collectMap​(java.util.Map<K,​V> destination,
                                                  java.lang.Iterable<? extends V> items,
                                                  Transformer<? extends K,​? super V> keyGenerator)
        Deprecated.
      • collectMap

        public static <K,​V> java.util.Map<K,​V> collectMap​(java.lang.Iterable<? extends V> items,
                                                                      Transformer<? extends K,​? super V> keyGenerator)
        Deprecated.
        Given a set of values, derive a set of keys and return a map
      • collectMapValues

        public static <K,​V> void collectMapValues​(java.util.Map<K,​V> destination,
                                                        java.lang.Iterable<? extends K> keys,
                                                        Transformer<? extends V,​? super K> keyGenerator)
        Deprecated.
      • collectMapValues

        public static <K,​V> java.util.Map<K,​V> collectMapValues​(java.lang.Iterable<? extends K> keys,
                                                                            Transformer<? extends V,​? super K> keyGenerator)
        Deprecated.
        Given a set of keys, derive a set of values and return a map
      • every

        public static <T> boolean every​(java.lang.Iterable<? extends T> things,
                                        Spec<? super T> predicate)
        Deprecated.
      • addAll

        public static <T,​C extends java.util.Collection<? super T>> C addAll​(C t1,
                                                                                   java.lang.Iterable<? extends T> t2)
        Deprecated.
        Utility for adding an iterable to a collection.
        Type Parameters:
        T - The element type of t1
        Parameters:
        t1 - The collection to add to
        t2 - The iterable to add each item of to the collection
        Returns:
        t1
      • addAll

        public static <T,​C extends java.util.Collection<? super T>> C addAll​(C t1,
                                                                                   T... t2)
        Deprecated.
        Utility for adding an array to a collection.
        Type Parameters:
        T - The element type of t1
        Parameters:
        t1 - The collection to add to
        t2 - The iterable to add each item of to the collection
        Returns:
        t1
      • diffSetsBy

        public static <T> CollectionUtils.SetDiff<T> diffSetsBy​(java.util.Set<? extends T> left,
                                                                java.util.Set<? extends T> right,
                                                                Transformer<?,​T> compareBy)
        Deprecated.
        Provides a “diff report” of how the two sets are similar and how they are different, comparing the entries by some aspect. The transformer is used to generate the value to use to compare the entries by. That is, the entries are not compared by equals by an attribute or characteristic. The transformer is expected to produce a unique value for each entry in a single set. Behaviour is undefined if this condition is not met.
        Type Parameters:
        T - The type of the entry objects
        Parameters:
        left - The set on the “left” side of the comparison.
        right - The set on the “right” side of the comparison.
        compareBy - Provides the value to compare entries from either side by
        Returns:
        A representation of the difference
      • join

        public static java.lang.String join​(java.lang.String separator,
                                            java.lang.Object[] objects)
        Deprecated.
        Creates a string with toString() of each object with the given separator.
         expect:
         join(",", new Object[]{"a"}) == "a"
         join(",", new Object[]{"a", "b", "c"}) == "a,b,c"
         join(",", new Object[]{}) == ""
         
        The separator must not be null and objects must not be null.
        Parameters:
        separator - The string by which to join each string representation
        objects - The objects to join the string representations of
        Returns:
        The joined string
      • join

        public static java.lang.String join​(java.lang.String separator,
                                            java.lang.Iterable<?> objects)
        Deprecated.
        Creates a string with toString() of each object with the given separator.
         expect:
         join(",", ["a"]) == "a"
         join(",", ["a", "b", "c"]) == "a,b,c"
         join(",", []) == ""
         
        The separator must not be null and objects must not be null.
        Parameters:
        separator - The string by which to join each string representation
        objects - The objects to join the string representations of
        Returns:
        The joined string
      • partition

        public static <T> org.gradle.internal.Pair<java.util.Collection<T>,​java.util.Collection<T>> partition​(java.lang.Iterable<T> items,
                                                                                                                    Spec<? super T> predicate)
        Deprecated.
        Partition given Collection into a Pair of Collections.
        Left
        Collection containing entries that satisfy the given predicate
        Right
        Collection containing entries that do NOT satisfy the given predicate
      • groupBy

        public static <K,​V> java.util.Map<K,​java.util.Collection<V>> groupBy​(java.lang.Iterable<? extends V> iterable,
                                                                                         Transformer<? extends K,​V> grouper)
        Deprecated.
      • unpack

        public static <T> java.lang.Iterable<? extends T> unpack​(java.lang.Iterable<? extends org.gradle.internal.Factory<? extends T>> factories)
        Deprecated.
      • nonEmptyOrNull

        @Nullable
        public static <T> java.util.List<T> nonEmptyOrNull​(java.lang.Iterable<T> iterable)
        Deprecated.
      • asCommandLine

        public static java.lang.String asCommandLine​(java.lang.Iterable<java.lang.String> arguments)
        Deprecated.