T
- The type of domain objects in this container.public interface NamedDomainObjectContainer<T> extends NamedDomainObjectSet<T>, org.gradle.util.Configurable<NamedDomainObjectContainer<T>>
A named domain object container is a specialisation of NamedDomainObjectSet
that adds the ability to create
instances of the element type.
Implementations may use different strategies for creating new object instances.
Note that a container is an implementation of SortedSet
, which means that the container is guaranteed
to only contain elements with unique names within this container. Furthermore, items are ordered by their name.
NamedDomainObjectSet
Modifier and Type | Method and Description |
---|---|
NamedDomainObjectContainer<T> |
configure(Closure configureClosure)
Allows the container to be configured, creating missing objects as they are referenced.
|
T |
create(String name)
Creates a new item with the given name, adding it to this container.
|
T |
create(String name,
Action<? super T> configureAction)
Creates a new item with the given name, adding it to this container, then configuring it with the given action.
|
T |
create(String name,
Closure configureClosure)
Creates a new item with the given name, adding it to this container, then configuring it with the given closure.
|
T |
maybeCreate(String name)
Looks for an item with the given name, creating and adding it to this container if it does not exist.
|
NamedDomainObjectProvider<T> |
register(String name)
Defines a new object, which will be created when it is required.
|
NamedDomainObjectProvider<T> |
register(String name,
Action<? super T> configurationAction)
Defines a new object, which will be created and configured when it is required.
|
findAll, matching, matching, withType
add, addAll, addRule, addRule, addRule, findByName, getAsMap, getAt, getByName, getByName, getByName, getCollectionSchema, getNamer, getNames, getRules, named
addLater, all, all, configureEach, whenObjectAdded, whenObjectAdded, whenObjectRemoved, whenObjectRemoved, withType, withType
clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
T create(String name) throws InvalidUserDataException
name
- The name to assign to the created objectInvalidUserDataException
- if an object with the given name already exists in this container.T maybeCreate(String name)
name
- The name to find or assign to the created objectT create(String name, Closure configureClosure) throws InvalidUserDataException
name
- The name to assign to the created objectconfigureClosure
- The closure to configure the created object withInvalidUserDataException
- if an object with the given name already exists in this container.T create(String name, Action<? super T> configureAction) throws InvalidUserDataException
name
- The name to assign to the created objectconfigureAction
- The action to configure the created object withInvalidUserDataException
- if an object with the given name already exists in this container.NamedDomainObjectContainer<T> configure(Closure configureClosure)
Allows the container to be configured, creating missing objects as they are referenced.
TODO: example usage
configure
in interface org.gradle.util.Configurable<NamedDomainObjectContainer<T>>
configureClosure
- The closure to configure this container with@Incubating NamedDomainObjectProvider<T> register(String name, Action<? super T> configurationAction) throws InvalidUserDataException
NamedDomainObjectCollection.getByName(java.lang.String)
or when Provider.get()
is called on the return value of this method.
It is generally more efficient to use this method instead of create(java.lang.String, org.gradle.api.Action)
or create(java.lang.String)
, as those methods will eagerly create and configure the object, regardless of whether that object is required for the current build or not. This method, on the other hand, will defer creation and configuration until required.
name
- The name of the object.configurationAction
- The action to run to configure the object. This action runs when the object is required.Provider
that whose value will be the object, when queried.InvalidUserDataException
- If a object with the given name already exists in this project.@Incubating NamedDomainObjectProvider<T> register(String name) throws InvalidUserDataException
NamedDomainObjectCollection.getByName(java.lang.String)
or when Provider.get()
is called on the return value of this method.
It is generally more efficient to use this method instead of create(java.lang.String)
, as that methods will eagerly create he object, regardless of whether that object is required for the current build or not. This method, on the other hand, will defer creation until required.
name
- The name of the object.Provider
that whose value will be the object, when queried.InvalidUserDataException
- If a object with the given name already exists in this project.