flattree.tree
Class AbstractLeaf

java.lang.Object
  extended by flattree.tree.AbstractLeaf
All Implemented Interfaces:
Leaf
Direct Known Subclasses:
ConstantLeaf, JumpLeaf, SkipLeaf, ValueLeaf

public abstract class AbstractLeaf
extends Object
implements Leaf

Base class handling common functionality of leaves.

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

Field Summary
 
Fields inherited from interface flattree.tree.Leaf
REQUIRED
 
Constructor Summary
AbstractLeaf()
           
 
Method Summary
 boolean getThrowOnRead()
           
 boolean read(ReadLine line, State state)
          Delegates to readImpl(ReadLine, State) and sets the read range on the State.
protected abstract  boolean readImpl(ReadLine line, State state)
          Do the actual reading.
 void setThrowOnRead(boolean throwOnRead)
          Should the inability to read from a ReadLine fail by throwing a TreeException or just return false instead.
 AbstractLeaf throwOnRead()
          Convenience mutator supporting method chaining.
protected  void throwOnRead(String message, ReadLine line)
          Throw a TreeException because of a read failure if so configured.
 void write(WriteLine line, State state)
          Delegates to writeImpl(WriteLine, State) and sets the written range on the State.
protected abstract  void writeImpl(WriteLine line, State state)
          Do the actual writing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractLeaf

public AbstractLeaf()
Method Detail

setThrowOnRead

public void setThrowOnRead(boolean throwOnRead)
Should the inability to read from a ReadLine fail by throwing a TreeException or just return false instead.

Parameters:
throwOnRead -
See Also:
throwOnRead(String, ReadLine), Leaf.read(ReadLine, State), Node.read(ReadLine, State)

getThrowOnRead

public boolean getThrowOnRead()
See Also:
setThrowOnRead(boolean)

throwOnRead

public AbstractLeaf throwOnRead()
Convenience mutator supporting method chaining.

See Also:
setThrowOnRead(boolean)

throwOnRead

protected void throwOnRead(String message,
                           ReadLine line)
                    throws TreeException
Throw a TreeException because of a read failure if so configured.

Parameters:
message - message of exception
line - the failed line
Throws:
TreeException - if configured to throw on read
See Also:
setThrowOnRead(boolean)

write

public final void write(WriteLine line,
                        State state)
Delegates to writeImpl(WriteLine, State) and sets the written range on the State.

Specified by:
write in interface Leaf
Parameters:
line - line to write to
state - state to put this leaf's value to
See Also:
State.setRange(Leaf, int, int)

writeImpl

protected abstract void writeImpl(WriteLine line,
                                  State state)
Do the actual writing.


read

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

Specified by:
read in interface Leaf
Parameters:
line - line to read from
state - state to get this leaf's value from
Returns:
true if leaf could be read or false otherwise
See Also:
State.setRange(Leaf, int, int), setThrowOnRead(boolean)

readImpl

protected abstract boolean readImpl(ReadLine line,
                                    State state)
Do the actual reading.



Copyright © 2011. All Rights Reserved.