org.palo.api.impl
Class HierarchyImpl

java.lang.Object
  extended by org.palo.api.impl.HierarchyImpl
All Implemented Interfaces:
Hierarchy, NamedEntity, PaloObject, Writable

public class HierarchyImpl
extends java.lang.Object
implements Hierarchy

TODO DOCUMENT ME

Version:
$Id: HierarchyImpl.html,v 1.6 2009/07/09 11:01:47 ArndHouben Exp $

Field Summary
 
Fields inherited from interface org.palo.api.PaloObject
TYPE_ATTRIBUTE, TYPE_NORMAL, TYPE_SYSTEM, TYPE_USER_INFO
 
Method Summary
 Attribute addAttribute(java.lang.String name)
          Creates a new Attribute and adds it to the hierarchy.
 Element addElement(java.lang.String name, int type)
          Adds an Element to this Hierarchy.
 void addElements(java.lang.String[] names, int[] types)
          Batch adds many elements.
 void addElements(java.lang.String[] names, int[] types, Element[][] children, double[][] weights)
          Available for Palo Server version 3 and above.
 void addElements(java.lang.String[] names, int type, Element[][] children, double[][] weights)
           
 Subset addSubset(java.lang.String name)
          Adds a new Subset with the given name to the hierarchy.
 boolean canBeModified()
          Returns true if this object can be modified (renamed, deleted, ...), false otherwise.
 boolean canCreateChildren()
          Returns true if this object can create child objects, false otherwise.
 boolean equals(java.lang.Object other)
           
 ElementNode[] getAllElementNodes()
          Returns an array of all element nodes of the consolidation hierarchy of this hierarchy.
 Attribute getAttribute(java.lang.String attrId)
          Returns the Attribute which corresponds to the given id or null if no Attribute with this id exists
 Attribute getAttributeByName(java.lang.String attrName)
          Returns the Attribute which corresponds to the given name or null if no Attribute with this name exists
 Cube getAttributeCube()
          Returns the attribute Cube corresponding to this hierarchy or null if the attribute cube couldn't be loaded or does not exist.
 Hierarchy getAttributeHierarchy()
          Returns the corresponding attribute Hierarchy or null if the attribute hierarchy couldn't be loaded or does not exist.
 Attribute[] getAttributes()
          Returns all Attributes this hierarchy has.
 java.lang.Object[] getAttributeValues(Attribute[] attributes, Element[] elements)
          Convenient method to receive the values from several Attributes in one go, i.e. the i.th object in the returned array is the i.th value of the i.th attribute for the i.th element.
 Dimension getDimension()
          Returns the parent dimension of this hierarchy.
 Element getElementAt(int index)
          Returns the Element stored at the given index.
 Element getElementById(java.lang.String id)
          Returns the Element stored under the given id or null if no such Element exists.
 Element getElementByName(java.lang.String name)
          Returns the Element stored under the given name or null if no such Element exists.
 int getElementCount()
          Returns the number of Elements of this instance.
 java.lang.String[] getElementNames()
          Returns the names of the elements of this Hierarchy.
 Element[] getElements()
          Returns an array of Element instances available for this instance.
 Element[] getElementsInOrder()
          Returns all elements of the hierarchy in an order that is determined by the consolidation hierarchy.
 ElementNode[] getElementsTree()
          Returns the root-nodes of the element-tree.
 java.lang.String getId()
          Returns the unique identifier of this palo object.
 int getMaxDepth()
          Returns the maximum depth of this hierarchy.
 int getMaxLevel()
          Returns the maximum level of this hierarchy.
 java.lang.String getName()
          Returns the name of the entity.
 Element[] getRootElements()
          Returns all root-elements (those without parents in the consolidation-hierarchy).
 Subset getSubset(java.lang.String id)
          Returns the subset which is registered with the given id or null if no subset with this id could be found
 SubsetHandler getSubsetHandler()
          Returns the SubsetHandler for managing the new subsets.
 Subset[] getSubsets()
          Returns all subsets currently registered with this hierarchy
 int getType()
          TODO please comment :)
 int hashCode()
           
 boolean isAttributeHierarchy()
          Checks if this Hierarchy is an attribute hierarchy, i.e.
 boolean isNormal()
          Returns if this hierarchy is a normal hierarchy (as opposed to being a system hierarchy).
 boolean isSubsetHierarchy()
          Checks if this Hierarchy is a subset hierarchy, i.e.
 Consolidation newConsolidation(Element element, Element parent, double weight)
          Creates a Consolidation for later use in this hierarchy.
 void reload(boolean doEvents)
          Reloads the internal hierarchy structure from database.
 void removeAllAttributes()
          Removes all attributes from the hierarchy
 void removeAttribute(Attribute attribute)
          Removes the given Attribute from the hierarchy
 void removeElement(Element element)
          Removes the given Element from this Hierarchy
 void removeElements(Element[] elements)
          Removes the given Elements from this Hierarchy
 void removeSubset(Subset subset)
          Removes the given subset from the dimension
 void rename(java.lang.String name)
          Renames this hierarchy.
 void renameElement(Element element, java.lang.String newName)
          Renames given Element.
 void setAttributeValues(Attribute[] attributes, Element[] elements, java.lang.Object[] values)
          Convenient method to set the values for several Attributes at once, i.e. the i.th value is assigned to the i.th attribute for the i.th element.
 java.lang.String toString()
           
 void visitElementTree(ElementNodeVisitor visitor)
          Visits the element-tree of this hierarchy.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

getId

public java.lang.String getId()
Description copied from interface: PaloObject
Returns the unique identifier of this palo object.

Important note: for a correct usage please note that the returned id is only unique within the parent scope of this palo object. Furthermore in case of deletion the id is reused, i.e. if a palo object is removed its id could be given to a newly created palo object afterwards!!

Specified by:
getId in interface PaloObject
Returns:
id of the palo object.

getName

public java.lang.String getName()
Description copied from interface: NamedEntity
Returns the name of the entity.

Specified by:
getName in interface NamedEntity
Returns:
the name of the entity.

isNormal

public boolean isNormal()
Description copied from interface: Hierarchy
Returns if this hierarchy is a normal hierarchy (as opposed to being a system hierarchy). A hierarchy is a system hierarchy, when its dimension is a system dimension.

Specified by:
isNormal in interface Hierarchy
Returns:
true if the hierarchy is a non-system hierarchy, false otherwise.

rename

public void rename(java.lang.String name)
Description copied from interface: Hierarchy
Renames this hierarchy.

Specified by:
rename in interface Hierarchy
Parameters:
name - the the name for the hierarchy.

canBeModified

public boolean canBeModified()
Description copied from interface: Writable
Returns true if this object can be modified (renamed, deleted, ...), false otherwise.

Specified by:
canBeModified in interface Writable
Returns:
true if this object can be modified, false otherwise.

canCreateChildren

public boolean canCreateChildren()
Description copied from interface: Writable
Returns true if this object can create child objects, false otherwise.

Specified by:
canCreateChildren in interface Writable
Returns:
true if this object can create child objects, false otherwise.

getType

public int getType()
Description copied from interface: PaloObject
TODO please comment :)

Specified by:
getType in interface PaloObject
Returns:
the type of this palo object

getDimension

public Dimension getDimension()
Description copied from interface: Hierarchy
Returns the parent dimension of this hierarchy.

Specified by:
getDimension in interface Hierarchy
Returns:
the parent dimension of this hierarchy.

getElementCount

public int getElementCount()
Description copied from interface: Hierarchy
Returns the number of Elements of this instance. Note that a single hierarchy with consolidated elements might consolidate a particular element more than once.

Specified by:
getElementCount in interface Hierarchy
Returns:
the number of Elements of this instance.

getElements

public final Element[] getElements()
Description copied from interface: Hierarchy
Returns an array of Element instances available for this instance.

The returned array is a copy of the internal data structure. Changing the returned array does not change this instance.

Specified by:
getElements in interface Hierarchy
Returns:
an array of Element instances available for this Hierarchy.

getElementAt

public final Element getElementAt(int index)
Description copied from interface: Hierarchy
Returns the Element stored at the given index. If the index does not correspond to a legal position in the internally managed array of elements of this instance, then null is returned.

Specified by:
getElementAt in interface Hierarchy
Parameters:
index - the index
Returns:
the Element stored at the given index or null.

getAllElementNodes

public final ElementNode[] getAllElementNodes()
Description copied from interface: Hierarchy
Returns an array of all element nodes of the consolidation hierarchy of this hierarchy.

Specified by:
getAllElementNodes in interface Hierarchy
Returns:
an array of all element nodes of this hierarchy.

addAttribute

public final Attribute addAttribute(java.lang.String name)
Description copied from interface: Hierarchy
Creates a new Attribute and adds it to the hierarchy.

Note: adding an attribute to a hierarchy which is itself of type attribute hierarchy is prohibited and will result in a PaloAPIException.

Specified by:
addAttribute in interface Hierarchy
Parameters:
name - the name of the new attribute
Returns:
the newly created Attribute

removeAllAttributes

public final void removeAllAttributes()
Description copied from interface: Hierarchy
Removes all attributes from the hierarchy

Specified by:
removeAllAttributes in interface Hierarchy

removeAttribute

public final void removeAttribute(Attribute attribute)
Description copied from interface: Hierarchy
Removes the given Attribute from the hierarchy

Specified by:
removeAttribute in interface Hierarchy
Parameters:
attribute - the attribute instance to remove

getAttributes

public final Attribute[] getAttributes()
Description copied from interface: Hierarchy
Returns all Attributes this hierarchy has.

Specified by:
getAttributes in interface Hierarchy
Returns:
the Attributes of this hierarchy

getAttribute

public final Attribute getAttribute(java.lang.String attrId)
Description copied from interface: Hierarchy
Returns the Attribute which corresponds to the given id or null if no Attribute with this id exists

Specified by:
getAttribute in interface Hierarchy
Parameters:
attrId - identifier of the Attribute to get
Returns:
the corresponding Attribute or null

getAttributeByName

public final Attribute getAttributeByName(java.lang.String attrName)
Description copied from interface: Hierarchy
Returns the Attribute which corresponds to the given name or null if no Attribute with this name exists

Specified by:
getAttributeByName in interface Hierarchy
Parameters:
attrName - the name of the Attribute to get
Returns:
the corresponding Attribute or null

getAttributeValues

public final java.lang.Object[] getAttributeValues(Attribute[] attributes,
                                                   Element[] elements)
Description copied from interface: Hierarchy
Convenient method to receive the values from several Attributes in one go, i.e. the i.th object in the returned array is the i.th value of the i.th attribute for the i.th element.
Note: if the attributes and elements arrays do not have same length an PaloAPIException is thrown.

Specified by:
getAttributeValues in interface Hierarchy
Parameters:
attributes - the attributes to get the values from
elements - the effected elements
Returns:
the attribute values

getAttributeCube

public final Cube getAttributeCube()
Description copied from interface: Hierarchy
Returns the attribute Cube corresponding to this hierarchy or null if the attribute cube couldn't be loaded or does not exist.

Note: this is a convenient method to provide raw access to the internal attribute handling. Its usage is not recommended!!

Specified by:
getAttributeCube in interface Hierarchy
Returns:
the attribute cube

setAttributeValues

public final void setAttributeValues(Attribute[] attributes,
                                     Element[] elements,
                                     java.lang.Object[] values)
Description copied from interface: Hierarchy
Convenient method to set the values for several Attributes at once, i.e. the i.th value is assigned to the i.th attribute for the i.th element.
Note: if the attributes, elements and values arrays do not have same length an PaloAPIException is thrown.

Specified by:
setAttributeValues in interface Hierarchy
Parameters:
attributes - the attributes to set the values for
elements - the effected elements
values - the new values

getAttributeHierarchy

public final Hierarchy getAttributeHierarchy()
Description copied from interface: Hierarchy
Returns the corresponding attribute Hierarchy or null if the attribute hierarchy couldn't be loaded or does not exist.

Note: this is a convenient method to provide raw access to the internal attribute handling. Its usage is not recommended!!

Specified by:
getAttributeHierarchy in interface Hierarchy
Returns:
the attribute hierarchy

addElement

public final Element addElement(java.lang.String name,
                                int type)
Description copied from interface: Hierarchy
Adds an Element to this Hierarchy.

Specified by:
addElement in interface Hierarchy
Parameters:
name - the name of the element to add.
type - the type of the element to add as defined by the constants in the Element class.

addElements

public final void addElements(java.lang.String[] names,
                              int[] types)
Description copied from interface: Hierarchy
Batch adds many elements.

Specified by:
addElements in interface Hierarchy
Parameters:
names - the names of the elements to add.
types - the types of the elements to add.

addElements

public final void addElements(java.lang.String[] names,
                              int type,
                              Element[][] children,
                              double[][] weights)
Specified by:
addElements in interface Hierarchy

addElements

public final void addElements(java.lang.String[] names,
                              int[] types,
                              Element[][] children,
                              double[][] weights)
Description copied from interface: Hierarchy
Available for Palo Server version 3 and above.

Specified by:
addElements in interface Hierarchy

getElementsTree

public final ElementNode[] getElementsTree()
Description copied from interface: Hierarchy
Returns the root-nodes of the element-tree.

Specified by:
getElementsTree in interface Hierarchy
Returns:
the root-nodes of the element-tree.

getRootElements

public final Element[] getRootElements()
Description copied from interface: Hierarchy
Returns all root-elements (those without parents in the consolidation-hierarchy).

Specified by:
getRootElements in interface Hierarchy
Returns:
all root elements of the hierarchy.

visitElementTree

public final void visitElementTree(ElementNodeVisitor visitor)
Description copied from interface: Hierarchy
Visits the element-tree of this hierarchy.

Specified by:
visitElementTree in interface Hierarchy
Parameters:
visitor - the visitor-callback to invoke during traversal.

removeElements

public final void removeElements(Element[] elements)
Description copied from interface: Hierarchy
Removes the given Elements from this Hierarchy

Specified by:
removeElements in interface Hierarchy
Parameters:
elements - Elements to remove.

getElementById

public final Element getElementById(java.lang.String id)
Description copied from interface: Hierarchy
Returns the Element stored under the given id or null if no such Element exists.

Specified by:
getElementById in interface Hierarchy
Parameters:
id - the element-id to look-up.
Returns:
the Element stored under the given id or null if no such Element exists.

getElementByName

public final Element getElementByName(java.lang.String name)
Description copied from interface: Hierarchy
Returns the Element stored under the given name or null if no such Element exists.

Specified by:
getElementByName in interface Hierarchy
Parameters:
name - the element-name to look-up.
Returns:
the Element stored under the given name or null if no such Element exists.

getElementNames

public final java.lang.String[] getElementNames()
Description copied from interface: Hierarchy
Returns the names of the elements of this Hierarchy.

The returned array is a copy of the internal data structure. Changing the returned array does not change this instance.

Specified by:
getElementNames in interface Hierarchy
Returns:
the names of the Elements instances available for this Dimension>.

renameElement

public final void renameElement(Element element,
                                java.lang.String newName)
Description copied from interface: Hierarchy
Renames given Element.

Specified by:
renameElement in interface Hierarchy
Parameters:
element - the Element to rename.
newName - the new name for this Element.

getElementsInOrder

public final Element[] getElementsInOrder()
Description copied from interface: Hierarchy
Returns all elements of the hierarchy in an order that is determined by the consolidation hierarchy. Since elements can be consolidated multiple times, this order is not always the same as a pre-order traversal of the directed acyclic graph of consolidations, but similar.

Specified by:
getElementsInOrder in interface Hierarchy
Returns:
the elements of the hierarchy in order.

newConsolidation

public final Consolidation newConsolidation(Element element,
                                            Element parent,
                                            double weight)
Description copied from interface: Hierarchy
Creates a Consolidation for later use in this hierarchy.

Specified by:
newConsolidation in interface Hierarchy
Parameters:
element - the Element to consolidate.
parent - the parent-Element of the consolidation.
weight - the consolidation weight.
Returns:
the created Consolidation object.

removeElement

public final void removeElement(Element element)
Description copied from interface: Hierarchy
Removes the given Element from this Hierarchy

Specified by:
removeElement in interface Hierarchy
Parameters:
element - the Element to remove.

getMaxDepth

public final int getMaxDepth()
Description copied from interface: Hierarchy
Returns the maximum depth of this hierarchy. Please refer to Element.getDepth() for an explanation of how the depth is determined

Specified by:
getMaxDepth in interface Hierarchy
Returns:
maximum depth of this hierarchy

getMaxLevel

public final int getMaxLevel()
Description copied from interface: Hierarchy
Returns the maximum level of this hierarchy. Please refer to Element.getLevel() for an explanation of how the level is determined

Specified by:
getMaxLevel in interface Hierarchy
Returns:
maximum level of this hierarchy

isAttributeHierarchy

public final boolean isAttributeHierarchy()
Description copied from interface: Hierarchy
Checks if this Hierarchy is an attribute hierarchy, i.e. its elements represent Attributes.

Specified by:
isAttributeHierarchy in interface Hierarchy
Returns:
true if this hierarchy is an attribute hierarchy, false otherwise

equals

public final boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public final int hashCode()
Overrides:
hashCode in class java.lang.Object

reload

public final void reload(boolean doEvents)
Description copied from interface: Hierarchy
Reloads the internal hierarchy structure from database.

Specified by:
reload in interface Hierarchy
Parameters:
doEvents - specify true to get event notification on hierarchy changes or false otherwise

addSubset

public Subset addSubset(java.lang.String name)
Description copied from interface: Hierarchy
Adds a new Subset with the given name to the hierarchy.

Specified by:
addSubset in interface Hierarchy
Parameters:
name - the name of the subset
Returns:
the new subset

getSubset

public Subset getSubset(java.lang.String id)
Description copied from interface: Hierarchy
Returns the subset which is registered with the given id or null if no subset with this id could be found

Specified by:
getSubset in interface Hierarchy
Parameters:
id - the subset id
Returns:
the corresponding subset instance

getSubsetHandler

public SubsetHandler getSubsetHandler()
Description copied from interface: Hierarchy
Returns the SubsetHandler for managing the new subsets. Please use Database.supportsNewSubsets() to check if new subsets are supported.

Specified by:
getSubsetHandler in interface Hierarchy
Returns:
the SubsetHandler for managing new subsets

getSubsets

public Subset[] getSubsets()
Description copied from interface: Hierarchy
Returns all subsets currently registered with this hierarchy

Specified by:
getSubsets in interface Hierarchy
Returns:
the registered subsets

removeSubset

public void removeSubset(Subset subset)
Description copied from interface: Hierarchy
Removes the given subset from the dimension

Specified by:
removeSubset in interface Hierarchy
Parameters:
subset - the subset to remove

isSubsetHierarchy

public final boolean isSubsetHierarchy()
Description copied from interface: Hierarchy
Checks if this Hierarchy is a subset hierarchy, i.e. its elements represent Subsets.

Specified by:
isSubsetHierarchy in interface Hierarchy
Returns:
true if hierarchy is a subset hierarchy, false otherwise

toString

public final java.lang.String toString()
Overrides:
toString in class java.lang.Object