Package: org.gradle.api

## [Java] Interface DomainObjectCollection<T>

- org.gradle.api.DomainObjectCollection

- All Superinterfaces:
    Iterable

  A `DomainObjectCollection` is a specialised Collection that adds the ability to modification notifications and 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.

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

- - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `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` | `all(groovy.lang.Closure action)` Executes the given closure against all objects in this collection, and any objects subsequently added to this collection.
    `Collection<T>` | `findAll(groovy.lang.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.
    `DomainObjectCollection<T>` | `matching(groovy.lang.Closure spec)` Returns a collection which contains the objects in this collection which meet the given closure 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.
    `void` | `whenObjectRemoved(groovy.lang.Closure action)` Adds a closure to be called when an object is removed from this collection.
    `DomainObjectCollection<S>` | `withType(Class<S> type)` Returns a collection containing the objects in this collection of the given type.
    `DomainObjectCollection<S>` | `withType(Class<S> type, Action<? super S> configureAction)` Returns a collection containing the objects in this collection of the given type.
    `DomainObjectCollection<S>` | `withType(Class<S> type, groovy.lang.Closure configureClosure)` Returns a collection containing the objects in this collection of the given type.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `interface Collection` | `add, equals, hashCode, clear, contains, isEmpty, size, toArray, toArray, addAll, iterator, remove, containsAll, removeAll, retainAll`
    `class Object` | `wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll`

- - ### Method Detail

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

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

    - #### public Collection<T> findAll(groovy.lang.Closure spec)

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

      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.

    - #### public 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.

    - #### public DomainObjectCollection<T> 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.

    - #### public 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

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

    - #### public 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

    - #### public void whenObjectRemoved(groovy.lang.Closure action)

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

      Parameters:
        `action` - The closure to be called

    - #### public 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 collection if there are no such objects in this collection.

    - #### public DomainObjectCollection<S> withType(Class<S> type, Action<? super S> 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 collection if there are no such objects in this collection.

    - #### public DomainObjectCollection<S> withType(Class<S> 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 collection if there are no such objects in this collection.