public class DefaultNamedDomainObjectCollection<T> extends DefaultDomainObjectCollection<T> implements NamedDomainObjectCollection<T>, DynamicObjectAware
| Modifier | Constructor and Description |
|---|---|
protected |
DefaultNamedDomainObjectCollection(Class<? extends T> type,
Collection<T> store,
CollectionEventRegister<T> eventRegister,
Instantiator instantiator,
Namer<? super T> namer) |
|
DefaultNamedDomainObjectCollection(Class<? extends T> type,
Collection<T> store,
Instantiator instantiator,
Namer<? super T> namer) |
|
DefaultNamedDomainObjectCollection(DefaultNamedDomainObjectCollection<? super T> collection,
CollectionFilter<T> filter,
Instantiator instantiator,
Namer<? super T> namer) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T o)
Subclasses that can guarantee that the backing store enforces name uniqueness should override this to simply call super.add(T) (avoiding an unnecessary lookup)
|
Rule |
addRule(Rule rule)
Adds a rule to this collection.
|
Rule |
addRule(String description,
Closure ruleAction)
Adds a rule to this collection.
|
protected void |
assertCanAdd(String name)
Asserts that an item with the given name can be added to this collection.
|
protected void |
assertCanAdd(T t)
Asserts that the given item can be added to this collection.
|
protected UnknownDomainObjectException |
createNotFoundException(String name) |
protected <S extends T> |
filtered(CollectionFilter<S> filter)
Creates a filtered version of this collection.
|
T |
findByName(String name)
Locates an object by name, returning null if there is no such object.
|
protected T |
findByNameWithoutRules(String name) |
DynamicObject |
getAsDynamicObject()
Returns a
DynamicObject which can be used to access the domain objects as dynamic properties and
methods. |
SortedMap<String,T> |
getAsMap()
Returns the objects in this collection, as a map from object name to object instance.
|
T |
getAt(String name)
Locates an object by name, failing if there is no such task.
|
T |
getByName(String name)
Locates an object by name, failing if there is no such object.
|
T |
getByName(String name,
Closure configureClosure)
Locates an object by name, failing if there is no such object.
|
Convention |
getConvention() |
String |
getDisplayName() |
protected DynamicObject |
getElementsAsDynamicObject() |
ExtensionContainer |
getExtensions() |
protected Instantiator |
getInstantiator() |
Namer<T> |
getNamer()
An object that represents the naming strategy used to name objects of this collection.
|
List<Rule> |
getRules()
Returns the rules used by this collection.
|
protected String |
getTypeDisplayName() |
protected void |
handleAttemptToAddItemWithNonUniqueName(T o)
Subclass hook for implementations wanting to throw an exception when an attempt is made to add
an item with the same name as an existing item.
|
protected boolean |
hasWithName(String name) |
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.
|
protected T |
removeByName(String name) |
<S extends T> |
withType(Class<S> type)
Returns a collection containing the objects in this collection of the given type.
|
addAll, all, all, assertMutable, beforeChange, clear, contains, containsAll, createFilter, createFilter, createFilter, filteredEvents, filteredStore, findAll, findAll, getEventRegister, getStore, getType, isEmpty, iterator, remove, removeAll, retainAll, size, whenObjectAdded, whenObjectAdded, whenObjectRemoved, whenObjectRemoved, withType, withTypetoArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddAllall, all, findAll, whenObjectAdded, whenObjectAdded, whenObjectRemoved, whenObjectRemoved, withType, withTypepublic DefaultNamedDomainObjectCollection(Class<? extends T> type, Collection<T> store, Instantiator instantiator, Namer<? super T> namer)
protected DefaultNamedDomainObjectCollection(Class<? extends T> type, Collection<T> store, CollectionEventRegister<T> eventRegister, Instantiator instantiator, Namer<? super T> namer)
public DefaultNamedDomainObjectCollection(DefaultNamedDomainObjectCollection<? super T> collection, CollectionFilter<T> filter, Instantiator instantiator, Namer<? super T> namer)
public boolean add(T o)
add in interface Collection<T>add in interface NamedDomainObjectCollection<T>add in class DefaultDomainObjectCollection<T>o - the item to add to the collectiontrue if the item was added, or false if an item with the same name already exists.protected void handleAttemptToAddItemWithNonUniqueName(T o)
Subclass hook for implementations wanting to throw an exception when an attempt is made to add an item with the same name as an existing item.
This implementation does not thrown an exception, meaning that add(T) will simply return false.
o - The item that is being attempted to add.protected void assertCanAdd(String name)
protected void assertCanAdd(T t)
public Namer<T> getNamer()
NamedDomainObjectCollectiongetNamer in interface NamedDomainObjectCollection<T>protected Instantiator getInstantiator()
protected <S extends T> DefaultNamedDomainObjectCollection<S> filtered(CollectionFilter<S> filter)
filtered in class DefaultDomainObjectCollection<T>public String getDisplayName()
public SortedMap<String,T> getAsMap()
NamedDomainObjectCollectionReturns 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).
getAsMap in interface NamedDomainObjectCollection<T>public <S extends T> NamedDomainObjectCollection<S> withType(Class<S> type)
DomainObjectCollectionwithType in interface DomainObjectCollection<T>withType in interface NamedDomainObjectCollection<T>withType in class DefaultDomainObjectCollection<T>type - The type of objects to find.public NamedDomainObjectCollection<T> matching(Spec<? super T> spec)
DomainObjectCollectionmatching in interface DomainObjectCollection<T>matching in interface NamedDomainObjectCollection<T>matching in class DefaultDomainObjectCollection<T>spec - The specification to use.public NamedDomainObjectCollection<T> matching(Closure spec)
DomainObjectCollectionmatching in interface DomainObjectCollection<T>matching in interface NamedDomainObjectCollection<T>matching in class DefaultDomainObjectCollection<T>spec - The specification to use. The closure gets a collection element as an argument.public T findByName(String name)
NamedDomainObjectCollectionfindByName in interface NamedDomainObjectCollection<T>name - The object nameprotected boolean hasWithName(String name)
public T getByName(String name) throws UnknownDomainObjectException
NamedDomainObjectCollectiongetByName in interface NamedDomainObjectCollection<T>name - The object nameUnknownDomainObjectException - when there is no such object in this collection.public T getByName(String name, Closure configureClosure) throws UnknownDomainObjectException
NamedDomainObjectCollectiongetByName in interface NamedDomainObjectCollection<T>name - The object nameconfigureClosure - The closure to use to configure the object.UnknownDomainObjectException - when there is no such object in this collection.public T getAt(String name) throws UnknownDomainObjectException
NamedDomainObjectCollectionNamedDomainObjectCollection.getByName(String). You can call this method in your build script by using the groovy [] operator.getAt in interface NamedDomainObjectCollection<T>name - The object nameUnknownDomainObjectException - when there is no such object in this collection.public DynamicObject getAsDynamicObject()
DynamicObject which can be used to access the domain objects as dynamic properties and
methods.getAsDynamicObject in interface DynamicObjectAwarepublic Convention getConvention()
public ExtensionContainer getExtensions()
protected DynamicObject getElementsAsDynamicObject()
public Rule addRule(Rule rule)
NamedDomainObjectCollectionaddRule in interface NamedDomainObjectCollection<T>rule - The rule to add.public Rule addRule(String description, Closure ruleAction)
NamedDomainObjectCollectionaddRule in interface NamedDomainObjectCollection<T>description - The description of the rule.ruleAction - The closure to execute to apply the rule.public List<Rule> getRules()
NamedDomainObjectCollectiongetRules in interface NamedDomainObjectCollection<T>protected UnknownDomainObjectException createNotFoundException(String name)
protected String getTypeDisplayName()
Copyright © 2013. All rights reserved