com.tensegrity.generic.util
Class AttributeOperations

java.lang.Object
  extended bycom.tensegrity.generic.util.AttributeOperations

public class AttributeOperations
extends java.lang.Object

AttributeOperations

Author:
BurkhardWick

Field Summary
static int INDEX_ADDITIONAL_IN_FIRST_SET
          INDEX_ADDITIONAL_IN_FIRST_SET: Array index for compareAttributeSets(AttributeSet, AttributeSet)
static int INDEX_ADDITIONAL_IN_SECOND_SET
          INDEX_ADDITIONAL_IN_SECOND_SET: Array index for compareAttributeSets(AttributeSet, AttributeSet)
static int INDEX_DIFFERENCES
          INDEX_DIFFERENCES: Array index for compareAttributeSets(AttributeSet, AttributeSet)
static int INDEX_DIFFERENCES_VALUES_IN_SECOND_SET
          INDEX_DIFFERENCES_VALUES_IN_SECOND_SET: Array index for compareAttributeSets(AttributeSet, AttributeSet)
 
Method Summary
static AttributeSet[] compareAttributeSets(AttributeSet set1, AttributeSet set2)
          Compares two AttributeSets and returns three new AttributeSets describing the differences.
static AttributeSet createAttributeSetPath(java.lang.String path)
          Creates nested AttributeSets to represent the given path.
static AttributeSet createAttributeSetPath(java.lang.String path, Attribute leaf)
          Creates nested AttributeSets to represent the given path.
static Attribute findByPath(AttributeSet parent, java.lang.String path)
          Utility method to find an attribute in an attribute tree.
static java.util.Collection flattenStructure(AttributeCollection attribs)
          Converts a hierarchical attribute collection structure to a flat list of attributes by storing the hierarchical information as complete path name in the new names of the attributes that are stored in the list.
static java.util.Collection flattenStructure(AttributeCollection attribs, boolean includeCollections)
          Converts a hierarchical attribute collection structure to a flat list of attributes by storing the hierarchical information as complete path name in the new names of the attributes that are stored in the list.
static java.util.Collection flattenStructure(AttributeCollection attribs, boolean includeCollections, java.lang.String pathSeparator)
          Converts a hierarchical attribute collection structure to a flat list of attributes by storing the hierarchical information as complete path name in the new names of the attributes that are stored in the list.
static java.util.List getAllAttributesOfType(AttributeCollection attribs, java.lang.Class type)
          Returns a list of all attributes that are instances of the given class or contain a value that is an instance of the given class in the given attribute set and in subsets of it.
static java.util.List getAllAttributesWithName(AttributeCollection attribs, java.lang.String name)
          Returns a list of all attributes with the given name in the given attribute set and in subsets of it.
static Attribute getAttributeWithNestedValue(AttributeCollection coll, java.lang.String attributeName, java.lang.String nestedName, java.lang.Object nestedValue)
          Looks for an Attribute with the given attribute name that contains an AttributeCollection containing an Attribute with the given name and value.
static Attribute getFirstAttributeInList(AttributeCollection list, java.lang.String name)
          Returns the first attribute with the given name that was found in the list, or null if there is no such attribute.
static Attribute getFirstAttributeInList(AttributeCollection list, java.lang.String name, boolean recursive)
          Returns the first attribute with the given name that was found in the list, or null if there is no such attribute.
static java.lang.Object getFirstValueInList(AttributeCollection list, java.lang.String name)
          Returns the value of the first attribute with the given name that was found in the list, or null if there is no such attribute.
static java.lang.Object getFirstValueInList(AttributeCollection list, java.lang.String name, boolean recursive)
          Returns the value of the first attribute with the given name that was found in the list, or null if there is no such attribute.
static AttributeCollection getMutableCopy(AttributeCollection coll)
          Creates a mutable copy of an AttributeCollection by creating new mutable attributes containing the original name, value and constraint.
static java.lang.String getPathOfInstance(AttributeCollection collection, Attribute attrib)
          Returns the full qualified path of the given attribute in the given collection.
static AttributeSet list2set(AttributeList list)
          Returns an AttributeSet that contains copies of all Attributes in the given AttributeList.
static boolean mergeAttributesImmutable(AttributeSet current, AttributeSet updated)
          Updates the attribute values in the given AttributeSet current with the values in updated.
static boolean removeByPath(AttributeSet parent, java.lang.String path)
          Utility method to remove an attribute in an attribute tree.
static java.lang.String[] splitPathString(java.lang.String path)
          Returns a string array representing the path components of the given path string
static boolean updateAttributeCollection(AttributeCollection current, AttributeCollection updated, boolean addMissing)
          Updates the attribute values in the given AttributeSet current with the values in updated.
static boolean updateAttributes(AttributeSet current, AttributeSet updated, boolean addMissing)
          Updates the attribute values in the given AttributeSet current with the values in updated.
static boolean updateAttributes(AttributeSet current, AttributeSet updated, boolean addMissing, boolean updateMutability)
          Updates the attribute values in the given AttributeSet current with the values in updated.
static boolean updateAttributes(AttributeSet current, AttributeSet updated, boolean addMissing, boolean updateMutability, boolean updateConstraint, boolean ignoreConstraintViolations)
          Updates the attribute values in the given AttributeSet current with the values in updated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INDEX_DIFFERENCES

public static final int INDEX_DIFFERENCES
INDEX_DIFFERENCES: Array index for compareAttributeSets(AttributeSet, AttributeSet)

See Also:
Constant Field Values

INDEX_ADDITIONAL_IN_FIRST_SET

public static final int INDEX_ADDITIONAL_IN_FIRST_SET
INDEX_ADDITIONAL_IN_FIRST_SET: Array index for compareAttributeSets(AttributeSet, AttributeSet)

See Also:
Constant Field Values

INDEX_ADDITIONAL_IN_SECOND_SET

public static final int INDEX_ADDITIONAL_IN_SECOND_SET
INDEX_ADDITIONAL_IN_SECOND_SET: Array index for compareAttributeSets(AttributeSet, AttributeSet)

See Also:
Constant Field Values

INDEX_DIFFERENCES_VALUES_IN_SECOND_SET

public static final int INDEX_DIFFERENCES_VALUES_IN_SECOND_SET
INDEX_DIFFERENCES_VALUES_IN_SECOND_SET: Array index for compareAttributeSets(AttributeSet, AttributeSet)

See Also:
Constant Field Values
Method Detail

findByPath

public static final Attribute findByPath(AttributeSet parent,
                                         java.lang.String path)
Utility method to find an attribute in an attribute tree.

Parameters:
parent - The parent set to start search
path - The path to the attribute to look for
Returns:
The found attribute or null

removeByPath

public static final boolean removeByPath(AttributeSet parent,
                                         java.lang.String path)
Utility method to remove an attribute in an attribute tree.

Parameters:
parent - The parent set to start search
path - The path to the attribute to look for
Returns:
True, if the attribute has been removed

mergeAttributesImmutable

public static boolean mergeAttributesImmutable(AttributeSet current,
                                               AttributeSet updated)
                                        throws IllegalValueException,
                                               IllegalAttributeException,
                                               ConstraintViolationException,
                                               java.lang.CloneNotSupportedException
Updates the attribute values in the given AttributeSet current with the values in updated. Both sets must have the same hierarchical structure, but in the AttributeSet updated some (or all) attributes can be omitted. This method will recurse into nested AttributeSets.

Parameters:
current - The current AttributeSet
updated - The new attribute values to store in current
Returns:
true, if the given AttributeSet current has been changed
Throws:
IllegalValueException - Forwarded from Attribute.setValue(Object)
ConstraintViolationException - Forwarded from Attribute.setValue(Object)
java.lang.CloneNotSupportedException - Forwarded from Attribute.clone()
IllegalAttributeException - Forwarded from AttributeSet.add(Attribute)

updateAttributes

public static boolean updateAttributes(AttributeSet current,
                                       AttributeSet updated,
                                       boolean addMissing)
                                throws IllegalValueException,
                                       IllegalAttributeException,
                                       ConstraintViolationException,
                                       java.lang.CloneNotSupportedException
Updates the attribute values in the given AttributeSet current with the values in updated. Both sets must have the same hierarchical structure, but in the AttributeSet updated some (or all) attributes can be omitted. This method will recurse into nested AttributeSets.

Parameters:
current - The current AttributeSet
updated - The new attribute values to store in current
addMissing - true, to add attributes from updated when they are missing in current
Returns:
true, if the given AttributeSet current has been changed
Throws:
IllegalValueException - Forwarded from Attribute.setValue(Object)
ConstraintViolationException - Forwarded from Attribute.setValue(Object)
java.lang.CloneNotSupportedException - Forwarded from Attribute.clone()
IllegalAttributeException - Forwarded from AttributeSet.add(Attribute)

updateAttributes

public static boolean updateAttributes(AttributeSet current,
                                       AttributeSet updated,
                                       boolean addMissing,
                                       boolean updateMutability)
                                throws IllegalValueException,
                                       IllegalAttributeException,
                                       ConstraintViolationException,
                                       java.lang.CloneNotSupportedException
Updates the attribute values in the given AttributeSet current with the values in updated. Both sets must have the same hierarchical structure, but in the AttributeSet updated some (or all) attributes can be omitted. This method will recurse into nested AttributeSets.

Parameters:
current - The current AttributeSet
updated - The new attribute values to store in current
addMissing - true, to add attributes from updated when they are missing in current
updateMutability - if true, the original mutable state is ignored and the value and mutability is updated
Returns:
true, if the given AttributeSet current has been changed
Throws:
IllegalValueException - Forwarded from Attribute.setValue(Object)
ConstraintViolationException - Forwarded from Attribute.setValue(Object)
java.lang.CloneNotSupportedException - Forwarded from Attribute.clone()
IllegalAttributeException - Forwarded from AttributeSet.add(Attribute)

updateAttributes

public static boolean updateAttributes(AttributeSet current,
                                       AttributeSet updated,
                                       boolean addMissing,
                                       boolean updateMutability,
                                       boolean updateConstraint,
                                       boolean ignoreConstraintViolations)
                                throws IllegalValueException,
                                       IllegalAttributeException,
                                       ConstraintViolationException,
                                       java.lang.CloneNotSupportedException
Updates the attribute values in the given AttributeSet current with the values in updated. Both sets must have the same hierarchical structure, but in the AttributeSet updated some (or all) attributes can be omitted. This method will recurse into nested AttributeSets.

Parameters:
current - The current AttributeSet
updated - The new attribute values to store in current
addMissing - true, to add attributes from updated when they are missing in current
updateMutability - if true, the original mutable state is ignored and the value and mutability is updated
updateConstraint - if true, the original contraint is ignored and the constraint is updated
ignoreConstraintViolations - set this to true if the constraint in the current AttributeSet might be incompatible with the value in the updated set and you simply want to discard invalid values
Returns:
true, if the given AttributeSet current has been changed
Throws:
IllegalValueException - Forwarded from Attribute.setValue(Object)
ConstraintViolationException - Forwarded from Attribute.setValue(Object)
java.lang.CloneNotSupportedException - Forwarded from Attribute.clone()
IllegalAttributeException - Forwarded from AttributeSet.add(Attribute)

updateAttributeCollection

public static boolean updateAttributeCollection(AttributeCollection current,
                                                AttributeCollection updated,
                                                boolean addMissing)
                                         throws IllegalValueException,
                                                IllegalAttributeException,
                                                ConstraintViolationException,
                                                java.lang.CloneNotSupportedException
Updates the attribute values in the given AttributeSet current with the values in updated. Both sets must have the same hierarchical structure, but in the AttributeSet updated some (or all) attributes can be omitted. This method will recurse into nested AttributeSets. !NOTE!: This method will NOT work if there is more than one attribute with the same name in the attribute collection, as the result is undetermined!

Parameters:
current - The current AttributeCollection
updated - The new attribute values to store in current
addMissing - true, to add attributes from updated when they are missing in current
Returns:
true, if the given AttributeSet current has been changed
Throws:
IllegalValueException - Forwarded from Attribute.setValue(Object)
ConstraintViolationException - Forwarded from Attribute.setValue(Object)
java.lang.CloneNotSupportedException - Forwarded from Attribute.clone()
IllegalAttributeException - Forwarded from AttributeSet.add(Attribute)

getAttributeWithNestedValue

public static Attribute getAttributeWithNestedValue(AttributeCollection coll,
                                                    java.lang.String attributeName,
                                                    java.lang.String nestedName,
                                                    java.lang.Object nestedValue)
Looks for an Attribute with the given attribute name that contains an AttributeCollection containing an Attribute with the given name and value.

Parameters:
coll - The collection to look through
attributeName - The name of the attribute that contains the nested attribute
nestedName - The name of the nested attribute
nestedValue - The value of the nested attribute
Returns:
The requested Attribute

createAttributeSetPath

public static AttributeSet createAttributeSetPath(java.lang.String path)
Creates nested AttributeSets to represent the given path. The leaf (last path element) is an Attribute containing an empty AttributeSet.

Parameters:
path - The path to create
Returns:
The root set of the hierarchy

createAttributeSetPath

public static AttributeSet createAttributeSetPath(java.lang.String path,
                                                  Attribute leaf)
Creates nested AttributeSets to represent the given path. The Attribute passed in the leaf argument will be used as last path element (only member of the deepest AttributeSet).

Parameters:
path - The path to create
leaf - The attribute to put in the deepest AttributeSet, this attribute can be retrieved using the given path plus the name of the attribute itself
Returns:
The root set of the hierarchy

getFirstAttributeInList

public static final Attribute getFirstAttributeInList(AttributeCollection list,
                                                      java.lang.String name)
Returns the first attribute with the given name that was found in the list, or null if there is no such attribute. The method will not search through nested AttributeCollections

Parameters:
list - The list to check
name - The name of the attribute to look for
Returns:
The first matching attribute or null if there is none

getFirstAttributeInList

public static final Attribute getFirstAttributeInList(AttributeCollection list,
                                                      java.lang.String name,
                                                      boolean recursive)
Returns the first attribute with the given name that was found in the list, or null if there is no such attribute.

Parameters:
list - The list to check
name - The name of the attribute to look for
recursive - True, to search through nested AttributeCollections
Returns:
The first matching attribute or null if there is none

getFirstValueInList

public static final java.lang.Object getFirstValueInList(AttributeCollection list,
                                                         java.lang.String name)
Returns the value of the first attribute with the given name that was found in the list, or null if there is no such attribute. The method will not search through nested AttributeCollections

Parameters:
list - The list to check
name - The name of the attribute to look for
Returns:
The value of the first matching attribute or null if there is none

getFirstValueInList

public static final java.lang.Object getFirstValueInList(AttributeCollection list,
                                                         java.lang.String name,
                                                         boolean recursive)
Returns the value of the first attribute with the given name that was found in the list, or null if there is no such attribute.

Parameters:
list - The list to check
name - The name of the attribute to look for
recursive - True, to search through nested AttributeCollections
Returns:
The value of the first matching attribute or null if there is none

getAllAttributesWithName

public static java.util.List getAllAttributesWithName(AttributeCollection attribs,
                                                      java.lang.String name)
Returns a list of all attributes with the given name in the given attribute set and in subsets of it.

Parameters:
attribs - The attribute collection to search through, recursing into subcollections automatically
name - The name to look for
Returns:
a list of all attributes with the given name in the given attribute set and in subsets of it.

getAllAttributesOfType

public static java.util.List getAllAttributesOfType(AttributeCollection attribs,
                                                    java.lang.Class type)
Returns a list of all attributes that are instances of the given class or contain a value that is an instance of the given class in the given attribute set and in subsets of it.

Parameters:
attribs - The attribute collection to search through, recursing into subcollections automatically
type - The type to look for
Returns:
a list of all attributes with the given name in the given attribute set and in subsets of it.

getPathOfInstance

public static final java.lang.String getPathOfInstance(AttributeCollection collection,
                                                       Attribute attrib)
Returns the full qualified path of the given attribute in the given collection. The given set has to contain the very same instance of the attribute, as an equals would match more than one attribute and is useless here.

Parameters:
collection - The collection that has to contain the attribute in its substructure
attrib - The attribute to look for
Returns:
The full qualified string of the attribute

splitPathString

public static final java.lang.String[] splitPathString(java.lang.String path)
Returns a string array representing the path components of the given path string

Parameters:
path - The complete path as string divided by the AttributeSet.SEPARATOR
Returns:
A string array representing the path components of the given path string

compareAttributeSets

public static final AttributeSet[] compareAttributeSets(AttributeSet set1,
                                                        AttributeSet set2)
Compares two AttributeSets and returns three new AttributeSets describing the differences.

Parameters:
set1 - The first AttributeSet
set2 - The first AttributeSet
Returns:
An array of size three, use the constants to retrieve these information: INDEX_DIFFERENCES: Contains all attributes that are part of both attribute sets, but differ in value INDEX_ADDITIONAL_IN_FIRST_SET: Contains all attributes that are only part of the first attribute set INDEX_ADDITIONAL_IN_SECOND_SET: Contains all attributes that are only part of the second attribute set

flattenStructure

public static java.util.Collection flattenStructure(AttributeCollection attribs)
                                             throws IllegalNameException,
                                                    IllegalValueException,
                                                    ConstraintViolationException
Converts a hierarchical attribute collection structure to a flat list of attributes by storing the hierarchical information as complete path name in the new names of the attributes that are stored in the list. The result list will not contain direct references to the original attributes, but will contain the original values, mutable states and constraints. Use flattenStructure(AttributeCollection, boolean) and pass true as second parameter, if you want the list to contain entries for values of type AttributeCollection.

Parameters:
attribs - the attribute collection to flatten
Returns:
a list containing all attributes from the original collection including nested attributes. the names of the attributes are the complete paths of the attribues.
Throws:
ConstraintViolationException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)
IllegalValueException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)
IllegalNameException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)

flattenStructure

public static java.util.Collection flattenStructure(AttributeCollection attribs,
                                                    boolean includeCollections)
                                             throws IllegalNameException,
                                                    IllegalValueException,
                                                    ConstraintViolationException
Converts a hierarchical attribute collection structure to a flat list of attributes by storing the hierarchical information as complete path name in the new names of the attributes that are stored in the list. The result list will not contain direct references to the original attributes, but will contain the original values, mutable states and constraints.

Parameters:
attribs - the attribute collection to flatten
includeCollections - true, to include the collections in the list
Returns:
a list containing all attributes from the original collection including nested attributes. the names of the attributes are the complete paths of the attribues.
Throws:
ConstraintViolationException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)
IllegalValueException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)
IllegalNameException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)

flattenStructure

public static java.util.Collection flattenStructure(AttributeCollection attribs,
                                                    boolean includeCollections,
                                                    java.lang.String pathSeparator)
                                             throws IllegalNameException,
                                                    IllegalValueException,
                                                    ConstraintViolationException
Converts a hierarchical attribute collection structure to a flat list of attributes by storing the hierarchical information as complete path name in the new names of the attributes that are stored in the list. The result list will not contain direct references to the original attributes, but will contain the original values, mutable states and constraints.

Parameters:
attribs - the attribute collection to flatten
includeCollections - true, to include the collections in the list
pathSeparator - the separator string for the path names
Returns:
a list containing all attributes from the original collection including nested attributes. the names of the attributes are the complete paths of the attribues.
Throws:
ConstraintViolationException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)
IllegalValueException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)
IllegalNameException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)

getMutableCopy

public static AttributeCollection getMutableCopy(AttributeCollection coll)
                                          throws IllegalNameException,
                                                 IllegalValueException,
                                                 IllegalAttributeException,
                                                 ConstraintViolationException
Creates a mutable copy of an AttributeCollection by creating new mutable attributes containing the original name, value and constraint.

Parameters:
coll - The collection to copy
Returns:
The copy of a collection with mutable attributes
Throws:
IllegalNameException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)
IllegalValueException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)
IllegalAttributeException - forwards exception from AttributeCollection.add(Attribute)
ConstraintViolationException - forwards exception from AttributeFactory.newAttribute(String, Object, Constraint)

list2set

public static AttributeSet list2set(AttributeList list)
                             throws IllegalAttributeException,
                                    ConstraintViolationException,
                                    java.lang.CloneNotSupportedException
Returns an AttributeSet that contains copies of all Attributes in the given AttributeList. This only works for lists that do not contain more than one attribute with the same name.

Parameters:
list - The list to get the attributes from
Returns:
The created set
Throws:
IllegalAttributeException - forwards exception from AttributeCollection.add(Attribute)
ConstraintViolationException - forwards exception from AttributeCollection.add(Attribute)
java.lang.CloneNotSupportedException - forwards exception from Attribute.clone()


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.