|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
An Attribute without a parent context is probably not a very
good design idea. After all, known attributes usually reside in the
context of a parent Class construct. Our Attribute
pattern implementation, therefore, provides a generic parent container,
represented by the AttributeCollection interface.
You will most likely need an object that implements a derived interface, such
as AttributeList or AttributeSet. This can be done
by means of an AttributeFactory,
which will hide the particular implementation classes from client code.
| Field Summary | |
static java.lang.String |
SEPARATOR
Path separator for AttributeSet hierarchies. |
| Method Summary | |
void |
add(Attribute attribute)
Adds the given Attribute to the collection. |
void |
clear()
Clears the entire AttributeCollection. |
java.lang.Object |
clone()
Clones / Deep-copies this AttributeCollection. |
void |
delete(java.lang.String name)
Deletes any Attribute with the given name from the collection.
|
int |
depth()
Returns the maximum depth of this hierarchy. |
java.util.Iterator |
find(java.lang.String path)
This method allows callers to retrieve attributes that are nested in an AttributeCollection to any arbitrary depth. |
void |
findAndDelete_nothrow(java.lang.String path)
Deletes the Attribute at the give location collection. |
void |
findAndDelete(java.lang.String path)
Deletes the Attribute at the given location from the
collection. |
java.util.Iterator |
findAndFlatten(java.lang.String path)
This method assembles attributes that match the path into a list of flat ones. |
java.util.Iterator |
findAndRemove_nothrow(java.lang.String path)
Removes the Attribute with the given path from the
AttributeCollection. |
java.util.Iterator |
findAndRemove(java.lang.String path)
Removes the Attribute with the given path from the
collection. |
java.util.Iterator |
findNoThrow(java.lang.String path)
Same as the plain find() method, with the difference that no
exception is thrown in case nothing is found or in case the search path
is invalid. |
void |
freeze()
Freezes the collection by making all attributes immutable and prohibiting the further addition of new ones. |
AttributeTypeSet |
getTypeSet()
Returns all AttributeType objects of each Attribute
in this set as a AttributeTypeSet. |
AttributeTypeSet |
getTypeTree()
Returns the AttributeType‘s of each attribute in this
set as a AttributeTypeSet. |
java.util.Iterator |
iterator()
Returns an Iterator for all attributes in this
collection. |
AttributeCollection |
merge(AttributeCollection other)
This method creates a new AttributeCollection reflecting a
merge of the given collection with this collection. |
int |
size()
Returns the number of elements in this collection. |
void |
unfreeze()
Releases the collection freeze state. |
void |
visit(AttributeCollectionVisitor visitor)
Visits this collection of Attribute objects and all nested
collections, then invokes visit(Attribute) from the given
AttributeCollectionVisitor on all Attribute
objects. |
| Methods inherited from interface com.tensegrity.generic.constraint.Restrictable |
getConstraint, setConstraint |
| Field Detail |
public static final java.lang.String SEPARATOR
AttributeSet hierarchies. The separator
must not be part of an attribute's name.
Must always be of length 1.
| Method Detail |
public void freeze()
public void unfreeze()
public int size()
AttributeCollection. This method will only return the number
of Attribute objects that are directly contained by this instance.
public void clear()
AttributeCollection.
public int depth()
AttributeSet then the depth is 1, if there is
another level of nesting then the depth is 2 and so on.
public void add(Attribute attribute)
throws IllegalAttributeException,
ConstraintViolationException
Attribute to the collection.AttributeCollection. That means it is not allowed to assign
an AttributeCollection to the value of an Attribute
and add the Attribute directly or indirectly to the original
AttributeCollection. It is the responsibility of the user to
make sure such cycles are not accidently built.
attribute - the attribute to add. It is not allowed to add
null as an attribute, doing so will result in a
IllegalAttributeException.
IllegalAttributeException - if the given Attribute is
invalid. The exception might as well be thrown in case the
AttributeCollection implementation can not deal with the
particular attribute implementation that is attempted to be added.
A null attribute or an attribute with its key being
null is considered to be in an illegal state and will cause
the exception to be thrown. The exception is thrown also if the
AttributeCollection is frozen. Attempting to add a an
Attribute to a frozen collection is forbidden and thus will
generate the exception until an unfreeze operation is performed.
ConstraintViolationException - if the attribute does not conform to
the constraints of this attribute set.freeze(),
unfreeze()public void delete(java.lang.String name)
Attribute with the given name from the collection.
Nested Attributecollection instances are not searched.
name - the name of the Attribute to be removed.public AttributeTypeSet getTypeSet()
AttributeType objects of each Attribute
in this set as a AttributeTypeSet.
AttributeTypeSet.public AttributeTypeSet getTypeTree()
AttributeType‘s of each attribute in this
set as a AttributeTypeSet. Each subset is added to
it‘s parent set as an AttributeType.
public java.util.Iterator iterator()
Iterator for all attributes in this
collection.
public java.util.Iterator find(java.lang.String path)
throws VisitException
AttributeCollection to any arbitrary depth. For example, an
AttributeCollection might look like this:
set0 -+---- attr01
|
|---- attr02
|
|---- set1 -+---- attr11
|
|---- set2 -+---- attr21
Finding Attribute attr21 in this
Attribute hierarchy given a reference to the top-level
AttributeCollection set0 is done by invoking
set0.find("set0:set1:set2:attr21");
AttributeCollection, a VisitException
is thrown. This exception is also thrown if the path ends with a separator
character or if the path components are not found during the search.
path - the path pattern to find in the set and nested sets.
Attributes.
VisitException - if the path is not valid or nothing was found.findNoThrow(String)public java.util.Iterator findNoThrow(java.lang.String path)
find() method, with the difference that no
exception is thrown in case nothing is found or in case the search path
is invalid. The exception is silently ignored and an empty
Iterator is returned.
path - the path pattern to find in the collection and nested collections.
Attributes that were
found.find(String)
public java.util.Iterator findAndRemove(java.lang.String path)
throws VisitException
Attribute with the given path from the
collection. An Iterator containing all removed
Attribute objects is returned to the caller.
path - the pattern of the Attribute(s) to remove.
Iterator for all removed Attributes.
VisitException - if the path is not valid or nothing was found.find(String)public java.util.Iterator findAndRemove_nothrow(java.lang.String path)
Attribute with the given path from the
AttributeCollection. This method is analogous to the
findAndRemove method, but no exceptions are thrown. In case
the given path is illegal or nothing is found an empty
Iterator is returned.
path - the path pattern of the Attribute(s) to remove.
Iterator for all the Attributes that
were removed or an empty Iterator if nothing was removed.find(String),
findAndRemove(String)
public void findAndDelete(java.lang.String path)
throws VisitException
Attribute at the given location from the
collection. This method recognizes paths the same way as the
find method does.
path - the path pattern for the Attribute(s) to remove.
VisitException - if the path is not valid or nothing was found.public void findAndDelete_nothrow(java.lang.String path)
Attribute at the give location collection. This
method recognizes paths the same way the find method does.
This method is analogous to the findAndRemove method, but no
exceptions are thrown.
path - the pattern for the Attributes to remove.findAndDelete(String)
public java.util.Iterator findAndFlatten(java.lang.String path)
throws VisitException,
IllegalNameException,
IllegalValueException,
ConstraintViolationException,
java.lang.CloneNotSupportedException,
IllegalAttributeException
path - the path of the attribute(s) to remove.
VisitException - thrown if an error occured.
IllegalNameException - thrown if an error occured.
IllegalValueException - thrown if an error occured.
ConstraintViolationException - thrown if an error occured.
java.lang.CloneNotSupportedException - thrown if an error occured.
IllegalAttributeException - thrown if an error occured.
public void visit(AttributeCollectionVisitor visitor)
throws VisitException
Attribute objects and all nested
collections, then invokes visit(Attribute) from the given
AttributeCollectionVisitor on all Attribute
objects.
visitor - the AttributeCollectionVisitor that visits
the found Attributes.
VisitException - thrown if the visitor got into to an exceptional
state.
public java.lang.Object clone()
throws java.lang.CloneNotSupportedException
AttributeCollection.
AttributeCollection.
java.lang.CloneNotSupportedException - if invoking clone()
method on some indwell object is not allowed or supported.
public AttributeCollection merge(AttributeCollection other)
throws IllegalAttributeException,
ConstraintViolationException
AttributeCollection reflecting a
merge of the given collection with this collection. Each subclass of
AttributeCollection regulates how a merge will be done.
! The given attribute collection other must not contain
elements with the same name !
other - the other collection you want to merge with this collection.
IllegalAttributeException - if an illegal attribute was found.
ConstraintViolationException - if a violation of constraints occurs.
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||