mulan.data
Class LabelNodeImpl

java.lang.Object
  extended by mulan.data.LabelNodeImpl
All Implemented Interfaces:
Serializable, LabelNode

public class LabelNodeImpl
extends Object
implements LabelNode, Serializable

Implementation of LabelNode, representing a label attribute and its connection within a hierarchy of labels.

Author:
Jozef Vilcek
See Also:
Serialized Form

Constructor Summary
LabelNodeImpl(String name)
          Creates a new instance of LabelNodeImpl.
 
Method Summary
 boolean addChildNode(LabelNode node)
          Adds the specified LabelNode to the set of child nodes.
 boolean equals(Object obj)
          The two LabelNodeImpl nodes are equal if the are the same (points to the same object) of if they returns same getName() value.
 Set<LabelNode> getChildren()
          Gets the unmodifiable Set of child LabelNode of this node, if hierarchy exists.
 Set<String> getChildrenLabels()
          Gets the children of a label
 Set<String> getDescendantLabels()
          Gets a Set of the names of descendant LabelNode of this node, if hierarchy exists.
 String getName()
          Gets the name of the label this node represents.
 LabelNode getParent()
          Gets the parent LabelNode of this node if hierarchy exists.
 boolean hasChildren()
          Determines whether the LabelNode has child nodes.
 int hashCode()
          The hash code is computed based on label name attribute, which defines the identity of the LabelNodeImpl node.
 boolean hasParent()
          Determines whether the LabelNode has a parent node in a hierarchy.
 boolean removeChildNode(LabelNode node)
          Removes the specified LabelNode from the set of child nodes.
protected  void setParent(LabelNode node)
          Sets a node as the parent of this node
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LabelNodeImpl

public LabelNodeImpl(String name)
Creates a new instance of LabelNodeImpl.

Parameters:
name - the name of the label attribute this node represents
Method Detail

addChildNode

public boolean addChildNode(LabelNode node)
Adds the specified LabelNode to the set of child nodes. The parent of added node is set to reference this LabelNode instance. This indicates that there is a hierarchy between these two LabelNode nodes.

Parameters:
node - the LabelNode to be removed
Returns:
true if node was actually removed; false node was not in child nodes set
Throws:
ArgumentNullException - if specified LabelNode parameter is null
IllegalArgumentException - if LabelNode being added has same name as this LabelNode instance (parent)

removeChildNode

public boolean removeChildNode(LabelNode node)
Removes the specified LabelNode from the set of child nodes. The connection between removed LabelNode and its LabelNode.getParent()

Parameters:
node - the LabelNode to be removed
Returns:
true if node was actually removed; false node was not in child nodes set
Throws:
ArgumentNullException - if specified LabelNode parameter is null

getChildrenLabels

public Set<String> getChildrenLabels()
Gets the children of a label

Returns:
a Set of labels

getDescendantLabels

public Set<String> getDescendantLabels()
Description copied from interface: LabelNode
Gets a Set of the names of descendant LabelNode of this node, if hierarchy exists. If no descendant nodes exists for this LabelNode, empty Set is returned.

Specified by:
getDescendantLabels in interface LabelNode
Returns:
the Set of child nodes

getChildren

public Set<LabelNode> getChildren()
Description copied from interface: LabelNode
Gets the unmodifiable Set of child LabelNode of this node, if hierarchy exists. If no child nodes exists for this LabelNode, empty Set is returned.

Specified by:
getChildren in interface LabelNode
Returns:
the Set of child nodes

getName

public String getName()
Description copied from interface: LabelNode
Gets the name of the label this node represents. The name corresponds to the ID of label attribute in the arff data set. The name of the label must be unique within the data set, because the identity of LabelNode is determined by the name.

Specified by:
getName in interface LabelNode
Returns:
the name of the label this node represents

getParent

public LabelNode getParent()
Description copied from interface: LabelNode
Gets the parent LabelNode of this node if hierarchy exists. If the node has not a parent LabelNode, null is returned.

Specified by:
getParent in interface LabelNode
Returns:
the parent LabelNode or null if the parent does not exists.

setParent

protected void setParent(LabelNode node)
Sets a node as the parent of this node

Parameters:
node - a node to be set as parent

hasChildren

public boolean hasChildren()
Description copied from interface: LabelNode
Determines whether the LabelNode has child nodes.

Specified by:
hasChildren in interface LabelNode
Returns:
true if the node has child nodes; false otherwise.

hasParent

public boolean hasParent()
Description copied from interface: LabelNode
Determines whether the LabelNode has a parent node in a hierarchy.

Specified by:
hasParent in interface LabelNode
Returns:
true if the node has parent; false otherwise.

hashCode

public int hashCode()
The hash code is computed based on label name attribute, which defines the identity of the LabelNodeImpl node.

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
The two LabelNodeImpl nodes are equal if the are the same (points to the same object) of if they returns same getName() value. The name of the labels gives the identity to the LabelNodeImpl.

Overrides:
equals in class Object