Groovy Documentation

org.gradle.api
[Java] Interface DomainObjectCollection


public interface DomainObjectCollection
extends java.lang.Iterable

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.

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


Method Summary
void all(Action action)

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

void all(groovy.lang.Closure action)

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

void allObjects(Action 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 findAll(Spec spec)

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

java.util.Set getAll()

Returns the objects in this collection.

DomainObjectCollection matching(Spec spec)

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

DomainObjectCollection matching(groovy.lang.Closure spec)

Returns a collection which contains the objects in this collection which meet the given closure specification.

Action whenObjectAdded(Action 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 whenObjectRemoved(Action action)

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

DomainObjectCollection withType(java.lang.Class type)

Returns a collection containing the objects in this collection of the given type.

DomainObjectCollection withType(java.lang.Class type, Action configureAction)

Returns a collection containing the objects in this collection of the given type.

DomainObjectCollection withType(java.lang.Class type, groovy.lang.Closure configureClosure)

Returns a collection containing the objects in this collection of the given type.

 
Methods inherited from interface java.lang.Iterable
java.lang.Iterable#iterator()
 
Methods inherited from class java.lang.Object
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#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Method Detail

all

public void all(Action 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


all

public void all(groovy.lang.Closure action)
Executes the given closure against all objects in this collection, and any objects subsequently added to this collection. The object is passed to the closure as the closure delegate. Alternatively, it is also passed as a parameter.
Parameters:
action - The action to be executed


allObjects

@Deprecated
public void allObjects(Action action)
Executes the given action against all objects in this collection, and any objects subsequently added to this collection.
deprecated:
Use all(Action) instead.
Parameters:
action - The action to be executed


allObjects

@Deprecated
public void allObjects(groovy.lang.Closure action)
Executes the given closure against all objects in this collection, and any objects subsequently added to this collection.
deprecated:
Use all(groovy.lang.Closure) instead.
Parameters:
action - The closure to be called


findAll

public java.util.Set findAll(Spec 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.


getAll

public java.util.Set getAll()
Returns the objects in this collection.
Returns:
The objects. Returns an empty set if this collection is empty.


matching

public DomainObjectCollection matching(Spec 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

public DomainObjectCollection matching(groovy.lang.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

public Action whenObjectAdded(Action 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

public 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

public Action whenObjectRemoved(Action 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


withType

public DomainObjectCollection withType(java.lang.Class 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.


withType

public DomainObjectCollection withType(java.lang.Class type, Action configureAction)
Returns a collection containing the objects in this collection of the given type. Equivalent to calling withType(type).all(configureAction)
Parameters:
type - The type of objects to find.
configureAction - The action to execute for each object in the resulting collection.
Returns:
The matching objects. Returns an empty set if there are no such objects in this collection.


withType

public DomainObjectCollection withType(java.lang.Class type, groovy.lang.Closure configureClosure)
Returns a collection containing the objects in this collection of the given type. Equivalent to calling withType(type).all(configureClosure).
Parameters:
type - The type of objects to find.
configureClosure - The closure to execute for each object in the resulting collection.
Returns:
The matching objects. Returns an empty set if there are no such objects in this collection.


 

Groovy Documentation