org.gradle.api
Interface NamedDomainObjectCollection<T>

Type Parameters:
T - The type of domain objects in this collection.
All Superinterfaces:
DomainObjectCollection<T>, Iterable<T>
All Known Subinterfaces:
ConfigurationContainer, NamedDomainObjectContainer<T>, RepositoryHandler, ResolverContainer, SourceSetContainer, TaskCollection<T>, TaskContainer

public interface NamedDomainObjectCollection<T>
extends DomainObjectCollection<T>

A NamedDomainObjectCollection represents a read-only set of domain objects of type T. Each domain object in this collection has a name, which uniquely identifies the object in this collection.

Each object in a collection are accessible as read-only properties of the collection, using the name of the object as the property name. For example:

 tasks.add('myTask')
 tasks.myTask.dependsOn someOtherTask
 

A dynamic method is added for each object which takes a configuration closure. This is equivalent to calling getByName(String, groovy.lang.Closure). For example:

 tasks.add('myTask')
 tasks.myTask {
     dependsOn someOtherTask
 }
 

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

 tasks.add('myTask')
 tasks['myTask'].dependsOn someOtherTask
 


Method Summary
 T findByName(String name)
          Locates an object by name, returning null if there is no such object.
 Map<String,T> getAsMap()
          Returns the objects in this collection, as a map from object name to object instance.
 T getAt(String name)
          Locates an object by name, failing if there is no such task.
 T getByName(String name)
          Locates an object by name, failing if there is no such object.
 T getByName(String name, Closure configureClosure)
          Locates an object by name, failing if there is no such object.
 NamedDomainObjectCollection<T> matching(Closure spec)
          Returns a collection which contains the objects in this collection which meet the given closure specification.
 NamedDomainObjectCollection<T> matching(Spec<? super T> spec)
          Returns a collection which contains the objects in this collection which meet the given specification.
<S extends T>
NamedDomainObjectCollection<S>
withType(Class<S> type)
          Returns a collection containing the objects in this collection of the given type.
 
Methods inherited from interface org.gradle.api.DomainObjectCollection
allObjects, allObjects, findAll, getAll, whenObjectAdded, whenObjectAdded, whenObjectRemoved
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

getAsMap

Map<String,T> getAsMap()
Returns the objects in this collection, as a map from object name to object instance.

Returns:
The objects. Returns an empty map if this collection is empty.

findByName

T findByName(String name)
Locates an object by name, returning null if there is no such object.

Parameters:
name - The object name
Returns:
The object with the given name, or null if there is no such object in this collection.

getByName

T getByName(String name)
            throws UnknownDomainObjectException
Locates an object by name, failing if there is no such object.

Parameters:
name - The object name
Returns:
The object with the given name. Never returns null.
Throws:
UnknownDomainObjectException - when there is no such object in this collection.

getByName

T getByName(String name,
            Closure configureClosure)
            throws UnknownDomainObjectException
Locates an object by name, failing if there is no such object. The given configure closure is executed against the object before it is returned from this method. The object is passed to the closure as it's delegate.

Parameters:
name - The object name
configureClosure - The closure to use to configure the object.
Returns:
The object with the given name, after the configure closure has been applied to it. Never returns null.
Throws:
UnknownDomainObjectException - when there is no such object in this collection.

getAt

T getAt(String name)
        throws UnknownDomainObjectException
Locates an object by name, failing if there is no such task. This method is identical to getByName(String). You can call this method in your build script by using the groovy [] operator.

Parameters:
name - The object name
Returns:
The object with the given name. Never returns null.
Throws:
UnknownDomainObjectException - when there is no such object in this collection.

withType

<S extends T> NamedDomainObjectCollection<S> withType(Class<S> type)
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.

Specified by:
withType in interface DomainObjectCollection<T>
Parameters:
type - The type of objects to find.
Returns:
The matching objects. Returns an empty set if there are no such objects in this collection.

matching

NamedDomainObjectCollection<T> matching(Spec<? super T> spec)
Returns a collection which contains the objects in this collection which meet the given specification. The returned collection is live, so that when matching objects are added to this collection, they are also visible in the filtered collection.

Specified by:
matching in interface DomainObjectCollection<T>
Parameters:
spec - The specification to use.
Returns:
The collection of matching objects. Returns an empty collection if there are no such objects in this collection.

matching

NamedDomainObjectCollection<T> matching(Closure spec)
Returns a collection which contains the objects in this collection which meet the given closure specification. The returned collection is live, so that when matching objects are added to this collection, they are also visible in the filtered collection.

Specified by:
matching in interface DomainObjectCollection<T>
Parameters:
spec - The specification to use. The closure gets a collection element as an argument.
Returns:
The collection of matching objects. Returns an empty collection if there are no such objects in this collection.