com.raritantechnologies.utils.tree
Class TreeNode

java.lang.Object
  extended bycom.raritantechnologies.utils.tree.TreeNode
Direct Known Subclasses:
CountTree, ProfileTreeNode, SourceMapTreeNode, TaxonomyTreeNode, ThesaurusNode, TreeRoot

public class TreeNode
extends java.lang.Object

Base class for tree objects. Contains methods for managing parents, children, path rendering etc.


Developed by Raritan Technologies Inc..

Author:
Ted Sullivan

Field Summary
protected  TreeNode activeNode
           
protected  java.util.ArrayList children
           
protected  int maxCount
           
protected  java.lang.String name
           
protected  boolean needsUpdate
           
protected  java.lang.Integer nodeCount
           
protected  java.lang.String nodeID
           
protected  boolean openState
           
protected  TreeNode parent
           
 
Constructor Summary
TreeNode()
           
 
Method Summary
 void addAttribute(java.lang.String name, java.lang.String value)
           
 void addChildNode(java.lang.String childName, java.lang.String pathSeparator, boolean uniqueNames)
           
 void addChildNode(TreeNode treeNode)
           
 void addParent(TreeNode parent)
           
 void addResult(IResult res)
           
static IResult convertToResult(TreeNode treeNode)
           
static TreeNode copyNode(TreeNode node)
           
static TreeNode copyNode(TreeNode node, TreeRoot toTree, boolean copyAll)
           
 void copyNodeAttributes(TreeNode node, boolean addResults, java.util.Map attributeActionMap)
          Add the node attributes and nested results to this node.
 void copyNodeCount(TreeNode toNode)
           
static TreeNode copyNodeOnly(TreeNode node)
           
 IResult createAttributesResult()
          Create an IResult object from the node attributes.
 void deleteChildNodes()
           
 TreeNode findNode(java.lang.Object nodeID)
          Returns a TreeNode that matches the given nodeID from within the Tree that this TreeNode belongs to.
 TreeNode getActiveNode()
           
 java.util.Set getAllParentAttributes(java.lang.String attributeName)
           
 java.util.Set getAllParentAttributes(java.lang.String attributeName, boolean allAncestors)
           
 java.util.Set getAllParentAttributes(java.lang.String attributeName, boolean allAncestors, ITreeNodeComparator comparator)
           
 java.util.Set getAllSubAttributes(java.lang.String attributeName)
          returns the set of all attribute values in this nodes sub nodes.
 java.util.Set getAllSubAttributes(java.lang.String attributeName, boolean allDescendents)
           
 java.util.Set getAllSubAttributes(java.lang.String attributeName, boolean allDescendents, ITreeNodeComparator comparator)
           
 java.util.List getAncestorPaths(java.lang.String separator, boolean initSeparator)
           
 java.util.List getAncestors()
           
 java.util.List getAncestors(boolean includeSelf, boolean includeRoot)
           
 java.lang.String getAttribute(java.lang.String name)
          Returns the value of the node attribute.
 java.util.Iterator getAttributeNames()
           
 void getAttributeSet(java.util.Set attributes, java.lang.String attributeName)
           
 void getAttributeSet(java.util.Set attributes, java.lang.String attributeName, boolean allDescendents)
           
 void getAttributeSet(java.util.Set attributes, java.lang.String attributeName, boolean allDescendents, ITreeNodeComparator comparator)
           
 java.util.Iterator getAttributeValues(java.lang.String name)
          Returns an iterator to all values for an attribute or null if the node has no values for this attribute.
 java.lang.String getAttributeValues(java.lang.String name, java.lang.String delimiter)
           
 TreeNode getChildNode(java.lang.String name)
           
 java.util.Iterator getChildren()
           
 int getChildrenCount()
           
 java.util.List getDescendents()
           
 java.util.List getDescendents(boolean includeSelf)
          Gets all descendents
 java.util.List getDescendents(boolean includeSelf, int generations)
          returns all descendents up to a set number of generations (1 = children, 2 = grandchildren, 3=greatgrandchildren etc.)
 int getLevel()
           
 java.lang.String getName()
           
 java.lang.String getNameCount()
           
 IResultSet getNestedResultSet(IResultMatcher resMatcher, java.lang.String nestedResultPath)
           
 IResultSet getNestedResultSet(java.lang.String nestedResultPath)
           
 int getNodeCount()
           
 java.lang.String getNodeID()
          returns nodeIDValue if set, else returns the path
 java.lang.String getNodeIDValue()
           
 TreeNode getParent()
           
 java.util.Iterator getParents()
           
 java.lang.String getPath(java.lang.String separator, boolean initSeparator)
           
 java.lang.String getPathNoRoot(java.lang.String separator, boolean initSeparator)
           
 java.util.List getPaths(java.lang.String separator, boolean initSeparator)
           
 java.util.List getPathsNoRoot(java.lang.String separator, boolean initSeparator)
           
 java.lang.String getPatternStringValue(java.lang.String pattern, java.lang.String startBrace, java.lang.String endBrace)
           
 IResultSet getResultSet()
           
protected  TreeNode getRootNode()
           
 java.util.List getSiblings()
           
 java.util.List getSiblings(boolean includeSelf)
           
 TreeRoot getTreeRoot()
           
 boolean hasAttributeValue(java.lang.String attribute, java.lang.String value)
           
 boolean hasChildren()
           
 boolean hasMultipleParents()
          methods to support Thesaurus structure default is single parent.
 boolean hasMultipleValues(java.lang.String attribute)
           
 boolean haveChildNode(java.lang.String name)
           
 boolean isOpen()
           
 boolean isRoot()
           
 boolean isVisible()
           
 boolean needsUpdate()
           
 void removeAttribute(java.lang.String name)
           
 void removeChildNode(java.lang.String name)
           
 void setActiveNode(TreeNode node)
           
 void setActiveNodeID(java.lang.Object nodeID)
           
 void setAttribute(java.lang.String name, java.lang.String value)
           
 void setMaxCount(int maxCount)
          used to set maxHits
 void setName(java.lang.String name)
           
 void setNeedsUpdate(boolean needsUpdate)
          sets the update flag: This flag is used by ITreeBuilders to determine if a node's children need to be calculated.
 void setNodeCount(int nodeCount)
          Enables implementation to change the meaning of a node "count"
 void setNodeID(java.lang.String nodeID)
           
 void setOpenState(boolean isOpen)
           
protected  void setParent(TreeNode parent)
           
 void setResultSet(IResultSet resSet)
           
 void sortChildren(ITreeNodeComparator treeNodeComparator)
          Sorts the children list using a treeNodeComparator
 void toggleState()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

activeNode

protected TreeNode activeNode

name

protected java.lang.String name

openState

protected boolean openState

nodeID

protected java.lang.String nodeID

parent

protected TreeNode parent

nodeCount

protected java.lang.Integer nodeCount

maxCount

protected int maxCount

children

protected java.util.ArrayList children

needsUpdate

protected boolean needsUpdate
Constructor Detail

TreeNode

public TreeNode()
Method Detail

setName

public void setName(java.lang.String name)

getName

public java.lang.String getName()

getNameCount

public java.lang.String getNameCount()

getPathNoRoot

public java.lang.String getPathNoRoot(java.lang.String separator,
                                      boolean initSeparator)

getPath

public java.lang.String getPath(java.lang.String separator,
                                boolean initSeparator)

getNodeID

public java.lang.String getNodeID()
returns nodeIDValue if set, else returns the path


getNodeIDValue

public java.lang.String getNodeIDValue()

setNodeID

public void setNodeID(java.lang.String nodeID)

setParent

protected void setParent(TreeNode parent)

hasChildren

public boolean hasChildren()

getLevel

public int getLevel()

isRoot

public boolean isRoot()

getChildren

public java.util.Iterator getChildren()

sortChildren

public void sortChildren(ITreeNodeComparator treeNodeComparator)
Sorts the children list using a treeNodeComparator


getChildrenCount

public int getChildrenCount()

getDescendents

public java.util.List getDescendents()

getDescendents

public java.util.List getDescendents(boolean includeSelf)
Gets all descendents


getDescendents

public java.util.List getDescendents(boolean includeSelf,
                                     int generations)
returns all descendents up to a set number of generations (1 = children, 2 = grandchildren, 3=greatgrandchildren etc.)


getSiblings

public java.util.List getSiblings()

getSiblings

public java.util.List getSiblings(boolean includeSelf)

getAncestors

public java.util.List getAncestors()

getAncestors

public java.util.List getAncestors(boolean includeSelf,
                                   boolean includeRoot)

setNodeCount

public void setNodeCount(int nodeCount)
Enables implementation to change the meaning of a node "count"


setMaxCount

public void setMaxCount(int maxCount)
used to set maxHits


getNodeCount

public int getNodeCount()

getTreeRoot

public TreeRoot getTreeRoot()

getRootNode

protected TreeNode getRootNode()

addChildNode

public void addChildNode(TreeNode treeNode)

addChildNode

public void addChildNode(java.lang.String childName,
                         java.lang.String pathSeparator,
                         boolean uniqueNames)

haveChildNode

public boolean haveChildNode(java.lang.String name)

getChildNode

public TreeNode getChildNode(java.lang.String name)

deleteChildNodes

public void deleteChildNodes()

removeChildNode

public void removeChildNode(java.lang.String name)

setOpenState

public void setOpenState(boolean isOpen)

toggleState

public void toggleState()

isOpen

public boolean isOpen()

isVisible

public boolean isVisible()

setActiveNode

public void setActiveNode(TreeNode node)

setActiveNodeID

public void setActiveNodeID(java.lang.Object nodeID)

getActiveNode

public TreeNode getActiveNode()

setNeedsUpdate

public void setNeedsUpdate(boolean needsUpdate)
sets the update flag: This flag is used by ITreeBuilders to determine if a node's children need to be calculated.


needsUpdate

public boolean needsUpdate()

findNode

public TreeNode findNode(java.lang.Object nodeID)
Returns a TreeNode that matches the given nodeID from within the Tree that this TreeNode belongs to.


setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)

addAttribute

public void addAttribute(java.lang.String name,
                         java.lang.String value)

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Returns the value of the node attribute. If the node has multiple values, this method returns the first value. If the node has no values for the attribute, the method returns null.


getAttributeValues

public java.lang.String getAttributeValues(java.lang.String name,
                                           java.lang.String delimiter)

removeAttribute

public void removeAttribute(java.lang.String name)

hasMultipleValues

public boolean hasMultipleValues(java.lang.String attribute)

getAttributeValues

public java.util.Iterator getAttributeValues(java.lang.String name)
Returns an iterator to all values for an attribute or null if the node has no values for this attribute.


hasAttributeValue

public boolean hasAttributeValue(java.lang.String attribute,
                                 java.lang.String value)

getAttributeNames

public java.util.Iterator getAttributeNames()

getAllSubAttributes

public java.util.Set getAllSubAttributes(java.lang.String attributeName)
returns the set of all attribute values in this nodes sub nodes.


getAllSubAttributes

public java.util.Set getAllSubAttributes(java.lang.String attributeName,
                                         boolean allDescendents)

getAllSubAttributes

public java.util.Set getAllSubAttributes(java.lang.String attributeName,
                                         boolean allDescendents,
                                         ITreeNodeComparator comparator)

getAllParentAttributes

public java.util.Set getAllParentAttributes(java.lang.String attributeName)

getAllParentAttributes

public java.util.Set getAllParentAttributes(java.lang.String attributeName,
                                            boolean allAncestors)

getAllParentAttributes

public java.util.Set getAllParentAttributes(java.lang.String attributeName,
                                            boolean allAncestors,
                                            ITreeNodeComparator comparator)

getAttributeSet

public void getAttributeSet(java.util.Set attributes,
                            java.lang.String attributeName)

getAttributeSet

public void getAttributeSet(java.util.Set attributes,
                            java.lang.String attributeName,
                            boolean allDescendents)

getAttributeSet

public void getAttributeSet(java.util.Set attributes,
                            java.lang.String attributeName,
                            boolean allDescendents,
                            ITreeNodeComparator comparator)

setResultSet

public void setResultSet(IResultSet resSet)

getResultSet

public IResultSet getResultSet()

addResult

public void addResult(IResult res)

hasMultipleParents

public boolean hasMultipleParents()
methods to support Thesaurus structure default is single parent.


addParent

public void addParent(TreeNode parent)

getParents

public java.util.Iterator getParents()

getParent

public TreeNode getParent()

getAncestorPaths

public java.util.List getAncestorPaths(java.lang.String separator,
                                       boolean initSeparator)

getPaths

public java.util.List getPaths(java.lang.String separator,
                               boolean initSeparator)

getPathsNoRoot

public java.util.List getPathsNoRoot(java.lang.String separator,
                                     boolean initSeparator)

copyNodeAttributes

public void copyNodeAttributes(TreeNode node,
                               boolean addResults,
                               java.util.Map attributeActionMap)
Add the node attributes and nested results to this node. if not null, attributeActionMap contains a map of the attribute name and an action ('ADD', 'REPLACE')


copyNode

public static TreeNode copyNode(TreeNode node)

copyNode

public static TreeNode copyNode(TreeNode node,
                                TreeRoot toTree,
                                boolean copyAll)

copyNodeOnly

public static TreeNode copyNodeOnly(TreeNode node)

convertToResult

public static IResult convertToResult(TreeNode treeNode)

copyNodeCount

public void copyNodeCount(TreeNode toNode)

createAttributesResult

public IResult createAttributesResult()
Create an IResult object from the node attributes.


getNestedResultSet

public IResultSet getNestedResultSet(java.lang.String nestedResultPath)

getNestedResultSet

public IResultSet getNestedResultSet(IResultMatcher resMatcher,
                                     java.lang.String nestedResultPath)

getPatternStringValue

public java.lang.String getPatternStringValue(java.lang.String pattern,
                                              java.lang.String startBrace,
                                              java.lang.String endBrace)