org.gradle.api
Interface DomainObjectCollection<T>

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

public interface DomainObjectCollection<T>
extends Iterable<T>

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

You can use the methods of this interface to query the elements of the collection. You can also add actions which are executed as elements are added to this collection.


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(Closure action)
          Executes the given closure against all objects in this collection, and any objects subsequently added to this collection.
 Set<T> findAll(Spec<? super T> spec)
          Returns the objects in this collection which meet the given specification.
 Set<T> getAll()
          Returns the objects in this collection.
 DomainObjectCollection<T> matching(Closure spec)
          Returns a collection which contains the objects in this collection which meet the given closure specification.
 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(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(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

Set<T> getAll()
Returns the objects in this collection.

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

findAll

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

matching

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

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.

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(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(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