|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.swri.swiftvis.DataFormula
public class DataFormula
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.
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 |
---|
private static final int PLUS_LEVEL
private static final int MULT_LEVEL
private static final int EXP_LEVEL
private static final int TERT_LEVEL
private static final int NO_LEVEL
private java.lang.String equ
private DataFormula.EquNode root
private DataFormula.GroupInformation groupInfo
private transient javax.swing.JTextField inputField
private transient DataFormula.Listener listener
private transient boolean errorHandling
private static final long serialVersionUID
Constructor Detail |
---|
public DataFormula(java.lang.String equation)
private DataFormula()
public DataFormula(DataFormula c)
Method Detail |
---|
public static void main(java.lang.String[] args)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String getFormula()
public void setFormula(java.lang.String equation)
public double valueOf(DataSink sink, int elem)
java.lang.ArithmeticException
- This means that it tried an undefinied operation.
NoSuchElementException
- A provided subscript was out of bounds.public double valueOf(DataSink sink, int elem, int[] specialElem)
java.lang.ArithmeticException
- This means that it tried an undefinied operation.
NoSuchElementException
- A provided subscript was out of bounds.public int[] getSafeElementRange(DataSink sink)
public javax.swing.JTextField getTextField(DataFormula.Listener dfl)
private DataFormula.EquNode parseToTree(java.lang.String e)
private void parse(java.lang.String equation)
private void formulaChanged()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |