# DomainObjectCollection

interface DomainObjectCollection<T> : Collection<E> (source)

A `DomainObjectCollection` is a specialised Collection that adds the ability to receive modification notifications and use live filtered sub collections.

The filtered collections returned by the filtering methods, such as matching, return collections that are live. That is, they reflect changes made to the source collection that they were created from. This is true for filtered collections made from filtered collections etc.

You can also add actions that are executed as elements are added to the collection. Actions added to filtered collections will be fired if an addition/removal occurs for the source collection that matches the filter.

`DomainObjectCollection` instances are not thread-safe and undefined behavior may result from the invocation of any method on a collection that is being mutated by another thread; this includes direct invocations, passing the collection to a method that might perform invocations, and using an existing iterator to examine the collection.

#### Parameters

<T>

The type of objects in this collection.

#### Inheritors

NamedDomainObjectCollection
DomainObjectSet

## Functions

add
Link copied to clipboard
abstract fun add(p: E): Boolean
addAll
Link copied to clipboard
abstract fun addAll(p: Collection<out E>): Boolean
addAllLater
Link copied to clipboard
abstract fun addAllLater(provider: Provider<out Iterable<T>>)
Adds elements to this collection, given a Provider of Iterable that will provide the elements when required.
addLater
Link copied to clipboard
abstract fun addLater(provider: Provider<out T>)
Adds an element to this collection, given a Provider that will provide the element when required.
all
Link copied to clipboard
abstract fun all(action: Closure)
Executes the given closure against all objects in this collection, and any objects subsequently added to this collection.
abstract fun all(action: Action<in T>)
Executes the given action against all objects in this collection, and any objects subsequently added to this collection.
clear
Link copied to clipboard
abstract fun clear()
configureEach
Link copied to clipboard
abstract fun configureEach(action: Action<in T>)
Configures each element in this collection using the given action, as each element is required.
contains
Link copied to clipboard
abstract fun contains(p: Any): Boolean
containsAll
Link copied to clipboard
abstract fun containsAll(p: Collection<out Any>): Boolean
disallowChanges
Link copied to clipboard
@Incubating
open fun disallowChanges()
Disallows further structural modifications to this collection.
equals
Link copied to clipboard
abstract fun equals(p: Any): Boolean
findAll
Link copied to clipboard
abstract fun findAll(spec: Closure): Collection<T>
Returns a collection which contains the objects in this collection which meet the given closure specification.
forEach
Link copied to clipboard
open fun forEach(p: Consumer<in T>)
hashCode
Link copied to clipboard
abstract fun hashCode(): Int
isEmpty
Link copied to clipboard
abstract fun isEmpty(): Boolean
iterator
Link copied to clipboard
abstract fun iterator(): Iterator<T>
abstract fun iterator(): Iterator<E>
matching
Link copied to clipboard
abstract fun matching(spec: Closure): DomainObjectCollection<T>
Returns a collection which contains the objects in this collection which meet the given closure specification.
abstract fun matching(spec: Spec<in T>): DomainObjectCollection<T>
Returns a collection which contains the objects in this collection which meet the given specification.
parallelStream
Link copied to clipboard
open fun parallelStream(): Stream<E>
remove
Link copied to clipboard
abstract fun remove(p: Any): Boolean
removeAll
Link copied to clipboard
abstract fun removeAll(p: Collection<out Any>): Boolean
removeIf
Link copied to clipboard
open fun removeIf(p: Predicate<in E>): Boolean
retainAll
Link copied to clipboard
abstract fun retainAll(p: Collection<out Any>): Boolean
size
Link copied to clipboard
abstract fun size(): Int
spliterator
Link copied to clipboard
open fun spliterator(): Spliterator<T>
open fun spliterator(): Spliterator<E>
stream
Link copied to clipboard
open fun stream(): Stream<E>
toArray
Link copied to clipboard
abstract fun toArray(): Array<Any>
abstract fun <T> toArray(p: Array<T>): Array<T>
whenObjectAdded
Link copied to clipboard
abstract fun whenObjectAdded(action: Closure)
Adds a closure to be called when an object is added to this collection.
abstract fun whenObjectAdded(action: Action<in T>): Action<in T>
Adds an `Action` to be executed when an object is added to this collection.
whenObjectRemoved
Link copied to clipboard
abstract fun whenObjectRemoved(action: Closure)
Adds a closure to be called when an object is removed from this collection.
abstract fun whenObjectRemoved(action: Action<in T>): Action<in T>
Adds an `Action` to be executed when an object is removed from this collection.
withType
Link copied to clipboard
abstract fun <S : T?> withType(type: Class<S>): DomainObjectCollection<S>
abstract fun <S : T?> withType(type: Class<S>, @DelegatesTo(genericTypeIndex = 0) configureClosure: Closure): DomainObjectCollection<S>
abstract fun <S : T?> withType(type: Class<S>, configureAction: Action<in S>): DomainObjectCollection<S>
Returns a collection containing the objects in this collection of the given type.
withType
Link copied to clipboard
inline fun <S : Any> DomainObjectCollection<in S>.withType(): <Error class: unknown class>

Returns a collection containing the objects in this collection of the given type. The returned collection is live, so that when matching objects are later added to this collection, they are also visible in the filtered collection.

inline fun <S : Any> DomainObjectCollection<in S>.withType(noinline configuration: S.() -> Unit): DomainObjectCollection<S>

Returns a collection containing the objects in this collection of the given type. Equivalent to calling `withType(type).all(configureAction)`.

inline fun <S : T, T : Any> DomainObjectCollection<T>.withType(type: KClass<S>): DomainObjectCollection<S>
inline fun <S : T, T : Any> DomainObjectCollection<T>.withType(type: KClass<S>, configureAction: Action<in S>): DomainObjectCollection<S>

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.DomainObjectCollection.withType.