Interface NamedDomainObjectCollection<T>

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      boolean add​(T e)
      Adds an object to the collection, if there is no existing object in the collection with the same name.
      boolean addAll​(java.util.Collection<? extends T> c)
      Adds any of the given objects to the collection that do not have the same name as any existing element.
      Rule addRule​(java.lang.String description, Closure ruleAction)
      Adds a rule to this collection.
      Rule addRule​(java.lang.String description, Action<java.lang.String> ruleAction)
      Adds a rule to this collection.
      Rule addRule​(Rule rule)
      Adds a rule to this collection.
      T findByName​(java.lang.String name)
      Locates an object by name, returning null if there is no such object.
      java.util.SortedMap<java.lang.String,​T> getAsMap()
      Returns the objects in this collection, as a map from object name to object instance.
      T getAt​(java.lang.String name)
      Locates an object by name, failing if there is no such object.
      T getByName​(java.lang.String name)
      Locates an object by name, failing if there is no such object.
      T getByName​(java.lang.String name, Closure configureClosure)
      Locates an object by name, failing if there is no such object.
      T getByName​(java.lang.String name, Action<? super T> configureAction)
      Locates an object by name, failing if there is no such object.
      NamedDomainObjectCollectionSchema getCollectionSchema()
      Provides access to the schema of all created or registered named domain objects in this collection.
      Namer<T> getNamer()
      An object that represents the naming strategy used to name objects of this collection.
      java.util.SortedSet<java.lang.String> getNames()
      Returns the names of the objects in this collection as a Set of Strings.
      java.util.List<Rule> getRules()
      Returns the rules used by this collection.
      NamedDomainObjectCollection<T> matching​(Closure spec)
      Returns a collection which contains the objects in this collection which meet the given closure specification.
      NamedDomainObjectCollection<T> matching​(Spec<? super T> spec)
      Returns a collection which contains the objects in this collection which meet the given specification.
      NamedDomainObjectProvider<T> named​(java.lang.String name)
      Locates a object by name, without triggering its creation or configuration, failing if there is no such object.
      <S extends T>
      NamedDomainObjectProvider<S>
      named​(java.lang.String name, java.lang.Class<S> type)
      Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object.
      <S extends T>
      NamedDomainObjectProvider<S>
      named​(java.lang.String name, java.lang.Class<S> type, Action<? super S> configurationAction)
      Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object.
      NamedDomainObjectProvider<T> named​(java.lang.String name, Action<? super T> configurationAction)
      Locates a object by name, without triggering its creation or configuration, failing if there is no such object.
      default NamedDomainObjectCollection<T> named​(Spec<java.lang.String> nameFilter)
      Returns a collection containing the objects with names matching the provided filter.
      <S extends T>
      NamedDomainObjectCollection<S>
      withType​(java.lang.Class<S> type)
      Returns a collection containing the objects in this collection of the given type.
      • Methods inherited from interface java.util.Collection

        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

      • add

        boolean add​(T e)
        Adds an object to the collection, if there is no existing object in the collection with the same name.
        Specified by:
        add in interface java.util.Collection<T>
        Parameters:
        e - the item to add to the collection
        Returns:
        true if the item was added, or false if an item with the same name already exists.
      • addAll

        boolean addAll​(java.util.Collection<? extends T> c)
        Adds any of the given objects to the collection that do not have the same name as any existing element.
        Specified by:
        addAll in interface java.util.Collection<T>
        Parameters:
        c - the items to add to the collection
        Returns:
        true if any item was added, or false if all items have non unique names within this collection.
      • getNamer

        Namer<T> getNamer()
        An object that represents the naming strategy used to name objects of this collection.
        Returns:
        Object representing the naming strategy.
      • getAsMap

        java.util.SortedMap<java.lang.String,​T> getAsMap()

        Returns the objects in this collection, as a map from object name to object instance.

        The map is ordered by the natural ordering of the object names (i.e. keys).

        Returns:
        The objects. Returns an empty map if this collection is empty.
      • getNames

        java.util.SortedSet<java.lang.String> getNames()

        Returns the names of the objects in this collection as a Set of Strings.

        The set of names is in natural ordering.

        Returns:
        The names. Returns an empty set if this collection is empty.
      • findByName

        @Nullable
        T findByName​(java.lang.String name)
        Locates an object by name, returning null if there is no such object.
        Parameters:
        name - The object name
        Returns:
        The object with the given name, or null if there is no such object in this collection.
      • getByName

        T getByName​(java.lang.String name)
             throws UnknownDomainObjectException
        Locates an object by name, failing if there is no such object.
        Parameters:
        name - The object name
        Returns:
        The object with the given name. Never returns null.
        Throws:
        UnknownDomainObjectException - when there is no such object in this collection.
      • getByName

        T getByName​(java.lang.String name,
                    Closure configureClosure)
             throws UnknownDomainObjectException
        Locates an object by name, failing if there is no such object. The given configure closure is executed against the object before it is returned from this method. The object is passed to the closure as its delegate.
        Parameters:
        name - The object name
        configureClosure - The closure to use to configure the object.
        Returns:
        The object with the given name, after the configure closure has been applied to it. Never returns null.
        Throws:
        UnknownDomainObjectException - when there is no such object in this collection.
      • getByName

        T getByName​(java.lang.String name,
                    Action<? super T> configureAction)
             throws UnknownDomainObjectException
        Locates an object by name, failing if there is no such object. The given configure action is executed against the object before it is returned from this method.
        Parameters:
        name - The object name
        configureAction - The action to use to configure the object.
        Returns:
        The object with the given name, after the configure action has been applied to it. Never returns null.
        Throws:
        UnknownDomainObjectException - when there is no such object in this collection.
        Since:
        3.1
      • getAt

        T getAt​(java.lang.String name)
         throws UnknownDomainObjectException
        Locates an object by name, failing if there is no such object. This method is identical to getByName(String). You can call this method in your build script by using the groovy [] operator.
        Parameters:
        name - The object name
        Returns:
        The object with the given name. Never returns null.
        Throws:
        UnknownDomainObjectException - when there is no such object in this collection.
      • addRule

        Rule addRule​(Rule rule)
        Adds a rule to this collection. The given rule is invoked when an unknown object is requested by name.
        Parameters:
        rule - The rule to add.
        Returns:
        The added rule.
      • addRule

        Rule addRule​(java.lang.String description,
                     Closure ruleAction)
        Adds a rule to this collection. The given closure is executed when an unknown object is requested by name. The requested name is passed to the closure as a parameter.
        Parameters:
        description - The description of the rule.
        ruleAction - The closure to execute to apply the rule.
        Returns:
        The added rule.
      • addRule

        Rule addRule​(java.lang.String description,
                     Action<java.lang.String> ruleAction)
        Adds a rule to this collection. The given action is executed when an unknown object is requested by name. The requested name is passed to the action.
        Parameters:
        description - The description of the rule.
        ruleAction - The action to execute to apply the rule.
        Returns:
        The added rule.
        Since:
        3.3
      • getRules

        java.util.List<Rule> getRules()
        Returns the rules used by this collection.
        Returns:
        The rules, in the order they will be applied.
      • withType

        <S extends TNamedDomainObjectCollection<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.
        Specified by:
        withType in interface DomainObjectCollection<T>
        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.
      • named

        @Incubating
        default NamedDomainObjectCollection<T> named​(Spec<java.lang.String> nameFilter)
        Returns a collection containing the objects with names matching the provided filter. The returned collection is live, so that when matching objects are added to this collection, they are also visible in the filtered collection. This method will NOT cause any pending objects in this container to be realized.
        Parameters:
        nameFilter - The specification to test names against.
        Returns:
        The collection of objects with names satisfying the filter. Returns an empty collection if there are no such objects in this collection.
        Since:
        8.6
      • matching

        NamedDomainObjectCollection<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.
        Specified by:
        matching in interface DomainObjectCollection<T>
        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

        NamedDomainObjectCollection<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.
        Specified by:
        matching in interface DomainObjectCollection<T>
        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.
      • named

        NamedDomainObjectProvider<T> named​(java.lang.String name)
                                    throws UnknownDomainObjectException
        Locates a object by name, without triggering its creation or configuration, failing if there is no such object.
        Parameters:
        name - The object's name
        Returns:
        A Provider that will return the object when queried. The object may be created and configured at this point, if not already.
        Throws:
        UnknownDomainObjectException - If a object with the given name is not defined.
        Since:
        4.10
      • named

        NamedDomainObjectProvider<T> named​(java.lang.String name,
                                           Action<? super T> configurationAction)
                                    throws UnknownDomainObjectException
        Locates a object by name, without triggering its creation or configuration, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.
        Parameters:
        name - The object's name
        Returns:
        A Provider that will return the object when queried. The object may be created and configured at this point, if not already.
        Throws:
        UnknownDomainObjectException - If an object with the given name is not defined.
        Since:
        5.0
      • named

        <S extends TNamedDomainObjectProvider<S> named​(java.lang.String name,
                                                         java.lang.Class<S> type)
                                                  throws UnknownDomainObjectException
        Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object.
        Parameters:
        name - The object's name
        type - The object's type
        Returns:
        A Provider that will return the object when queried. The object may be created and configured at this point, if not already.
        Throws:
        UnknownDomainObjectException - If an object with the given name is not defined.
        Since:
        5.0
      • named

        <S extends TNamedDomainObjectProvider<S> named​(java.lang.String name,
                                                         java.lang.Class<S> type,
                                                         Action<? super S> configurationAction)
                                                  throws UnknownDomainObjectException
        Locates a object by name and type, without triggering its creation or configuration, failing if there is no such object. The given configure action is executed against the object before it is returned from the provider.
        Parameters:
        name - The object's name
        type - The object's type
        configurationAction - The action to use to configure the object.
        Returns:
        A Provider that will return the object when queried. The object may be created and configured at this point, if not already.
        Throws:
        UnknownDomainObjectException - If an object with the given name is not defined.
        Since:
        5.0