edu.swri.swiftvis
Class DataFormula

java.lang.Object
  extended by edu.swri.swiftvis.DataFormula
All Implemented Interfaces:
java.io.Serializable

public class DataFormula
extends java.lang.Object
implements java.io.Serializable

This class is intended to allow users to type in formulas that can be applied to the inputs of a given data sink. The formulas can use standard mathematical functions in them in normal infix notation with parentheses. It also allows you to specify data from one of the inputs. Typically the functions will be working on a particular DataElement though it is possible to refer to earlier or later elements as well. The format for referring to data elements is d[#].p[#] for an integer property or d[#].v[#] for a value. The # in the d subscript is which source for that sink to use. The # in the p or v subscript is which property of value. To refer to values of earlier of later elements you can use a format like d[#].v[offset][#]. Here the offset is how many data elements forward or backward to look. The shorter form above is equivalent to d[#].v[0][#]. Because many situations will involve only one data source, you can also use a shorter notation where the d[#]. is dropped off. In this case the [0] source is assumed. These formulas support the operators +, -, *, /, %, and ** as well as the ternary operator ?: for doing conditionals (See BooleanFormula for the format of the conditionals). In addition, They can also include the functions sin, cos, tan, sqrt, exp, log, abs, rand, floor, and round. The class also has built into it the ability to include values or parameters selected from a "group" of adjacent elements. A group is defined by a formula and any sequential elements with the same value of that formula are part of the group. Group information is specified in braces before the rest of the formula. The format is {group formula, boolean selector 1, boolean selector 2, ...}. In the formula, the selected indices are specified with primes ('). The following formula would return the difference between the current semimajor axis and that of the second planet for a bin.dat input {v[0],p[0]=-2} v[1]-v'[1]. Note that the grouping is done by time so that we compare bodies during the same timestep which is all that makes sense. This class parses the formula out to an expression tree to enable quick evalutation.

See Also:
Serialized Form

Nested Class Summary
private  class DataFormula.AbsNode
           
private  class DataFormula.CosNode
           
private  class DataFormula.DivNode
           
private static interface DataFormula.EquNode
           
private  class DataFormula.ExpNode
           
private  class DataFormula.FloorNode
           
static class DataFormula.GroupInformation
          This inner class is intended to represent grouping information for a formula.
static interface DataFormula.Listener
           
private  class DataFormula.LogNode
           
private  class DataFormula.MinusNode
           
private  class DataFormula.ModNode
           
private  class DataFormula.MultNode
           
private  class DataFormula.NumberNode
           
private  class DataFormula.ParamNode
           
private  class DataFormula.PlusNode
           
private  class DataFormula.PowNode
           
private  class DataFormula.RandNode
           
private  class DataFormula.RoundNode
           
private  class DataFormula.SinNode
           
private  class DataFormula.SpecialParamNode
           
private  class DataFormula.SpecialValueNode
           
private  class DataFormula.SqrtNode
           
private  class DataFormula.TanNode
           
private  class DataFormula.TernaryNode
           
private  class DataFormula.ValueNode
           
 
Field Summary
private  java.lang.String equ
           
private  boolean errorHandling
           
private static int EXP_LEVEL
           
private  DataFormula.GroupInformation groupInfo
           
private  javax.swing.JTextField inputField
           
private  DataFormula.Listener listener
           
private static int MULT_LEVEL
           
private static int NO_LEVEL
           
private static int PLUS_LEVEL
           
private  DataFormula.EquNode root
           
private static long serialVersionUID
           
private static int TERT_LEVEL
           
 
Constructor Summary
private DataFormula()
           
  DataFormula(DataFormula c)
           
  DataFormula(java.lang.String equation)
           
 
Method Summary
 boolean equals(java.lang.Object o)
           
private  void formulaChanged()
           
 java.lang.String getFormula()
           
 int[] getSafeElementRange(DataSink sink)
          Returns the smallest and largest element numbers that are safe to use with this formula.
 javax.swing.JTextField getTextField(DataFormula.Listener dfl)
          This method returns a text field that can be put into a GUI to edit this formula.
static void main(java.lang.String[] args)
           
private  void parse(java.lang.String equation)
           
private  DataFormula.EquNode parseToTree(java.lang.String e)
           
 void setFormula(java.lang.String equation)
           
 double valueOf(DataSink sink, int elem)
          Returns the value of the given expression using the provided DataSink, primary element.
 double valueOf(DataSink sink, int elem, int[] specialElem)
          Returns the value of the given expression using the provided DataSink, primary element, and special element.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLUS_LEVEL

private static final int PLUS_LEVEL
See Also:
Constant Field Values

MULT_LEVEL

private static final int MULT_LEVEL
See Also:
Constant Field Values

EXP_LEVEL

private static final int EXP_LEVEL
See Also:
Constant Field Values

TERT_LEVEL

private static final int TERT_LEVEL
See Also:
Constant Field Values

NO_LEVEL

private static final int NO_LEVEL
See Also:
Constant Field Values

equ

private java.lang.String equ

root

private DataFormula.EquNode root

groupInfo

private DataFormula.GroupInformation groupInfo

inputField

private transient javax.swing.JTextField inputField

listener

private transient DataFormula.Listener listener

errorHandling

private transient boolean errorHandling

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

DataFormula

public DataFormula(java.lang.String equation)

DataFormula

private DataFormula()

DataFormula

public DataFormula(DataFormula c)
Method Detail

main

public static void main(java.lang.String[] args)

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

getFormula

public java.lang.String getFormula()

setFormula

public void setFormula(java.lang.String equation)

valueOf

public double valueOf(DataSink sink,
                      int elem)
Returns the value of the given expression using the provided DataSink, primary element. Special elements are calculated using group settings.

Throws:
java.lang.ArithmeticException - This means that it tried an undefinied operation.
NoSuchElementException - A provided subscript was out of bounds.

valueOf

public double valueOf(DataSink sink,
                      int elem,
                      int[] specialElem)
Returns the value of the given expression using the provided DataSink, primary element, and special element. The special element array can be null if none has been precalculated.

Throws:
java.lang.ArithmeticException - This means that it tried an undefinied operation.
NoSuchElementException - A provided subscript was out of bounds.

getSafeElementRange

public int[] getSafeElementRange(DataSink sink)
Returns the smallest and largest element numbers that are safe to use with this formula. This only checks the various data sources used and the offsets in them.


getTextField

public javax.swing.JTextField getTextField(DataFormula.Listener dfl)
This method returns a text field that can be put into a GUI to edit this formula. If the formula hasn't created one yet, it will create it. This field has listeners attached to it that will update the formula on action or focus loss. The provided DataFormulaListener will be notified when the formula is altered. It can be null.


parseToTree

private DataFormula.EquNode parseToTree(java.lang.String e)

parse

private void parse(java.lang.String equation)

formulaChanged

private void formulaChanged()