Interface DomainObjectCollection<T>

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void addAllLater​(Provider<? extends java.lang.Iterable<T>> provider)
      Adds elements to this collection, given a Provider of Iterable that will provide the elements when required.
      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.
      java.util.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>
      DomainObjectCollection<S>
      withType​(java.lang.Class<S> type)
      Returns a collection containing the objects in this collection of the given type.
      <S extends T>
      DomainObjectCollection<S>
      withType​(java.lang.Class<S> type, Closure configureClosure)
      Returns a collection containing the objects in this collection of the given type.
      <S extends T>
      DomainObjectCollection<S>
      withType​(java.lang.Class<S> type, Action<? super S> configureAction)
      Returns a collection containing the objects in this collection of the given type.
      • Methods inherited from interface java.util.Collection

        add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Method Detail

      • addLater

        void addLater​(Provider<? extends T> provider)
        Adds an element to this collection, given a Provider that will provide the element when required.
        Parameters:
        provider - A Provider that can provide the element when required.
        Since:
        4.8
      • addAllLater

        void addAllLater​(Provider<? extends java.lang.Iterable<T>> provider)
        Adds elements to this collection, given a Provider of Iterable that will provide the elements when required.
        Parameters:
        provider - A Provider of Iterable that can provide the elements when required.
        Since:
        5.0
      • withType

        <S extends TDomainObjectCollection<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 collection if there are no such objects in this collection.
      • withType

        <S extends TDomainObjectCollection<S> withType​(java.lang.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.
      • withType

        <S extends TDomainObjectCollection<S> withType​(java.lang.Class<S> type,
                                                         @DelegatesTo(genericTypeIndex=0)
                                                         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.
      • 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.

        Like all(Action), this method will cause all objects in this container to be realized.

        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
        See Also:
        whenObjectAdded(Action)
      • 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
      • whenObjectRemoved

        void whenObjectRemoved​(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
      • all

        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
      • all

        void all​(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
      • configureEach

        void configureEach​(Action<? super T> action)
        Configures each element in this collection using the given action, as each element is required. Actions are run in the order added.
        Parameters:
        action - A Action that can configure the element when required.
        Since:
        4.9
      • findAll

        java.util.Collection<T> findAll​(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.