NamedDomainObjectCollection

A NamedDomainObjectCollection represents a collection of objects that have an inherent, constant, name.

Objects to be added to a named domain object collection must implement equals() in such a way that no two objects with different names are considered equal. That is, all equality tests must consider the name as an equality key. Behavior is undefined if two objects with different names are considered equal by their equals() implementation.

All implementations must guarantee that all elements in the collection are uniquely named. That is, an attempt to add an object with a name equal to the name of any existing object in the collection will fail. Implementations may choose to simply return false from add(T) or to throw an exception.

Objects in the collection are accessible as read-only properties, using the name of the object as the property name. For example (assuming the 'name' property provides the object name):

books.add(new Book(name: "gradle", title: null))
books.gradle.title = "Gradle in Action"

A dynamic method is added for each object which takes a configuration closure. This is equivalent to calling getByName. For example:

books.add(new Book(name: "gradle", title: null))
books.gradle {
  title = "Gradle in Action"
}

You can also use the [] operator to access the objects of a collection by name. For example:

books.add(new Book(name: "gradle", title: null))
books['gradle'].title = "Gradle in Action"

Rule objects can be attached to the collection in order to respond to requests for objects by name where no object with name exists in the collection. This mechanism can be used to create objects on demand. For example:

books.addRule('create any') { books.add(new Book(name: "gradle", title: null)) }
books.gradle.name == "gradle"

Parameters

<T>

The type of objects in this collection.

Inheritors

Functions

Link copied to clipboard
abstract fun add(e: T): Boolean
Adds an object to the collection, if there is no existing object in the collection with the same name.
Link copied to clipboard
abstract fun addAll(c: Collection<out T>): Boolean
Adds any of the given objects to the collection that do not have the same name as any existing element.
Link copied to clipboard
abstract fun addAllLater(provider: Provider<out Iterable<T>>)
Link copied to clipboard
abstract fun addLater(provider: Provider<out T>)
Link copied to clipboard
abstract fun addRule(rule: Rule): Rule
abstract fun addRule(description: String, ruleAction: Closure): Rule
abstract fun addRule(description: String, ruleAction: Action<String>): Rule
Adds a rule to this collection.
Link copied to clipboard
abstract fun all(action: Action<in T>)
Link copied to clipboard
abstract fun clear()
Link copied to clipboard
abstract fun configureEach(action: Action<in T>)
Link copied to clipboard
abstract fun contains(p: Any): Boolean
Link copied to clipboard
abstract fun containsAll(p: Collection<out Any>): Boolean
Link copied to clipboard
abstract fun equals(p: Any): Boolean
Link copied to clipboard
abstract fun findAll(spec: Closure): Collection<T>
Link copied to clipboard
@Nullable
abstract fun findByName(name: String): T
Locates an object by name, returning null if there is no such object.
Link copied to clipboard
open fun forEach(action: Consumer<in T>)
Link copied to clipboard
operator fun <T : Any> NamedDomainObjectCollection<T>.get(name: String): T

Locates an object by name, failing if there is no such object.

Link copied to clipboard
abstract fun getAsMap(): SortedMap<String, T>
Returns the objects in this collection, as a map from object name to object instance.
Link copied to clipboard
abstract fun getAt(name: String): T
Locates an object by name, failing if there is no such object.
Link copied to clipboard
abstract fun getByName(name: String): T
abstract fun getByName(name: String, configureClosure: Closure): T
abstract fun getByName(name: String, configureAction: Action<in T>): T
Locates an object by name, failing if there is no such object.
Link copied to clipboard
inline fun <T : Any> NamedDomainObjectCollection<out Any>.getByName(name: String): T

Locates an object by name and casts it to the expected type T.

inline fun <T : Any> NamedDomainObjectCollection<out Any>.getByName(name: String, configure: T.() -> Unit): T

Locates an object by name and casts it to the expected type T then configures it.

Locates an object by name and casts it to the expected type.

fun <T : Any> NamedDomainObjectCollection<out Any>.getByName(name: String, type: KClass<T>, configure: T.() -> Unit): T

Locates an object by name and casts it to the expected type then configures it.

Link copied to clipboard
Provides access to the schema of all created or registered named domain objects in this collection.
Link copied to clipboard
abstract fun getNamer(): Namer<T>
An object that represents the naming strategy used to name objects of this collection.
Link copied to clipboard
abstract fun getNames(): SortedSet<String>
Returns the names of the objects in this collection as a Set of Strings.
Link copied to clipboard
abstract fun getRules(): List<Rule>
Returns the rules used by this collection.
Link copied to clipboard
abstract fun hashCode(): Int
Link copied to clipboard
abstract fun isEmpty(): Boolean
Link copied to clipboard
abstract fun iterator(): Iterator<T>
abstract fun iterator(): Iterator<E>
Link copied to clipboard
abstract fun matching(spec: Closure): NamedDomainObjectCollection<T>
abstract fun matching(spec: Spec<in T>): NamedDomainObjectCollection<T>
Link copied to clipboard
abstract fun named(name: String): NamedDomainObjectProvider<T>
abstract fun named(name: String, configurationAction: Action<in T>): NamedDomainObjectProvider<T>
Locates a object by name, without triggering its creation or configuration, failing if there is no such object.
Returns a collection containing the objects with names matching the provided filter.
abstract fun <S : T?> named(name: String, type: Class<S>): NamedDomainObjectProvider<S>
abstract fun <S : T?> named(name: String, type: Class<S>, configurationAction: Action<in S>): NamedDomainObjectProvider<S>
Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object.
Link copied to clipboard

Locates an object by name and type, without triggering its creation or configuration, failing if there is no such object.

inline fun <S : T, T : Any> NamedDomainObjectCollection<T>.named(name: String, type: KClass<S>, configurationAction: Action<in S>): NamedDomainObjectProvider<S>

Kotlin extension function taking kotlin.reflect.KClass for org.gradle.api.NamedDomainObjectCollection.named.

inline fun <T : Any> NamedDomainObjectCollection<out Any>.named(name: String, noinline configuration: T.() -> Unit): NamedDomainObjectProvider<T>
fun <T : Any> NamedDomainObjectCollection<out Any>.named(name: String, type: KClass<T>, configuration: T.() -> Unit): NamedDomainObjectProvider<T>

Configures an object by name and type, without triggering its creation or configuration, failing if there is no such object.

Link copied to clipboard
open fun parallelStream(): Stream<E>
Link copied to clipboard

Allows a NamedDomainObjectCollection to be used as a property delegate.

Link copied to clipboard
abstract fun remove(p: Any): Boolean
Link copied to clipboard
abstract fun removeAll(p: Collection<out Any>): Boolean
Link copied to clipboard
open fun removeIf(filter: Predicate<in E>): Boolean
Link copied to clipboard
abstract fun retainAll(p: Collection<out Any>): Boolean
Link copied to clipboard
abstract fun size(): Int
Link copied to clipboard
Link copied to clipboard
open fun stream(): Stream<E>
Link copied to clipboard
abstract fun toArray(): Array<Any>
abstract fun <T> toArray(p: Array<T>): Array<T>
Link copied to clipboard
abstract fun whenObjectAdded(action: Closure)
abstract fun whenObjectAdded(action: Action<in T>): Action<in T>
Link copied to clipboard
abstract fun whenObjectRemoved(action: Closure)
abstract fun whenObjectRemoved(action: Action<in T>): Action<in T>
Link copied to clipboard
abstract fun <S : T?> withType(type: Class<S>): NamedDomainObjectCollection<S>
Link copied to clipboard

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>, configureAction: Action<in S>): DomainObjectCollection<S>

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

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