gradle
8.2

# CollectionUtils

abstract class CollectionUtils

### Deprecated

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 org.gradle.util.internal.CollectionUtils.

#### Deprecated

Will be removed in Gradle 9.0.

## Constructors

CollectionUtils
Link copied to clipboard
constructor()

## Types

InjectionStep
Link copied to clipboard
open class InjectionStep<T, I>
Injection step.
SetDiff
Link copied to clipboard
open class SetDiff<T>
The result of diffing two sets.

## Functions

addAll
Link copied to clipboard
open fun <T, C : Collection<out Any>?> addAll(t1: C, t2: Array<T>): C
Utility for adding an array to a collection.
open fun <T, C : Collection<out Any>?> addAll(t1: C, t2: Iterable<out T>): C
Utility for adding an iterable to a collection.
any
Link copied to clipboard
open fun <T> any(source: Array<T>, filter: Spec<out Any>): Boolean
open fun <T> any(source: Iterable<out T>, filter: Spec<out Any>): Boolean
asCommandLine
Link copied to clipboard
open fun asCommandLine(arguments: Iterable<String>): String
checkedCast
Link copied to clipboard
open fun <T> checkedCast(type: Class<T>, input: Collection<out Any>): Collection<out T>
collect
Link copied to clipboard
open fun <R, I> collect(list: Array<I>, transformer: Transformer<out R, out Any>): List<R>
open fun <R, I> collect(source: Iterable<out I>, transformer: Transformer<out R, out Any>): List<R>
open fun <R, I> collect(set: Set<out I>, transformer: Transformer<out R, out Any>): Set<R>
open fun <R, I, C : Collection<R>?> collect(source: Iterable<out I>, destination: C, transformer: Transformer<out R, out Any>): C
collectArray
Link copied to clipboard
open fun <R, I> collectArray(list: Array<I>, destination: Array<R>, transformer: Transformer<out R, out Any>): Array<R>
open fun <R, I> collectArray(list: Array<I>, newType: Class<R>, transformer: Transformer<out R, out Any>): Array<R>
collectMap
Link copied to clipboard
open fun <K, V> collectMap(items: Iterable<out V>, keyGenerator: Transformer<out K, out Any>): Map<K, V>
Given a set of values, derive a set of keys and return a map
open fun <K, V> collectMap(destination: Map<K, V>, items: Iterable<out V>, keyGenerator: Transformer<out K, out Any>)
collectMapValues
Link copied to clipboard
open fun <K, V> collectMapValues(keys: Iterable<out K>, keyGenerator: Transformer<out V, out Any>): Map<K, V>
Given a set of keys, derive a set of values and return a map
open fun <K, V> collectMapValues(destination: Map<K, V>, keys: Iterable<out K>, keyGenerator: Transformer<out V, out Any>)
compact
Link copied to clipboard
open fun <E> compact(list: List<E>): List<E>
diffSetsBy
Link copied to clipboard
open fun <T> diffSetsBy(left: Set<out T>, right: Set<out T>, compareBy: Transformer<out Any, T>): CollectionUtils.SetDiff<T>
Provides a “diff report” of how the two sets are similar and how they are different, comparing the entries by some aspect.
every
Link copied to clipboard
open fun <T> every(things: Iterable<out T>, predicate: Spec<out Any>): Boolean
filter
Link copied to clipboard
open fun <T> filter(array: Array<T>, filter: Spec<out Any>): List<T>
open fun <T> filter(list: List<out T>, filter: Spec<out Any>): List<T>
open fun <K, V> filter(map: Map<K, V>, filter: Spec<Map.Entry<K, V>>): Map<K, V>
open fun <T> filter(set: Set<out T>, filter: Spec<out Any>): Set<T>
open fun <T, C : Collection<T>?> filter(source: Iterable<out T>, destination: C, filter: Spec<out Any>): C
open fun <K, V> filter(map: Map<K, V>, destination: Map<K, V>, filter: Spec<Map.Entry<K, V>>): Map<K, V>
findFirst
Link copied to clipboard
@Nullable
open fun <T> findFirst(source: Array<T>, filter: Spec<out Any>): T
@Nullable
open fun <T> findFirst(source: Iterable<out T>, filter: Spec<out Any>): T
findSingle
Link copied to clipboard
@Nullable
open fun <T> findSingle(source: Iterable<T>): T
Returns null if the collection is empty otherwise expects a single element to be found.
first
Link copied to clipboard
open fun <T> first(source: Iterable<out T>): T
flattenCollections
Link copied to clipboard
open fun flattenCollections(things: Array<Any>): List<out Any>
Recursively unpacks all the given things into a flat list.
open fun <T> flattenCollections(type: Class<T>, things: Array<Any>): List<T>
Recursively unpacks all the given things into a flat list, ensuring they are of a certain type.
groupBy
Link copied to clipboard
open fun <K, V> groupBy(iterable: Iterable<out V>, grouper: Transformer<out K, V>): Map<K, Collection<V>>
inject
Link copied to clipboard
open fun <T, I> inject(target: T, items: Iterable<out I>, action: Action<CollectionUtils.InjectionStep<T, I>>): T
intersection
Link copied to clipboard
open fun <T> intersection(availableValuesByDescriptor: Collection<out Collection<T>>): List<T>
join
Link copied to clipboard
open fun join(separator: String, objects: Iterable<out Any>): String
open fun join(separator: String, objects: Array<Any>): String
Creates a string with `toString()` of each object with the given separator.
nonEmptyOrNull
Link copied to clipboard
@Nullable
open fun <T> nonEmptyOrNull(iterable: Iterable<T>): List<T>
partition
Link copied to clipboard
open fun <T> partition(items: Iterable<T>, predicate: Spec<out Any>): Pair<Collection<T>, Collection<T>>
Partition given Collection into a Pair of Collections.
replace
Link copied to clipboard
open fun <E> replace(list: List<E>, filter: Spec<out Any>, transformer: Transformer<out E, out Any>): Boolean
single
Link copied to clipboard
open fun <T> single(source: Iterable<out T>): T
Returns the single element in the collection or throws.
sort
Link copied to clipboard
open fun <T : Comparable<T>?> sort(things: Iterable<T>): List<T>
open fun <T> sort(things: Iterable<out T>, comparator: Comparator<out Any>): List<T>
Returns a sorted copy of the provided collection of things.
stringize
Link copied to clipboard
open fun stringize(source: Collection<out Any>): List<String>
open fun <C : Collection<String>?> stringize(source: Iterable<out Any>, destination: C): C
toList
Link copied to clipboard
open fun <T> toList(things: Array<T>): List<T>
open fun <T> toList(things: Iterable<out T>): List<T>
open fun <T> toList(things: Enumeration<out T>): List<T>
toSet
Link copied to clipboard
open fun <T> toSet(things: Iterable<out T>): Set<T>
toStringList
Link copied to clipboard
open fun toStringList(iterable: Iterable<out Any>): List<String>
unpack
Link copied to clipboard
open fun <T> unpack(factories: Iterable<out Factory<out T>>): Iterable<out T>