Package de.unirostock.sems.xmlutils.ds
Class TreeNode
- java.lang.Object
-
- de.unirostock.sems.xmlutils.ds.TreeNode
-
- Direct Known Subclasses:
DocumentNode,TextNode
public abstract class TreeNode extends Object
The abstract class TreeNode representing a node in a document tree.- Author:
- Martin Scharm
-
-
Field Summary
Fields Modifier and Type Field Description static intCOPIEDCOPIED => node was copied.protected TreeDocumentdocThe corresponding document.static intDOC_NODEDOC_NODE this is a DocumentNode.static intGLUEDGLUED => node was glued.static intKIDSSWAPPEDKIDSSWAPPED => the sequence of kids of this node were altered.protected intlevelThe level in the tree document.protected intmodifiedThe current modification state.static intMODIFIEDMODIFIED => node was modified.static intMOVEDMOVED => node has moves.protected StringownHashThe hash of this single nodeprotected DocumentNodeparentThe parent node.static intSUB_MODIFIEDSUB_MODIFIED => the corresponding subtree was modified.static intSUBTREEUNMAPPEDSUBTREEUNMAPPED => the whole subtree is unmapped.static intSWAPPEDKIDSWAPPEDKID => this is a swapped kid.static intTEXT_NODETEXT_NODE this is a TextNode.static StringTEXT_TAGThe node tag name for text nodes, as we will use it in XPath expressions.protected inttypeThe node type.static intUNCHANGEDUNCHANGED => node hasn't changes.static intUNMAPPEDUNMAPPED => node wasn't mapped.protected StringxPathThe XPath of this node.
-
Constructor Summary
Constructors Constructor Description TreeNode(int type, DocumentNode parent, TreeDocument doc, int level)Instantiates a new tree node.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddModification(int mod)Add a modification.booleancontentDiffers(TreeNode tn)Check if content between two nodes differs.abstract Stringdump(String prefix)Dump this node.abstract booleanevaluate(ConnectionManager conMgmr)Evaluate the modifications of this node.TreeDocumentgetDocument()Gets the corresponding document.intgetLevel()Returns the level of this node in its tree.intgetModification()Returns the modification state.abstract voidgetNodeStats(HashMap<String,Integer> map)Gets the node statistics of the subtree rooted in this node: tagname => number nodes having this tag name.abstract StringgetOwnHash()Gets the hash of this single node (w/o its subtree).DocumentNodegetParent()Gets the parent node.abstract org.jdom2.ElementgetSubDoc(org.jdom2.Element parent)Attaches the subtree rooted in this node to the node parent.abstract StringgetSubTreeHash()Gets the calculated hash of the subtree rooted in this node, in TextNodes it equals the own hash.abstract StringgetTagName()Gets the tag name.intgetType()Gets the node type.abstract doublegetWeight()Gets the weight of this node.StringgetXPath()Gets the XPath expression corresponding to this node.booleanhasModification(int mod)Checks for a certain modification.booleanisRoot()Checks if this is the root of the tree.booleannetworkDiffers(TreeNode tn, ConnectionManager conMgmr, Connection c)Checks if the network of two nodes differs.voidresetModifications()Resets all modifications.protected abstract voidreSetupStructureDown(TreeDocument doc, int numChild)Re-setup the document structure downwards.protected abstract voidreSetupStructureUp()Re-setup the document structure upwards.voidrmModification(int mod)Remove a modification.voidsetModification(int mod)Sets the modification.
-
-
-
Field Detail
-
TEXT_TAG
public static final String TEXT_TAG
The node tag name for text nodes, as we will use it in XPath expressions.- See Also:
- Constant Field Values
-
UNCHANGED
public static final int UNCHANGED
UNCHANGED => node hasn't changes.- See Also:
- Constant Field Values
-
UNMAPPED
public static final int UNMAPPED
UNMAPPED => node wasn't mapped.- See Also:
- Constant Field Values
-
MOVED
public static final int MOVED
MOVED => node has moves.- See Also:
- Constant Field Values
-
MODIFIED
public static final int MODIFIED
MODIFIED => node was modified.- See Also:
- Constant Field Values
-
SUB_MODIFIED
public static final int SUB_MODIFIED
SUB_MODIFIED => the corresponding subtree was modified.- See Also:
- Constant Field Values
-
COPIED
public static final int COPIED
COPIED => node was copied.- See Also:
- Constant Field Values
-
GLUED
public static final int GLUED
GLUED => node was glued.- See Also:
- Constant Field Values
-
KIDSSWAPPED
public static final int KIDSSWAPPED
KIDSSWAPPED => the sequence of kids of this node were altered.- See Also:
- Constant Field Values
-
SWAPPEDKID
public static final int SWAPPEDKID
SWAPPEDKID => this is a swapped kid.- See Also:
- Constant Field Values
-
SUBTREEUNMAPPED
public static final int SUBTREEUNMAPPED
SUBTREEUNMAPPED => the whole subtree is unmapped.- See Also:
- Constant Field Values
-
DOC_NODE
public static final int DOC_NODE
DOC_NODE this is a DocumentNode.- See Also:
DocumentNode, Constant Field Values
-
TEXT_NODE
public static final int TEXT_NODE
TEXT_NODE this is a TextNode.- See Also:
TextNode, Constant Field Values
-
modified
protected int modified
The current modification state.
-
type
protected int type
The node type.
-
xPath
protected String xPath
The XPath of this node.
-
parent
protected DocumentNode parent
The parent node.
-
doc
protected TreeDocument doc
The corresponding document.
-
level
protected int level
The level in the tree document.
-
ownHash
protected String ownHash
The hash of this single node
-
-
Constructor Detail
-
TreeNode
public TreeNode(int type, DocumentNode parent, TreeDocument doc, int level)Instantiates a new tree node.- Parameters:
type- the node typeparent- the parent nodedoc- the corresponding documentlevel- the level in the tree
-
-
Method Detail
-
getLevel
public int getLevel()
Returns the level of this node in its tree. Root has level 0.- Returns:
- the level
-
getModification
public int getModification()
Returns the modification state.- Returns:
- the modification
-
rmModification
public void rmModification(int mod)
Remove a modification.- Parameters:
mod- the modification
-
addModification
public void addModification(int mod)
Add a modification.- Parameters:
mod- the modification
-
setModification
public void setModification(int mod)
Sets the modification.- Parameters:
mod- the new modification
-
hasModification
public boolean hasModification(int mod)
Checks for a certain modification.- Parameters:
mod- the modification- Returns:
- true, if this node has modification mod
-
getType
public int getType()
Gets the node type.
-
getParent
public DocumentNode getParent()
Gets the parent node.- Returns:
- the parent node
-
getXPath
public String getXPath()
Gets the XPath expression corresponding to this node.- Returns:
- the XPath to the node
-
isRoot
public boolean isRoot()
Checks if this is the root of the tree.- Returns:
- true, if this is root
-
resetModifications
public void resetModifications()
Resets all modifications.
-
getDocument
public TreeDocument getDocument()
Gets the corresponding document.- Returns:
- the document
-
networkDiffers
public boolean networkDiffers(TreeNode tn, ConnectionManager conMgmr, Connection c)
Checks if the network of two nodes differs.- Parameters:
tn- the node in another tree documentconMgmr- the connection managerc- the connection- Returns:
- true, if parents of these nodes are not connected.
-
contentDiffers
public boolean contentDiffers(TreeNode tn)
Check if content between two nodes differs. Just compares the nodes, neglects everything else of the tree (e.g. network, kids etc).- Parameters:
tn- the other node to compare- Returns:
- true, if nodes differ
-
getTagName
public abstract String getTagName()
Gets the tag name. For document nodes it's the actual tag name, in case of text nodes you'll receiveTreeNode.TEXT_TAG.- Returns:
- the tag name
-
getWeight
public abstract double getWeight()
Gets the weight of this node.- Returns:
- the weight
-
getOwnHash
public abstract String getOwnHash()
Gets the hash of this single node (w/o its subtree).- Returns:
- the hash of the node
-
getSubTreeHash
public abstract String getSubTreeHash()
Gets the calculated hash of the subtree rooted in this node, in TextNodes it equals the own hash.- Returns:
- the hash of the current subtree
-
evaluate
public abstract boolean evaluate(ConnectionManager conMgmr)
Evaluate the modifications of this node. Just useful for tree comparisons.- Parameters:
conMgmr- the connection manager- Returns:
- true, if node was changed
-
dump
public abstract String dump(String prefix)
Dump this node. Just for debugging purposes..- Parameters:
prefix- the prefix for a line (indention)- Returns:
- the produced dump
-
getSubDoc
public abstract org.jdom2.Element getSubDoc(org.jdom2.Element parent)
Attaches the subtree rooted in this node to the node parent. Recursively attaches its children. Will fail forparent == null && this.getType () == TreeNode.TEXT_NODEThat means a text node cannot become root.- Parameters:
parent- the parent element which will root this node. If null, this node will be root in the document- Returns:
- the sub doc
-
reSetupStructureDown
protected abstract void reSetupStructureDown(TreeDocument doc, int numChild)
Re-setup the document structure downwards. (e.g. recompute XPaths etc.)- Parameters:
doc- the document this node corresponds tonumChild- the child number of this node
-
reSetupStructureUp
protected abstract void reSetupStructureUp()
Re-setup the document structure upwards. (e.g. recompute hashes etc.)
-
-