antsnest.datastructure
Class DefaultAntNode

java.lang.Object
  extended by antsnest.datastructure.DefaultAntNode
All Implemented Interfaces:
AntNode, Serializable
Direct Known Subclasses:
DefaultAntCData, DefaultAntComment, DefaultAntElement, DefaultAntProject, DefaultAntTarget, DefaultAntTextNode

public abstract class DefaultAntNode
extends Object
implements AntNode

Implementation of an AntNode

Author:
Chris Clohosy
See Also:
AntNode, Serialized Form

Constructor Summary
DefaultAntNode(int type)
          Constructs a new node
 
Method Summary
 void addAttribute(AntAttribute attribute)
          Adds an attribute to the end of the list
 void addAttribute(AntAttribute attribute, int position)
          Adds an attribute to this node
 void addNode(AntNode node)
          Adds a node to this node
 void addNode(AntNode node, int position)
          Adds a node to this node
 void changeAttribute(AntAttribute attribute)
          Changes an attribute in the list
abstract  AntNode cloneNode(IDPool idPool)
          Gets a clone of this node
 boolean equals(Object obj)
          Whether this node is equal to another
 AntAttribute getAttribute(int position)
          Gets an attribute from this node
 AntAttribute getAttribute(String name)
          Gets the attribute with the required name
 int getAttributeSize()
          Gets the number of attributes held by this node
 String getData()
          Gets any character data stored in this node
 String getDescription()
          Gets the description of this node
 IDPool getIDPool()
          Gets the ID pool used by this node
 String getName()
          Gets the name of this node
 AntNode getNode(int position)
          Gets a node from this node
 long getNodeID()
          Gets the ID of this node
 int getNodeSize()
          Gets tthe number of nested elements held by thsi node
 AntNodeText getNodeText()
          Gets the text node in this one, if any
 AntNode getParent()
          Gets the parent of this node
 int getType()
          Gets the type of this node
 int getTypeAt(int position)
          Gets the type of the node at the specified position
 int indexOfAttribute(AntAttribute attribute)
          Gets the index of an attribute in this node
 int indexOfNode(AntNode node)
          Gets the index of a node nested in this node
 void moveAttribute(int fromPosition, int toPosition)
          Moves an attribute in this node
 void moveNode(int fromPosition, int toPosition)
          Moves a node to a new position
 void removeAttribute(AntAttribute attribute)
          Removes an attribute from this node
 void removeAttribute(int position)
          Removes an attribute from this node
 void removeNode(AntNode node)
          Removes a node from this node
 void removeNode(int position)
          Removes a node from this node
 void setData(String data)
          Sets the character data stored in this node
 void setDescription(String description)
          Sets the description of this node
 void setIDPool(IDPool idPool)
          Sets the ID pool used by this node
 void setName(String name)
          Sets the name of this node
 void setNodeID(long id)
          Sets the ID of this node
 void setParent(AntNode parent)
          Sets the parent of this node
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultAntNode

public DefaultAntNode(int type)
Constructs a new node

Parameters:
type - the type of this node
Method Detail

setIDPool

public void setIDPool(IDPool idPool)
Sets the ID pool used by this node

Specified by:
setIDPool in interface AntNode
Parameters:
idPool - the ID pool to use

getIDPool

public IDPool getIDPool()
Gets the ID pool used by this node

Specified by:
getIDPool in interface AntNode
Returns:
an IDPool, the ID pool being used

setNodeID

public void setNodeID(long id)
Sets the ID of this node

Specified by:
setNodeID in interface AntNode
Parameters:
id - the ID of this node

getNodeID

public long getNodeID()
Gets the ID of this node

Specified by:
getNodeID in interface AntNode
Returns:
a long, the ID of this node

getName

public String getName()
Gets the name of this node

Specified by:
getName in interface AntNode
Returns:
a String, the name

setName

public void setName(String name)
Sets the name of this node

Specified by:
setName in interface AntNode
Parameters:
name - the new name

getParent

public AntNode getParent()
Gets the parent of this node

Specified by:
getParent in interface AntNode
Returns:
an AntNode, the parent

setParent

public void setParent(AntNode parent)
Sets the parent of this node

Specified by:
setParent in interface AntNode
Parameters:
parent - the new parent

getDescription

public String getDescription()
Gets the description of this node

Specified by:
getDescription in interface AntNode
Returns:
a String, the description

setDescription

public void setDescription(String description)
Sets the description of this node

Specified by:
setDescription in interface AntNode
Parameters:
description - the new description

getType

public int getType()
Gets the type of this node

Specified by:
getType in interface AntNode
Returns:
an int, the type

getAttribute

public AntAttribute getAttribute(int position)
Gets an attribute from this node

Specified by:
getAttribute in interface AntNode
Parameters:
position - the index of the attribute required
Returns:
an AntAttribute, the required attribute

getAttribute

public AntAttribute getAttribute(String name)
Gets the attribute with the required name

Specified by:
getAttribute in interface AntNode
Parameters:
name - the required attribute's name
Returns:
an AntAttribute, the required attribute

moveAttribute

public void moveAttribute(int fromPosition,
                          int toPosition)
Moves an attribute in this node

Specified by:
moveAttribute in interface AntNode
Parameters:
fromPosition - the index of the attribute to move
toPosition - the index to move the attribute to

indexOfAttribute

public int indexOfAttribute(AntAttribute attribute)
Gets the index of an attribute in this node

Specified by:
indexOfAttribute in interface AntNode
Parameters:
attribute - the specified attribute
Returns:
an int, the index

addAttribute

public void addAttribute(AntAttribute attribute,
                         int position)
Adds an attribute to this node

Specified by:
addAttribute in interface AntNode
Parameters:
attribute - the attribute to add
position - the index to place the attribute

addAttribute

public void addAttribute(AntAttribute attribute)
Adds an attribute to the end of the list

Specified by:
addAttribute in interface AntNode
Parameters:
attribute - the attribute to add

removeAttribute

public void removeAttribute(AntAttribute attribute)
Removes an attribute from this node

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

removeAttribute

public void removeAttribute(int position)
Removes an attribute from this node

Specified by:
removeAttribute in interface AntNode
Parameters:
position - the position of the attribute to remove

changeAttribute

public void changeAttribute(AntAttribute attribute)
Changes an attribute in the list

Specified by:
changeAttribute in interface AntNode
Parameters:
attribute - the new version of an attribute

getNode

public AntNode getNode(int position)
Gets a node from this node

Specified by:
getNode in interface AntNode
Parameters:
position - the position of the required node
Returns:
an AntNode, the required node

addNode

public void addNode(AntNode node,
                    int position)
             throws CannotAddNodeException
Adds a node to this node

Specified by:
addNode in interface AntNode
Parameters:
node - the node to add
position - the the index where to place the node
Throws:
CannotAddNodeException - if the node is not allowed to be added

addNode

public void addNode(AntNode node)
             throws CannotAddNodeException
Adds a node to this node

Specified by:
addNode in interface AntNode
Parameters:
node - the node to add
Throws:
CannotAddNodeException - if the node is not allowed to be added

removeNode

public void removeNode(AntNode node)
Removes a node from this node

Specified by:
removeNode in interface AntNode
Parameters:
node - the node to remove

removeNode

public void removeNode(int position)
Removes a node from this node

Specified by:
removeNode in interface AntNode
Parameters:
position - the index of the node to remove

moveNode

public void moveNode(int fromPosition,
                     int toPosition)
              throws CannotAddNodeException
Moves a node to a new position

Specified by:
moveNode in interface AntNode
Parameters:
fromPosition - the position the node is moving from
toPosition - the position the node is moving to
Throws:
CannotAddNodeException - if the node is not allowed to be added

indexOfNode

public int indexOfNode(AntNode node)
Gets the index of a node nested in this node

Specified by:
indexOfNode in interface AntNode
Parameters:
node - the specified node
Returns:
an int, the index

getTypeAt

public int getTypeAt(int position)
Gets the type of the node at the specified position

Specified by:
getTypeAt in interface AntNode
Parameters:
position - the index of the required node type
Returns:
an int, the type

equals

public boolean equals(Object obj)
Whether this node is equal to another

Overrides:
equals in class Object
Parameters:
obj - the object to compare to
Returns:
a boolean, whether they are equal

getAttributeSize

public int getAttributeSize()
Gets the number of attributes held by this node

Specified by:
getAttributeSize in interface AntNode
Returns:
an int, the number of attributes

getNodeSize

public int getNodeSize()
Gets tthe number of nested elements held by thsi node

Specified by:
getNodeSize in interface AntNode
Returns:
an int, the number of elements

getData

public String getData()
Gets any character data stored in this node

Specified by:
getData in interface AntNode
Returns:
a String, the character data, or null if empty

setData

public void setData(String data)
Sets the character data stored in this node

Specified by:
setData in interface AntNode
Parameters:
data - the new character data

getNodeText

public AntNodeText getNodeText()
Gets the text node in this one, if any

Specified by:
getNodeText in interface AntNode
Returns:
an AntNodeText, the text nose inside this one

cloneNode

public abstract AntNode cloneNode(IDPool idPool)
Gets a clone of this node

Specified by:
cloneNode in interface AntNode
Parameters:
idPool - an ID pool to use
Returns:
an AntNode, the cloned node