flattree.tree
Class AbstractNode

java.lang.Object
  extended by flattree.tree.AbstractNode
All Implemented Interfaces:
Node
Direct Known Subclasses:
DelimitedNode, DynamicNode, FixedLengthNode, SyntheticNode

public abstract class AbstractNode
extends Object
implements Node

Base class fhandling common functionality of nodes.

See Also:
read(ReadLine, State), write(WriteLine, State)

Constructor Summary
AbstractNode()
           
AbstractNode(String name)
           
 
Method Summary
 AbstractNode add(Leaf leaf)
          Add a single leaf.
 AbstractNode add(Node node)
          A a single child node.
protected  ReadLine beforeRead(ReadLine line)
          Hook method for subclasses to wrap the line to read from.
protected  WriteLine beforeWrite(WriteLine line)
          Hook method for subclasses to wrap the line to write to.
 List<Leaf> getLeaves()
          Get all leaves.
 String getName()
          Name of node.
 List<Node> getNodes()
          Get all children nodes.
 boolean read(ReadLine line, State state)
          Delegates reading to all leaves and sets the range on the State.
 void setLeaves(List<Leaf> leaves)
          Set the leaves of this node.
 void setName(String name)
           
 void setNodes(List<Node> nodes)
          Set the children nodes.
 void write(WriteLine line, State state)
          Delegates writing to all leaves and sets the range on the State.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractNode

public AbstractNode()

AbstractNode

public AbstractNode(String name)
Method Detail

setName

public void setName(String name)

getName

public String getName()
Description copied from interface: Node
Name of node.

Specified by:
getName in interface Node
Returns:
name

setLeaves

public void setLeaves(List<Leaf> leaves)
Set the leaves of this node.

Parameters:
leaves - the leaves

add

public AbstractNode add(Leaf leaf)
Add a single leaf.

Parameters:
leaf - leaf to add
Returns:
this

getLeaves

public List<Leaf> getLeaves()
Get all leaves.

Specified by:
getLeaves in interface Node
Returns:
leaves
See Also:
Collections.unmodifiableList(List)

setNodes

public void setNodes(List<Node> nodes)
Set the children nodes.

Parameters:
nodes - children nodes

add

public AbstractNode add(Node node)
A a single child node.

Parameters:
node - node to add
Returns:
this

getNodes

public List<Node> getNodes()
Get all children nodes.

Specified by:
getNodes in interface Node
Returns:
nodes

read

public final boolean read(ReadLine line,
                          State state)
Delegates reading to all leaves and sets the range on the State.

Specified by:
read in interface Node
Parameters:
line - line to read from
state - state to get values for leaves from
Returns:
false if one of the leaves cannot be read
See Also:
beforeRead(ReadLine), Leaf.read(ReadLine, State), State.setRange(int, int)

beforeRead

protected ReadLine beforeRead(ReadLine line)
Hook method for subclasses to wrap the line to read from.

Parameters:
line - line to wrap before read
Returns:
line to read from

write

public void write(WriteLine line,
                  State state)
Delegates writing to all leaves and sets the range on the State.

Specified by:
write in interface Node
Parameters:
line - line to write to
state - state to put values of leaves to
See Also:
beforeWrite(WriteLine), Leaf.write(WriteLine, State), State.setRange(int, int)

beforeWrite

protected WriteLine beforeWrite(WriteLine line)
Hook method for subclasses to wrap the line to write to.

Parameters:
line - line to wrap before write
Returns:
line to write to


Copyright © 2011. All Rights Reserved.