info.bioinfweb.treegraph.document.undo.edit
Class CalculateColumnEdit

java.lang.Object
  extended by info.bioinfweb.treegraph.document.undo.DocumentEdit
      extended by info.bioinfweb.treegraph.document.undo.NodeBranchDataEdit
          extended by info.bioinfweb.treegraph.document.undo.edit.CalculateColumnEdit
All Implemented Interfaces:
javax.swing.undo.UndoableEdit

public class CalculateColumnEdit
extends NodeBranchDataEdit

Calculates a node/branch data column as specified by the passed expression.

Since:
2.0.24
Author:
Ben Stöver

Field Summary
private  java.util.Map<java.lang.String,NodeBranchDataAdapter> adapterMap
           
static java.lang.String BRANCH_LENGTH_VAR
           
static java.lang.String CURRENT_VALUE_VAR
           
private  java.util.List<java.lang.String> errors
           
private  java.lang.String expression
           
static java.lang.String GET_VALUE_FUNC
           
static java.lang.String HAS_VALUE_FUNC
           
private  boolean isEvaluating
           
private  boolean isEvaluatingDecimal
           
static java.lang.String NODE_NAMES_VAR
           
private  org.nfunk.jep.JEP parser
           
private  Node position
           
static java.lang.String UNIQUE_NODE_NAMES_VAR
           
 
Fields inherited from class info.bioinfweb.treegraph.document.undo.NodeBranchDataEdit
adapter, backup
 
Fields inherited from class info.bioinfweb.treegraph.document.undo.DocumentEdit
document
 
Constructor Summary
CalculateColumnEdit(Document document, NodeBranchDataAdapter targetAdapter, java.lang.String expression)
           
 
Method Summary
private  void calculateSubtree(Node root)
           
private  java.util.HashMap<java.lang.String,NodeBranchDataAdapter> createAdapterMap()
           
private  org.nfunk.jep.JEP createParser()
           
 boolean evaluate()
          Evaluates the expression of this instance.
private  java.lang.String evaluationStep(java.lang.Object defaultValue)
          Evaluates the expression with one set of variable values.
private  java.lang.Object getCurrentValue(NodeBranchDataAdapter adapter)
          Returns the value of the specified column in the current line (specified by position).
 java.lang.String[] getErrors()
          Returns a description of the errors that occured during the last call of redo() or evaluate().
private  java.lang.Object getIDValue(java.lang.String id)
          Returns the value of the current line in the column specified the passed id present.
 java.lang.String getPresentationName()
           
 void redo()
           
 
Methods inherited from class info.bioinfweb.treegraph.document.undo.NodeBranchDataEdit
undo
 
Methods inherited from class info.bioinfweb.treegraph.document.undo.DocumentEdit
addEdit, canRedo, canUndo, die, getRedoPresentationName, getUndoPresentationName, isSignificant, replaceEdit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CURRENT_VALUE_VAR

public static final java.lang.String CURRENT_VALUE_VAR
See Also:
Constant Field Values

UNIQUE_NODE_NAMES_VAR

public static final java.lang.String UNIQUE_NODE_NAMES_VAR
See Also:
Constant Field Values

NODE_NAMES_VAR

public static final java.lang.String NODE_NAMES_VAR
See Also:
Constant Field Values

BRANCH_LENGTH_VAR

public static final java.lang.String BRANCH_LENGTH_VAR
See Also:
Constant Field Values

GET_VALUE_FUNC

public static final java.lang.String GET_VALUE_FUNC
See Also:
Constant Field Values

HAS_VALUE_FUNC

public static final java.lang.String HAS_VALUE_FUNC
See Also:
Constant Field Values

expression

private java.lang.String expression

parser

private org.nfunk.jep.JEP parser

adapterMap

private java.util.Map<java.lang.String,NodeBranchDataAdapter> adapterMap

isEvaluating

private boolean isEvaluating

isEvaluatingDecimal

private boolean isEvaluatingDecimal

position

private Node position

errors

private java.util.List<java.lang.String> errors
Constructor Detail

CalculateColumnEdit

public CalculateColumnEdit(Document document,
                           NodeBranchDataAdapter targetAdapter,
                           java.lang.String expression)
Method Detail

createParser

private org.nfunk.jep.JEP createParser()

createAdapterMap

private java.util.HashMap<java.lang.String,NodeBranchDataAdapter> createAdapterMap()

evaluationStep

private java.lang.String evaluationStep(java.lang.Object defaultValue)
Evaluates the expression with one set of variable values.

Parameters:
defaultValue - - either a string or a double value
Returns:
the error information or null if no error occurred.

evaluate

public boolean evaluate()
Evaluates the expression of this instance. Error can be obtined by calling getErrors().

Returns:
true if the expression contained no errors.

getCurrentValue

private java.lang.Object getCurrentValue(NodeBranchDataAdapter adapter)
Returns the value of the specified column in the current line (specified by position).

Parameters:
adapter - - defined the column to use
Returns:
a value of type Double or String

getIDValue

private java.lang.Object getIDValue(java.lang.String id)
                             throws org.nfunk.jep.ParseException
Returns the value of the current line in the column specified the passed id present.

Parameters:
id - - the ID of the node/branch data column
Returns:
the value (as Double, String) or null if the specified column does not contain any value at the current position or a Double with the value 1 if isEvaluating is true
Throws:
UndefinedIDException - - if no column with the specified ID exists
org.nfunk.jep.ParseException

calculateSubtree

private void calculateSubtree(Node root)

redo

public void redo()
          throws javax.swing.undo.CannotRedoException
Specified by:
redo in interface javax.swing.undo.UndoableEdit
Overrides:
redo in class DocumentEdit
Throws:
javax.swing.undo.CannotRedoException

getPresentationName

public java.lang.String getPresentationName()

getErrors

public java.lang.String[] getErrors()
Returns a description of the errors that occured during the last call of redo() or evaluate().

Returns: