Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.gradle.api
Interface DomainObjectCollection<T>

Type Parameters:
  `T` - The type of domain objects in this collection.

All Superinterfaces:
  java.lang.Iterable<T>

All Known Subinterfaces:
  ConfigurationContainer, ConfigurationHandler, DomainObjectContainer<T>, PluginCollection<T>, PluginContainer, ProjectPluginsContainer, RepositoryHandler, ResolverContainer, SourceSetContainer, TaskCollection<T>, TaskContainer

    public interface DomainObjectCollection<T>

extends java.lang.Iterable<T>

A `DomainObjectCollection` represents a read-only set of domain objects of type `T`.

The object in a collection are accessable 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
`void` | `allObjects(Action<? super T> action)` Executes the given action against all objects in this collection, and any objects subsequently added to this collection.
`void` | `allObjects(groovy.lang.Closure action)` Executes the given closure against all objects in this collection, and any objects subsequently added to this collection.
`java.util.Set<T>` | `findAll(Spec<? super T> spec)` Returns the objects in this collection which meet the given specification.
`T` | `findByName(java.lang.String name)` Locates an object by name, returning null if there is no such object.
`java.util.Set<T>` | `getAll()` Returns the objects in this collection.
`java.util.Map<java.lang.String,T>` | `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.
`DomainObjectCollection<T>` | `matching(Spec<? super T> spec)` Returns a collection which contains the objects in this collection which meet the given specification.
`Action<? super T>` | `whenObjectAdded(Action<? super T> action)` Adds an `Action` to be executed when an object is added to this collection.
`void` | `whenObjectAdded(groovy.lang.Closure action)` Adds a closure to be called when an object is added to this collection.
`Action<? super T>` | `whenObjectRemoved(Action<? super T> action)` Adds an `Action` to be executed when an object is removed from this collection.
`
`<S extends T> DomainObjectCollection<S>`
` | `withType(java.lang.Class<S> type)` Returns a collection containing the objects in this collection of the given type.

Methods inherited from interface java.lang.Iterable
`iterator`

Method Detail

### getAll

    java.util.Set<T> getAll()

  Returns the objects in this collection.

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

### getAsMap

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

### getByName

    T getByName(java.lang.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(java.lang.String name,
                groovy.lang.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(java.lang.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.

### findAll

    java.util.Set<T> findAll(Spec<? super T> spec)

  Returns the objects in this collection which meet the given specification.

  Parameters:
    `spec` - The specification to use.
  Returns:
    The matching objects. Returns an empty set if there are no such objects in this collection.

### withType

    <S extends T> DomainObjectCollection<S> withType(java.lang.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.

  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

    DomainObjectCollection<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.

  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.

### whenObjectAdded

    Action<? super T> whenObjectAdded(Action<? super T> action)

  Adds an `Action` to be executed when an object is added to this collection.

  Parameters:
    `action` - The action to be executed
  Returns:
    the supplied action

### whenObjectAdded

    void whenObjectAdded(groovy.lang.Closure action)

  Adds a closure to be called when an object is added to this collection. The newly added object is passed to the closure as the parameter.

  Parameters:
    `action` - The closure to be called

### whenObjectRemoved

    Action<? super T> whenObjectRemoved(Action<? super T> action)

  Adds an `Action` to be executed when an object is removed from this collection.

  Parameters:
    `action` - The action to be executed
  Returns:
    the supplied action

### allObjects

    void allObjects(Action<? super T> action)

  Executes the given action against all objects in this collection, and any objects subsequently added to this collection.

  Parameters:
    `action` - The action to be executed

### allObjects

    void allObjects(groovy.lang.Closure action)

  Executes the given closure against all objects in this collection, and any objects subsequently added to this collection.

  Parameters:
    `action` - The closure to be called

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD