org.sbml.jsbml.util.compilers
public class FormulaCompiler extends StringTools implements ASTNodeCompiler
String
s that represent the
content of ASTNode
s. These can be used to save equations in SBML with
older than Level 2.DECIMAL_FORMAT, REAL_FORMAT, SCIENTIFIC_FORMAT, underscore
Constructor and Description |
---|
FormulaCompiler() |
Modifier and Type | Method and Description |
---|---|
ASTNodeValue |
abs(ASTNode node)
The absolute value represented by the given
ASTNode . |
ASTNodeValue |
and(java.util.List<ASTNode> nodes) |
ASTNodeValue |
arccos(ASTNode node) |
ASTNodeValue |
arccosh(ASTNode node) |
ASTNodeValue |
arccot(ASTNode node) |
ASTNodeValue |
arccoth(ASTNode node) |
ASTNodeValue |
arccsc(ASTNode node) |
ASTNodeValue |
arccsch(ASTNode node) |
ASTNodeValue |
arcsec(ASTNode node) |
ASTNodeValue |
arcsech(ASTNode node) |
ASTNodeValue |
arcsin(ASTNode node) |
ASTNodeValue |
arcsinh(ASTNode node) |
ASTNodeValue |
arctan(ASTNode node) |
ASTNodeValue |
arctanh(ASTNode node) |
private static java.lang.StringBuffer |
arith(char operator,
java.lang.Object... elements)
Basic method which links several elements with a mathematical operator.
|
static java.lang.StringBuffer |
brackets(java.lang.Object sb) |
ASTNodeValue |
ceiling(ASTNode node) |
protected java.lang.String |
checkBrackets(ASTNode node)
Creates brackets if needed.
|
protected java.lang.String |
checkDenominatorBrackets(ASTNode nodes)
Creates brackets if needed.
|
ASTNodeValue |
compile(CallableSBase variable) |
ASTNodeValue |
compile(Compartment c) |
ASTNodeValue |
compile(double mantissa,
int exponent,
java.lang.String units)
Creates an
ASTNodeValue that represents a real number in
scientific notation, i.e., mantissa * 10^exponent, and the given units. |
ASTNodeValue |
compile(double real,
java.lang.String units) |
ASTNodeValue |
compile(int integer,
java.lang.String units) |
ASTNodeValue |
compile(java.lang.String name)
A compiler will also have to deal with a name.
|
private static boolean |
containsArith(java.lang.Object something)
Tests whether the String representation of the given object contains any
arithmetic symbols and if the given object is already surrounded by
brackets.
|
ASTNodeValue |
cos(ASTNode node) |
ASTNodeValue |
cosh(ASTNode node) |
ASTNodeValue |
cot(ASTNode node) |
ASTNodeValue |
coth(ASTNode node) |
ASTNodeValue |
csc(ASTNode node) |
ASTNodeValue |
csch(ASTNode node) |
ASTNodeValue |
delay(java.lang.String delayName,
ASTNode x,
ASTNode y,
java.lang.String timeUnits)
Evaluates delay functions.
|
static java.lang.StringBuffer |
diff(java.lang.Object... subtrahents)
Returns the difference of the given elements as StringBuffer.
|
ASTNodeValue |
eq(ASTNode left,
ASTNode right)
Equal.
|
ASTNodeValue |
exp(ASTNode node) |
ASTNodeValue |
factorial(ASTNode node) |
ASTNodeValue |
floor(ASTNode node) |
ASTNodeValue |
frac(ASTNode numerator,
ASTNode denominator)
Fraction of two
ASTNode s |
ASTNodeValue |
frac(int numerator,
int denominator)
A fraction of two int values.
|
static java.lang.StringBuffer |
frac(java.lang.Object numerator,
java.lang.Object denominator)
Returns a fraction with the given elements as numerator and denominator.
|
ASTNodeValue |
function(FunctionDefinition func,
java.util.List<ASTNode> nodes) |
protected ASTNodeValue |
function(java.lang.String name,
ASTNode... nodes) |
ASTNodeValue |
function(java.lang.String name,
java.util.List<ASTNode> nodes) |
ASTNodeValue |
geq(ASTNode left,
ASTNode right)
Greater equal.
|
ASTNodeValue |
getConstantAvogadro(java.lang.String name)
Creates an
ASTNodeValue that represent's Avogadro's number. |
ASTNodeValue |
getConstantE() |
ASTNodeValue |
getConstantFalse() |
ASTNodeValue |
getConstantPi() |
ASTNodeValue |
getConstantTrue() |
ASTNodeValue |
getNegativeInfinity() |
ASTNodeValue |
getPositiveInfinity() |
protected static java.lang.StringBuffer |
getSpecies(SpeciesReference ref)
Returns the id of a PluginSpeciesReference object's belonging species as
an object of type StringBuffer.
|
protected static double |
getStoichiometry(SpeciesReference ref)
Returns the value of a PluginSpeciesReference object's stoichiometry
either as a double or, if the stoichiometry has an integer value, as an
int object.
|
ASTNodeValue |
gt(ASTNode left,
ASTNode right)
Greater than.
|
ASTNodeValue |
lambda(java.util.List<ASTNode> nodes)
The body of a
FunctionDefinition . |
protected java.lang.String |
lambdaBody(java.util.List<ASTNode> nodes)
Creates the body of a lambda function, i.e., the argument list and the
actual mathematical operation, all comma separated and surrounded in
brackets.
|
ASTNodeValue |
leq(ASTNode left,
ASTNode right)
Less equal.
|
ASTNodeValue |
ln(ASTNode node)
Natural logarithm.
|
ASTNodeValue |
log(ASTNode node)
Logarithm of the given value to base 10.
|
ASTNodeValue |
log(ASTNode left,
ASTNode right)
Logarithm of the given value to the given base.
|
protected ASTNodeValue |
logicalOperation(java.lang.String operator,
java.util.List<ASTNode> nodes) |
ASTNodeValue |
lt(ASTNode left,
ASTNode right)
Less than.
|
ASTNodeValue |
minus(java.util.List<ASTNode> nodes)
Subtraction.
|
ASTNodeValue |
neq(ASTNode left,
ASTNode right)
Not equal.
|
ASTNodeValue |
not(ASTNode node) |
ASTNodeValue |
or(java.util.List<ASTNode> nodes) |
ASTNodeValue |
piecewise(java.util.List<ASTNode> nodes) |
ASTNodeValue |
plus(java.util.List<ASTNode> nodes) |
ASTNodeValue |
pow(ASTNode left,
ASTNode right) |
static java.lang.StringBuffer |
pow(java.lang.Object basis,
java.lang.Object exponent)
Returns the basis to the power of the exponent as StringBuffer.
|
protected java.lang.String |
relation(ASTNode left,
java.lang.String symbol,
ASTNode right) |
ASTNodeValue |
root(ASTNode rootExponent,
ASTNode radiant) |
ASTNodeValue |
root(double rootExponent,
ASTNode radiant) |
static java.lang.StringBuffer |
root(java.lang.Object exponent,
java.lang.Object basis)
Returns the exponent-th root of the basis as StringBuffer.
|
ASTNodeValue |
sec(ASTNode node) |
ASTNodeValue |
sech(ASTNode node) |
ASTNodeValue |
selector(java.util.List<ASTNode> nodes) |
protected static java.lang.StringBuffer |
selector(java.lang.Object... elements)
Returns the given selector as StringBuffer.
|
ASTNodeValue |
sin(ASTNode node) |
ASTNodeValue |
sinh(ASTNode node) |
ASTNodeValue |
sqrt(ASTNode node)
Square root.
|
static java.lang.StringBuffer |
sqrt(java.lang.Object basis) |
static java.lang.StringBuffer |
sum(java.lang.Object... summands)
Returns the sum of the given elements as StringBuffer.
|
ASTNodeValue |
symbolTime(java.lang.String time)
The simulation time.
|
ASTNodeValue |
tan(ASTNode node) |
ASTNodeValue |
tanh(ASTNode node) |
ASTNodeValue |
times(java.util.List<ASTNode> nodes)
Product of all given
ASTNode s. |
static java.lang.StringBuffer |
times(java.lang.Object... factors)
Returns the product of the given elements as StringBuffer.
|
ASTNodeValue |
uMinus(ASTNode node)
Unary minus, i.e., negation of the given
ASTNode . |
ASTNodeValue |
unknownValue()
Dealing with a malformed
ASTNode . |
ASTNodeValue |
vector(java.util.List<ASTNode> nodes)
Dealing with a vector.
|
protected static java.lang.StringBuffer |
vector(java.lang.Object... elements)
Returns the given vector as StringBuffer.
|
ASTNodeValue |
xor(java.util.List<ASTNode> nodes)
Exclusive or.
|
append, append, concat, concatStringBuilder, encodeForHTML, fill, fill, firstLetterLowerCase, firstLetterUpperCase, getWordForNumber, leadingZeros, newLine, parseSBMLBoolean, parseSBMLDouble, parseSBMLInt, parseSBMLShort, toHTML, toHTML, toString, toString, toXMLAnnotationString, toXMLMessageString, toXMLNotesString
private static final java.lang.StringBuffer arith(char operator, java.lang.Object... elements)
operator
- elements
- public static final java.lang.StringBuffer brackets(java.lang.Object sb)
sb
- private static boolean containsArith(java.lang.Object something)
something
- public static final java.lang.StringBuffer diff(java.lang.Object... subtrahents)
subtrahents
- public static final java.lang.StringBuffer frac(java.lang.Object numerator, java.lang.Object denominator)
numerator
- denominator
- protected static final java.lang.StringBuffer getSpecies(SpeciesReference ref)
ref
- protected static final double getStoichiometry(SpeciesReference ref)
ref
- public static final java.lang.StringBuffer pow(java.lang.Object basis, java.lang.Object exponent)
basis
- exponent
- public static final java.lang.StringBuffer root(java.lang.Object exponent, java.lang.Object basis) throws java.lang.NumberFormatException
exponent
- basis
- java.util.IllegalFormatException
- If the given exponent represents a zero.java.lang.NumberFormatException
protected static final java.lang.StringBuffer selector(java.lang.Object... elements)
operator
- elements
- public static final java.lang.StringBuffer sqrt(java.lang.Object basis)
basis
- public static final java.lang.StringBuffer sum(java.lang.Object... summands)
summands
- public static final java.lang.StringBuffer times(java.lang.Object... factors)
factors
- protected static final java.lang.StringBuffer vector(java.lang.Object... elements)
operator
- elements
- public ASTNodeValue abs(ASTNode node) throws SBMLException
ASTNodeCompiler
ASTNode
.abs
in interface ASTNodeCompiler
node
- Must be interpretable as a Number
.SBMLException
public ASTNodeValue and(java.util.List<ASTNode> nodes) throws SBMLException
and
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arccos(ASTNode node) throws SBMLException
arccos
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arccosh(ASTNode node) throws SBMLException
arccosh
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arccot(ASTNode node) throws SBMLException
arccot
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arccoth(ASTNode node) throws SBMLException
arccoth
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arccsc(ASTNode node) throws SBMLException
arccsc
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arccsch(ASTNode node) throws SBMLException
arccsch
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arcsec(ASTNode node) throws SBMLException
arcsec
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arcsech(ASTNode node) throws SBMLException
arcsech
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arcsin(ASTNode node) throws SBMLException
arcsin
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arcsinh(ASTNode node) throws SBMLException
arcsinh
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arctan(ASTNode node) throws SBMLException
arctan
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue arctanh(ASTNode node) throws SBMLException
arctanh
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue ceiling(ASTNode node) throws SBMLException
ceiling
in interface ASTNodeCompiler
SBMLException
protected java.lang.String checkBrackets(ASTNode node) throws SBMLException
node
- SBMLException
protected java.lang.String checkDenominatorBrackets(ASTNode nodes) throws SBMLException
nodes
- SBMLException
public ASTNodeValue compile(Compartment c)
compile
in interface ASTNodeCompiler
public ASTNodeValue compile(double mantissa, int exponent, java.lang.String units)
ASTNodeCompiler
ASTNodeValue
that represents a real number in
scientific notation, i.e., mantissa * 10^exponent, and the given units.compile
in interface ASTNodeCompiler
mantissa
- The number to be multiplied with ten to the power of the given
exponent.exponent
- The exponent for the multiplier ten.units
- The identifier of the units object associated with the number
represented by this element. Can be null if no units have been
defined.public ASTNodeValue compile(double real, java.lang.String units)
compile
in interface ASTNodeCompiler
units
- A String representing the Unit
of the given number.
This can be the identifier of a UnitDefinition
in the
model or a literal in Unit.Kind
. Can be null if no units
have been defined.public ASTNodeValue compile(int integer, java.lang.String units)
compile
in interface ASTNodeCompiler
units
- A String representing the Unit
of the given number.
This can be the identifier of a UnitDefinition
in the
model or a literal in Unit.Kind
. Can be null if no units
have been defined.public ASTNodeValue compile(CallableSBase variable)
compile
in interface ASTNodeCompiler
public ASTNodeValue compile(java.lang.String name)
ASTNodeCompiler
Species
in the
system. In case of numerical computation, the ASTNodeCompiler
must create an ASTNodeValue
representing the current value of
this Species
.compile
in interface ASTNodeCompiler
public ASTNodeValue cos(ASTNode node) throws SBMLException
cos
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue cosh(ASTNode node) throws SBMLException
cosh
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue cot(ASTNode node) throws SBMLException
cot
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue coth(ASTNode node) throws SBMLException
coth
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue csc(ASTNode node) throws SBMLException
csc
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue csch(ASTNode node) throws SBMLException
csch
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue delay(java.lang.String delayName, ASTNode x, ASTNode y, java.lang.String timeUnits) throws SBMLException
ASTNodeCompiler
delay
in interface ASTNodeCompiler
delayName
- the name of this delay function.y
- an expression of a positive duration time (the amoutn of
delay)timeUnits
- the units for the delay.SBMLException
public ASTNodeValue eq(ASTNode left, ASTNode right) throws SBMLException
ASTNodeCompiler
eq
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue exp(ASTNode node) throws SBMLException
exp
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue factorial(ASTNode node)
factorial
in interface ASTNodeCompiler
public ASTNodeValue floor(ASTNode node) throws SBMLException
floor
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue frac(ASTNode numerator, ASTNode denominator) throws SBMLException
ASTNodeCompiler
ASTNode
sfrac
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue frac(int numerator, int denominator)
ASTNodeCompiler
frac
in interface ASTNodeCompiler
public ASTNodeValue function(FunctionDefinition func, java.util.List<ASTNode> nodes) throws SBMLException
function
in interface ASTNodeCompiler
nodes
- Values to be inserted into the parameter list of the
function.SBMLException
protected ASTNodeValue function(java.lang.String name, ASTNode... nodes) throws SBMLException
name
- nodes
- SBMLException
public ASTNodeValue function(java.lang.String name, java.util.List<ASTNode> nodes) throws SBMLException
function
in interface ASTNodeCompiler
name
- nodes
- SBMLException
public ASTNodeValue geq(ASTNode left, ASTNode right) throws SBMLException
ASTNodeCompiler
geq
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue getConstantAvogadro(java.lang.String name)
ASTNodeCompiler
ASTNodeValue
that represent's Avogadro's number.
Optionally, the compiler may associate the given name with this number.getConstantAvogadro
in interface ASTNodeCompiler
name
- An optional name for Avogadro's number.public ASTNodeValue getConstantE()
getConstantE
in interface ASTNodeCompiler
public ASTNodeValue getConstantFalse()
getConstantFalse
in interface ASTNodeCompiler
public ASTNodeValue getConstantPi()
getConstantPi
in interface ASTNodeCompiler
public ASTNodeValue getConstantTrue()
getConstantTrue
in interface ASTNodeCompiler
public ASTNodeValue getNegativeInfinity()
getNegativeInfinity
in interface ASTNodeCompiler
public ASTNodeValue getPositiveInfinity()
getPositiveInfinity
in interface ASTNodeCompiler
public ASTNodeValue gt(ASTNode left, ASTNode right) throws SBMLException
ASTNodeCompiler
gt
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue lambda(java.util.List<ASTNode> nodes) throws SBMLException
ASTNodeCompiler
FunctionDefinition
.lambda
in interface ASTNodeCompiler
nodes
- Place holders for arguments.SBMLException
protected java.lang.String lambdaBody(java.util.List<ASTNode> nodes) throws SBMLException
nodes
- SBMLException
public ASTNodeValue leq(ASTNode left, ASTNode right) throws SBMLException
ASTNodeCompiler
leq
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue ln(ASTNode node) throws SBMLException
ASTNodeCompiler
ln
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue log(ASTNode node) throws SBMLException
ASTNodeCompiler
log
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue log(ASTNode left, ASTNode right) throws SBMLException
ASTNodeCompiler
log
in interface ASTNodeCompiler
SBMLException
protected ASTNodeValue logicalOperation(java.lang.String operator, java.util.List<ASTNode> nodes) throws SBMLException
operator
- nodes
- SBMLException
public ASTNodeValue lt(ASTNode left, ASTNode right) throws SBMLException
ASTNodeCompiler
lt
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue minus(java.util.List<ASTNode> nodes) throws SBMLException
ASTNodeCompiler
minus
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue neq(ASTNode left, ASTNode right) throws SBMLException
ASTNodeCompiler
neq
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue not(ASTNode node) throws SBMLException
not
in interface ASTNodeCompiler
node
- This value must be interpretable as a Boolean
.SBMLException
public ASTNodeValue or(java.util.List<ASTNode> nodes) throws SBMLException
or
in interface ASTNodeCompiler
nodes
- These values must be interpretable as a Boolean
.SBMLException
public ASTNodeValue piecewise(java.util.List<ASTNode> nodes) throws SBMLException
piecewise
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue plus(java.util.List<ASTNode> nodes) throws SBMLException
plus
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue pow(ASTNode left, ASTNode right) throws SBMLException
pow
in interface ASTNodeCompiler
SBMLException
protected java.lang.String relation(ASTNode left, java.lang.String symbol, ASTNode right) throws SBMLException
left
- symbol
- right
- SBMLException
public ASTNodeValue root(ASTNode rootExponent, ASTNode radiant) throws SBMLException
root
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue root(double rootExponent, ASTNode radiant) throws SBMLException
root
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue sec(ASTNode node) throws SBMLException
sec
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue sech(ASTNode node) throws SBMLException
sech
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue sin(ASTNode node) throws SBMLException
sin
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue sinh(ASTNode node) throws SBMLException
sinh
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue sqrt(ASTNode node) throws SBMLException
ASTNodeCompiler
sqrt
in interface ASTNodeCompiler
node
- This value must be interpretable as a Number
.SBMLException
public ASTNodeValue symbolTime(java.lang.String time)
ASTNodeCompiler
symbolTime
in interface ASTNodeCompiler
time
- The name of the time symbol.ASTNodeValue
that represents the current time.public ASTNodeValue tan(ASTNode node) throws SBMLException
tan
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue tanh(ASTNode node) throws SBMLException
tanh
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue times(java.util.List<ASTNode> nodes) throws SBMLException
ASTNodeCompiler
ASTNode
s.times
in interface ASTNodeCompiler
nodes
- These values must be interpretable to Number
.SBMLException
public ASTNodeValue uMinus(ASTNode node) throws SBMLException
ASTNodeCompiler
ASTNode
.uMinus
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue unknownValue() throws SBMLException
ASTNodeCompiler
ASTNode
.unknownValue
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue xor(java.util.List<ASTNode> nodes) throws SBMLException
ASTNodeCompiler
xor
in interface ASTNodeCompiler
nodes
- It must be possible to evaluate the given values to
Boolean
.SBMLException
public ASTNodeValue selector(java.util.List<ASTNode> nodes) throws SBMLException
selector
in interface ASTNodeCompiler
SBMLException
public ASTNodeValue vector(java.util.List<ASTNode> nodes) throws SBMLException
ASTNodeCompiler
vector
in interface ASTNodeCompiler
SBMLException