Groovy Documentation

org.gradle.api
[Java] Interface NamedDomainObjectCollection

org.gradle.api.NamedDomainObjectCollection
  org.gradle.api.DomainObjectCollection
All Superinterfaces:
DomainObjectCollection

public interface NamedDomainObjectCollection
extends DomainObjectCollection

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
 
Parameters:
- The type of domain objects in this collection.


Method Summary
T findByName(java.lang.String name)

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

java.util.Map getAsMap()

Returns the objects in this collection, as a map from object name to object instance.

T getAt(java.lang.String name)

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

T getByName(java.lang.String name)

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

T getByName(java.lang.String name, groovy.lang.Closure configureClosure)

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

NamedDomainObjectCollection matching(Spec spec)

{@inheritDoc}

NamedDomainObjectCollection matching(groovy.lang.Closure spec)

{@inheritDoc}

NamedDomainObjectCollection withType(java.lang.Class type)

{@inheritDoc}

 
Methods inherited from interface DomainObjectCollection
allObjects, allObjects, findAll, getAll, matching, matching, whenObjectAdded, whenObjectAdded, whenObjectRemoved, withType
 
Methods inherited from interface java.lang.Iterable
java.lang.Iterable#iterator()
 
Methods inherited from class java.lang.Object
java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString()
 

Method Detail

findByName

public T findByName(java.lang.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.


getAsMap

public java.util.Map 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.


getAt

public T getAt(java.lang.String name)
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.
throws:
UnknownDomainObjectException when there is no such object in this collection.
Parameters:
name - The object name
Returns:
The object with the given name. Never returns null.


getByName

public T getByName(java.lang.String name)
Locates an object by name, failing if there is no such object.
throws:
UnknownDomainObjectException when there is no such object in this collection.
Parameters:
name - The object name
Returns:
The object with the given name. Never returns null.


getByName

public T getByName(java.lang.String name, groovy.lang.Closure configureClosure)
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.
throws:
UnknownDomainObjectException when there is no such object in this collection.
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.


matching

public NamedDomainObjectCollection matching(Spec spec)
{@inheritDoc}


matching

public NamedDomainObjectCollection matching(groovy.lang.Closure spec)
{@inheritDoc}


withType

public NamedDomainObjectCollection withType(java.lang.Class type)
{@inheritDoc}


 

Groovy Documentation