com.sdm.quasar.client.core.common.hierarchy
Class DefaultHierarchyManager

java.lang.Object
  extended bycom.sdm.quasar.client.core.common.hierarchy.DefaultHierarchyManager
All Implemented Interfaces:
Disposable, HierarchyManager, HierarchyProvider

public class DefaultHierarchyManager
extends java.lang.Object
implements HierarchyManager, Disposable

Default implementation of the HierarchyManager.

Version:
1.0
Author:
Bernd Olleck, sd&m AG

Constructor Summary
DefaultHierarchyManager()
          Constructor.
DefaultHierarchyManager(ID rootId)
          Constructor.
DefaultHierarchyManager(ID[] rootIds)
          Constructor.
 
Method Summary
 void addChild(ID parentId, ID childId)
          This implementation uses constant time with respect to the number of nodes and linear time with respect to the number of children of the parent node.
 void addHierarchyProviderListener(HierarchyProviderListener listener)
          Registers a listener that observes changes in the hierarchy.
 void addRoot(ID rootId)
          This implementation uses linear time with respect to the number of root nodes.
 void dispose()
          Disposes the component.
protected  void fireChildAdded(ID parentId, ID childId)
          Notifies all registered listeners that a child has been added.
protected  void fireChildRemoved(ID parentId, ID childId)
          Notifies all registered listeners that a child has been removed.
protected  void fireRootAdded(ID rootId)
          Notifies all registered listeners that a root has been added.
protected  void fireRootRemoved(ID rootId)
          Notifies all registered listeners that a root has been removed.
 int getChildCount(ID parentId, boolean deep, boolean leafesOnly)
          Returns the number of childs for the given parent id.
 ID[] getChildren(ID parentId)
          Returns the children of a node.
 ID getParentForChild(ID id)
          This implementation uses constant time with respect to the number of nodes.
 ID[] getRoots()
          Returns the root nodes.
 boolean hasID(ID id)
          This implementation uses constant time with respect to the number of nodes.
 boolean isChild(ID id1, ID id2, boolean deep)
          Checks if id2 is a child of id1.
 void removeChild(ID parentId, ID childId)
          This implementation uses constant time with respect to the number of nodes and linear time with respect to the number of children of the parent node.
 void removeHierarchyProviderListener(HierarchyProviderListener listener)
          Unregisters a listener.
 void removeRoot(ID rootId)
          This implementation uses linear time with respect to the number of root nodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultHierarchyManager

public DefaultHierarchyManager()
Constructor.


DefaultHierarchyManager

public DefaultHierarchyManager(ID rootId)
Constructor.


DefaultHierarchyManager

public DefaultHierarchyManager(ID[] rootIds)
Constructor.

Method Detail

hasID

public boolean hasID(ID id)
This implementation uses constant time with respect to the number of nodes.

Specified by:
hasID in interface HierarchyProvider
Parameters:
id - the id to be tested
Returns:
true iff the node is registered in the hierarchy
See Also:
HierarchyProvider.hasID(ID)

addRoot

public void addRoot(ID rootId)
This implementation uses linear time with respect to the number of root nodes.

Specified by:
addRoot in interface HierarchyManager
Parameters:
rootId - the id of the new root node
See Also:
HierarchyManager.addRoot(ID)

removeRoot

public void removeRoot(ID rootId)
This implementation uses linear time with respect to the number of root nodes.

Specified by:
removeRoot in interface HierarchyManager
Parameters:
rootId - the id of the root node
See Also:
HierarchyManager.removeRoot(ID)

getRoots

public ID[] getRoots()
Description copied from interface: HierarchyProvider
Returns the root nodes. The returned array is a copy, any modifications made to the hierarchy will not affect the returned value.

Specified by:
getRoots in interface HierarchyProvider
Returns:
an array with the IDs of the root nodes.
See Also:
HierarchyProvider.getRoots(), HierarchyProvider.getRoots()

addChild

public void addChild(ID parentId,
                     ID childId)
This implementation uses constant time with respect to the number of nodes and linear time with respect to the number of children of the parent node.

Specified by:
addChild in interface HierarchyManager
Parameters:
parentId - the id of the parent node
childId - the id of the new child
See Also:
HierarchyManager.addChild(ID, ID)

getChildren

public ID[] getChildren(ID parentId)
Description copied from interface: HierarchyProvider
Returns the children of a node. The returned array is a copy, any modifications made to the hierarchy will not affect the returned set.

Specified by:
getChildren in interface HierarchyProvider
Parameters:
parentId - the id of the parent node
Returns:
an array with the IDs of the children
See Also:
HierarchyProvider.getChildren(ID), HierarchyProvider.getChildren(com.sdm.quasar.client.core.common.ID)

getParentForChild

public ID getParentForChild(ID id)
This implementation uses constant time with respect to the number of nodes.

Specified by:
getParentForChild in interface HierarchyProvider
Parameters:
id - the id of the child node
Returns:
the id of the parent node or null, if the child has no parent
See Also:
HierarchyProvider.getParentForChild(ID)

isChild

public boolean isChild(ID id1,
                       ID id2,
                       boolean deep)
Description copied from interface: HierarchyProvider
Checks if id2 is a child of id1. The check is done down the whole sub hierarchy of id1 if deep = true. Else only direct childs are considered.

Specified by:
isChild in interface HierarchyProvider
Parameters:
id1 - the potential parent
id2 - the potential child
deep - true: The check is done down the whole sub hierarchy false: only direct childs are considered
Returns:
true, if

getChildCount

public int getChildCount(ID parentId,
                         boolean deep,
                         boolean leafesOnly)
Description copied from interface: HierarchyProvider
Returns the number of childs for the given parent id.

Specified by:
getChildCount in interface HierarchyProvider
Parameters:
parentId - the ID of the parent to count childs of
deep - if true, the whole subtree will be counted, if false, only direct childs are counted
leafesOnly - if true, the returned number is restricted to leafes (childs, that have no childs themselfes)
Returns:
the number of children of the specified parent node
See Also:
HierarchyProvider.getChildCount(com.sdm.quasar.client.core.common.ID, boolean, boolean)

removeChild

public void removeChild(ID parentId,
                        ID childId)
This implementation uses constant time with respect to the number of nodes and linear time with respect to the number of children of the parent node.

Specified by:
removeChild in interface HierarchyManager
Parameters:
parentId - the id of the parent node
childId - the id of the child node to be removed
See Also:
HierarchyManager.removeChild(ID, ID)

addHierarchyProviderListener

public void addHierarchyProviderListener(HierarchyProviderListener listener)
Description copied from interface: HierarchyProvider
Registers a listener that observes changes in the hierarchy.

Specified by:
addHierarchyProviderListener in interface HierarchyProvider
Parameters:
listener - the listener to be added
See Also:
HierarchyProvider.addHierarchyProviderListener(com.sdm.quasar.client.core.common.hierarchy.HierarchyProviderListener)

removeHierarchyProviderListener

public void removeHierarchyProviderListener(HierarchyProviderListener listener)
Description copied from interface: HierarchyProvider
Unregisters a listener.

Specified by:
removeHierarchyProviderListener in interface HierarchyProvider
Parameters:
listener - the listener to be removed
See Also:
HierarchyProvider.removeHierarchyProviderListener(com.sdm.quasar.client.core.common.hierarchy.HierarchyProviderListener)

fireRootAdded

protected void fireRootAdded(ID rootId)
Notifies all registered listeners that a root has been added.

Parameters:
rootId - id of the root

fireRootRemoved

protected void fireRootRemoved(ID rootId)
Notifies all registered listeners that a root has been removed.

Parameters:
rootId - id of the root

fireChildAdded

protected void fireChildAdded(ID parentId,
                              ID childId)
Notifies all registered listeners that a child has been added.

Parameters:
parentId - the parent id
childId - the child id

fireChildRemoved

protected void fireChildRemoved(ID parentId,
                                ID childId)
Notifies all registered listeners that a child has been removed.

Parameters:
parentId - the parent id
childId - the child id

dispose

public void dispose()
             throws DisposeException
Description copied from interface: Disposable
Disposes the component.

Important:
This method is called by an administrating component and must never be called directly.

The implementation should release any resources or objects allocated and any services registered. Furthermore, this method should be developed carefully to free a maximum of resources even when the system may have become unstable. In case of one or multiple errors, you should collect them in a DisposeException, continue with the execution, and throw it at the end of the method.

Note: The implementation must not return before the component is disposed. Any threads or asynchronous calls started must be completed before this method returns.

Specified by:
dispose in interface Disposable
Throws:
DisposeException