T
- The type of domain objects in this collection.Collection<T>
, Iterable<T>
ArtifactRepositoryContainer
, ArtifactTypeContainer
, AuthenticationContainer
, BinaryTasksCollection
, BuildDashboardReports
, BuildTypeContainer
, CheckstyleReports
, CodeNarcReports
, ConfigurationContainer
, DependencyConstraintSet
, DependencyReportContainer
, DependencySet
, DistributionContainer
, DomainObjectSet<T>
, ExtensiblePolymorphicDomainObjectContainer<T>
, FindBugsReports
, FlavorContainer
, IvyArtifactSet
, IvyConfigurationContainer
, JacocoReportsContainer
, JarBinarySpec.TasksCollection
, JDependReports
, JvmTestSuiteBinarySpec.JvmTestSuiteTasks
, MavenArtifactSet
, NamedDomainObjectCollection<T>
, NamedDomainObjectContainer<T>
, NamedDomainObjectList<T>
, NamedDomainObjectSet<T>
, NativeExecutableBinarySpec.TasksCollection
, NativeTestSuiteBinarySpec.TasksCollection
, NativeToolChainRegistry
, PlatformContainer
, PlayDistributionContainer
, PluginCollection<T>
, PluginContainer
, PmdReports
, PolymorphicDomainObjectContainer<T>
, PrebuiltLibraries
, ProjectSourceSet
, PublicationContainer
, PublishArtifactSet
, ReportContainer<T>
, Repositories
, RepositoryHandler
, SharedLibraryBinarySpec.TasksCollection
, SoftwareComponentContainer
, SourceSetContainer
, StaticLibraryBinarySpec.TasksCollection
, TaskCollection<T>
, TaskContainer
, TestSuiteTaskCollection
, TestTaskReports
public interface DomainObjectCollection<T> extends Collection<T>
A DomainObjectCollection
is a specialised Collection
that adds the ability to receive modification notifications and use live filtered sub collections.
The filtered collections returned by the filtering methods, such as matching(Closure)
, return collections that are live. That is, they reflect
changes made to the source collection that they were created from. This is true for filtered collections made from filtered collections etc.
You can also add actions which are executed as elements are added to the collection. Actions added to filtered collections will be fired if an addition/removal occurs for the source collection that matches the filter.
DomainObjectCollection
instances are not thread-safe and undefined behavior may result from the invocation of any method on a collection that is being mutated by another
thread; this includes direct invocations, passing the collection to a method that might perform invocations, and using an existing iterator to examine the collection.
Modifier and Type | Method | Description |
---|---|---|
void |
addAllLater(Provider<? extends Iterable<T>> provider) |
|
void |
addLater(Provider<? extends T> provider) |
Adds an element to this collection, given a
Provider that will provide the element when required. |
void |
all(Closure action) |
Executes the given closure against all objects in this collection, and any objects subsequently added to this collection.
|
void |
all(Action<? super T> action) |
Executes the given action against all objects in this collection, and any objects subsequently added to this
collection.
|
void |
configureEach(Action<? super T> action) |
Configures each element in this collection using the given action, as each element is required.
|
Collection<T> |
findAll(Closure spec) |
Returns a collection which contains the objects in this collection which meet the given closure specification.
|
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.
|
void |
whenObjectAdded(Closure action) |
Adds a closure to be called when an object is added to this collection.
|
Action<? super T> |
whenObjectAdded(Action<? super T> action) |
Adds an
Action to be executed when an object is added to this collection. |
void |
whenObjectRemoved(Closure action) |
Adds a closure to be called when an object is removed from 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> |
withType(Class<S> type) |
Returns a collection containing the objects in this collection of the given type.
|
<S extends T> |
withType(Class<S> type,
Closure configureClosure) |
Returns a collection containing the objects in this collection of the given type.
|
<S extends T> |
withType(Class<S> type,
Action<? super S> configureAction) |
Returns a collection containing the objects in this collection of the given type.
|
@Incubating void addLater(Provider<? extends T> provider)
Provider
that will provide the element when required.
Note: this method currently has a placeholder name and will almost certainly be renamed.provider
- A Provider
that can provide the element when required.@Incubating void addAllLater(Provider<? extends Iterable<T>> provider)
<S extends T> DomainObjectCollection<S> withType(Class<S> type)
type
- The type of objects to find.<S extends T> DomainObjectCollection<S> withType(Class<S> type, Action<? super S> configureAction)
withType(type).all(configureAction)
type
- The type of objects to find.configureAction
- The action to execute for each object in the resulting collection.<S extends T> DomainObjectCollection<S> withType(Class<S> type, Closure configureClosure)
withType(type).all(configureClosure)
.type
- The type of objects to find.configureClosure
- The closure to execute for each object in the resulting collection.DomainObjectCollection<T> matching(Spec<? super T> spec)
spec
- The specification to use.DomainObjectCollection<T> matching(Closure spec)
spec
- The specification to use. The closure gets a collection element as an argument.Action<? super T> whenObjectAdded(Action<? super T> action)
Action
to be executed when an object is added to this collection.
Like all(Action)
, this method will cause all objects in this container to be realized.
action
- The action to be executedvoid whenObjectAdded(Closure action)
action
- The closure to be calledwhenObjectAdded(Action)
Action<? super T> whenObjectRemoved(Action<? super T> action)
Action
to be executed when an object is removed from this collection.action
- The action to be executedvoid whenObjectRemoved(Closure action)
action
- The closure to be calledvoid all(Action<? super T> action)
action
- The action to be executedvoid all(Closure action)
action
- The action to be executedvoid configureEach(Action<? super T> action)
action
- A Action
that can configure the element when required.Collection<T> findAll(Closure spec)
spec
- The specification to use. The closure gets a collection element as an argument.