org.sbml.jsbml
public class ASTNode extends AbstractTreeNode
Modifier and Type | Class and Description |
---|---|
static class |
ASTNode.Type
An enumeration of all possible types that can be represented by an
abstract syntax tree node.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
className
Possible attributes for a MathML element
|
private java.lang.String |
definitionURL
The value of the definitionURL for csymbol element.
|
private int |
denominator |
private java.lang.String |
encoding
Possible attributes for a MathML element
|
private int |
exponent |
private java.lang.String |
id
Possible attributes for a MathML element
|
static java.lang.String |
INVALID_OPERATOR_MSG
Message to indicate that an
ASTNode.Type type has been chosen
which cannot be used as an operator. |
private boolean |
isSetNumberType
Tells if the type attribute of the cn element was set and we need to
write it back or if it is set to the default (REAL).
|
private java.util.List<ASTNode> |
listOfNodes
Child nodes.
|
private static org.apache.log4j.Logger |
logger
A
Logger for this class. |
private double |
mantissa
The part of a number in scientific format (with an E) that is on the left
side of the E (the prefix of the number).
|
private java.lang.String |
name
If no NamedSBase object exists or can be identified when
setName(String) is called, the given name is stored in this
field. |
private int |
numerator
This value stores the numerator if this.isRational() is
true , or the
value of an integer if this.isInteger() is true . |
private MathContainer |
parentSBMLObject
The container that holds this ASTNode.
|
private static long |
serialVersionUID
Generated serial version identifier.
|
private java.lang.String |
style
Possible attributes for a MathML element
|
private ASTNode.Type |
type
The type of this ASTNode.
|
private java.lang.String |
unitId
Since Level 3 SBML allows to equip numbers with unit identifiers.
|
static java.lang.String |
URI_AVOGADRO_DEFINITION
The URI for the definition of the csymbol for avogadro.
|
static java.lang.String |
URI_DELAY_DEFINITION
The URI for the definition of the csymbol for delay.
|
static java.lang.String |
URI_MATHML_DEFINITION
URI for the definition of MathML.
|
static java.lang.String |
URI_MATHML_PREFIX
URI prefix for the definition of MathML, it will be used to write the sbml file
|
static java.lang.String |
URI_TIME_DEFINITION
The URI for the definition of the csymbol for time.
|
private CallableSBase |
variable
A direct pointer to a referenced variable.
|
listOfListeners, parent, UNKNOWN_ATTRIBUTES, UNKNOWN_ELEMENTS
Constructor and Description |
---|
ASTNode()
Creates a new
ASTNode of unspecified type and without a pointer
to its containing MathContainer . |
ASTNode(ASTNode.Type type)
|
ASTNode(ASTNode.Type type,
MathContainer parent)
Creates and returns a new
ASTNode . |
ASTNode(ASTNode astNode)
Copy constructor; Creates a deep copy of the given
ASTNode . |
ASTNode(CallableSBase nsb)
Creates and returns a new
ASTNode referring to the given CallableSBase . |
ASTNode(CallableSBase nsb,
MathContainer parent)
Creates and returns a new
ASTNode referring to the given CallableSBase . |
ASTNode(char operator)
Creates a new
ASTNode representing an operator, i.e., an internal
node. |
ASTNode(char operator,
MathContainer parent)
Creates a new
ASTNode representing an operator, i.e., an internal
node. |
ASTNode(double real)
Creates and returns a new
ASTNode . |
ASTNode(double mantissa,
int exponent)
Creates and returns a new
ASTNode . |
ASTNode(double mantissa,
int exponent,
MathContainer parent)
Creates and returns a new
ASTNode . |
ASTNode(double real,
MathContainer parent)
Creates and returns a new
ASTNode . |
ASTNode(int integer)
Creates and returns a new
ASTNode with the given integer value. |
ASTNode(int integer,
MathContainer parent)
Creates and returns a new
ASTNode with the given integer value for
the
given MathContainer as its parent SBML object. |
ASTNode(int integer,
java.lang.String unitsID,
MathContainer parent)
Creates and returns a new
ASTNode with the given integer value with
the given associated unitId for the
given MathContainer as its parent SBML object. |
ASTNode(MathContainer parent)
Creates and returns a new
ASTNode . |
ASTNode(java.lang.String name)
Creates and returns a new
ASTNode with the given name. |
ASTNode(java.lang.String name,
MathContainer parent)
Creates and returns a new
ASTNode with the given name. |
Modifier and Type | Method and Description |
---|---|
static ASTNode |
abs(double d,
MathContainer parent)
Creates and returns an
ASTNode that computes the absolute value
of the given double value. |
static ASTNode |
abs(int integer,
MathContainer parent)
Creates and returns an
ASTNode that computes the absolute value
of the given integer value. |
void |
addChild(ASTNode child)
Adds a child to this node.
|
private static ASTNode |
arithmethicOperation(ASTNode.Type operator,
ASTNode... ast)
Creates a new
ASTNode of type operator and adds the given nodes as children. |
private void |
arithmeticOperation(ASTNode.Type operator,
ASTNode astnode)
Creates a new node with the type of this node, moves all children of this
node to this new node, sets the type of this node to the given operator,
adds the new node as left child of this node and the given
ASTNode as the
right child of this node. |
ASTNode |
clone() |
ASTNodeValue |
compile(ASTNodeCompiler compiler)
Compiles this
ASTNode and returns the result. |
boolean |
containsUndeclaredUnits()
Returns
true or false depending on whether this
ASTNode refers to elements such as parameters or numbers with
undeclared units. |
UnitDefinition |
deriveUnit()
Evaluates recursively this ASTNode and creates a new UnitDefinition with
respect of all referenced elements.
|
static ASTNode |
diff(ASTNode... ast)
Creates a new
ASTNode of type MINUS and adds the given nodes as children |
ASTNode |
divideBy(ASTNode ast)
Divides this node by the given node
|
ASTNode |
divideBy(CallableSBase namedSBase)
Divides this node by the given SBML element.
|
static ASTNode |
eq(ASTNode left,
ASTNode right)
Creates a new
ASTNode of type RELATIONAL_EQ. |
boolean |
equals(java.lang.Object object) |
static ASTNode |
exp(ASTNode exponent)
Returns a new
ASTNode that represents Euler's constant raised by the
power of the given exponent. |
java.util.List<Parameter> |
findReferencedGlobalParameters()
Goes through the formula and identifies all global parameters that are
referenced by this rate equation.
|
static java.lang.String |
formulaToString(ASTNode tree)
Returns the formula from the given ASTNode as an SBML Level 1 text-string
mathematical formula.
|
static ASTNode |
frac(ASTNode numerator,
ASTNode denominator)
Creates a new
ASTNode of type DIVIDE with the given nodes as children. |
static ASTNode |
frac(int numerator,
ASTNode denominator)
Creates a new
ASTNode that of type DIVIDE with the given numerator and
denominator. |
static ASTNode |
frac(MathContainer container,
CallableSBase numerator,
CallableSBase denominator)
Creates a new
ASTNode that divides two CallableSBase objects. |
static ASTNode |
frac(MathContainer container,
java.lang.String numeratorId,
java.lang.String denominatorId)
Returns a new
ASTNode that of type DIVIDE with the two entities as numerator and denominator. |
static ASTNode |
geq(ASTNode left,
ASTNode right)
Creates an
ASTNode representing greater or equal for
the two given nodes. |
boolean |
getAllowsChildren() |
char |
getCharacter()
Gets the value of this node as a single character.
|
ASTNode |
getChild(int index)
Gets a child of this node according to an index number.
|
javax.swing.tree.TreeNode |
getChildAt(int i) |
int |
getChildCount() |
java.util.List<ASTNode> |
getChildren()
Returns the list of children of the current ASTNode.
|
java.lang.String |
getClassName()
Returns the class name of the mathML element represented by this ASTNode.
|
java.lang.String |
getDefinitionURL()
Returns the definitionURL
|
int |
getDenominator()
Gets the value of the denominator of this node.
|
java.lang.String |
getEncoding()
Returns the encoding of the mathML element represented by this ASTNode.
|
int |
getExponent()
Gets the exponent value of this ASTNode.
|
java.lang.String |
getId()
Returns the id of the mathML element represented by this ASTNode.
|
int |
getInteger()
Gets the value of this node as an integer.
|
ASTNode |
getLeftChild()
Gets the left child of this node.
|
java.util.List<ASTNode> |
getListOfNodes()
Returns the list of children of the current ASTNode.
|
java.util.List<ASTNode> |
getListOfNodes(Filter filter)
Returns the list of children of the current ASTNode that satisfy the
given filter.
|
double |
getMantissa()
Gets the mantissa value of this node.
|
java.lang.String |
getName()
Gets the name of this node.
|
int |
getNumerator()
Gets the value of the numerator of this node.
|
javax.swing.tree.TreeNode |
getParent() |
MathContainer |
getParentSBMLObject()
This method is convenient when holding an object nested inside other
objects in an SBML model.
|
double |
getReal()
Gets the real-numbered value of this node.
|
java.util.Set<NamedSBase> |
getReferencedNamedSBases()
Returns a set of all the
NamedSBase referenced on this node and
all his descendant. |
ASTNode |
getRightChild()
Returns the last child in the list of children of this node.
|
java.lang.String |
getStyle()
Returns the style of the mathML element represented by this ASTNode.
|
ASTNode.Type |
getType()
Returns the type of this node.
|
java.lang.String |
getUnits()
Returns the units attribute.
|
UnitDefinition |
getUnitsInstance()
Creates or obtains a
UnitDefinition corresponding to the unit
that has been set for this ASTNode and returns a pointer to it. |
CallableSBase |
getVariable()
Returns the variable of this node.
|
static ASTNode |
gt(ASTNode left,
ASTNode right)
Creates an
ASTNode representing greater than for
the two given left and right child. |
int |
hashCode() |
boolean |
hasUnits()
Returns
true if the current ASTNode or any of his descendant has a unit
defined. |
private void |
initDefaults()
Initializes the default values/attributes of the node.
|
void |
insertChild(int n,
ASTNode newChild)
|
boolean |
isBoolean()
Returns
true if this node has a boolean type (a logical operator, a
relational operator, or the constants true or false ). |
boolean |
isConstant()
Returns
true if this node represents a MathML constant (e.g., true , Pi). |
boolean |
isDifference()
Checks if this
ASTNode represents a difference. |
boolean |
isFunction()
Returns
true if this node represents a function. |
boolean |
isInfinity()
Returns
true if this node represents the special IEEE 754 value infinity,
false otherwise. |
boolean |
isInteger()
Returns
true if this node contains an integer value, false otherwise. |
boolean |
isLambda()
Returns
true if this node is a MathML <lambda>, false otherwise. |
boolean |
isLog10()
Returns
true if this node represents a log10() function, false otherwise. |
boolean |
isLogical()
Returns
true if this node is a MathML logical operator (i.e., and, or,
not, xor). |
boolean |
isMinusOne()
Returns
true if this astnode represents the number minus one (either as
integer or as real value). |
boolean |
isName()
Returns
true if this node is a user-defined Variable name in SBML L1, L2
(MathML), or the special symbols delay or time. |
boolean |
isNaN()
Returns
true if this node is a type Real and represents the special IEEE
754 value 'not a number' Double.NaN , false otherwise. |
boolean |
isNegInfinity()
Returns
true if this node represents the special IEEE 754 value 'negative
infinity' Double.NEGATIVE_INFINITY , false otherwise. |
boolean |
isNumber()
Returns
true if this node contains a number, false otherwise. |
boolean |
isOne()
Returns
true if this ASTNode represents the number one (either as
integer or as real value). |
boolean |
isOperator()
Returns
true if this node is a mathematical operator, meaning, +, -, *, /
or ^ (power). |
boolean |
isPiecewise()
Returns
true if this node is the MathML <piecewise> construct,
false otherwise. |
boolean |
isRational()
Returns
true if this node represents a rational number, false otherwise. |
boolean |
isReal()
Returns
true if this node can represent a real number, false otherwise. |
boolean |
isRelational()
Returns
true if this node is a MathML relational operator, meaning ==,
>=, >, <, and !=. |
boolean |
isSetClassName() |
boolean |
isSetDefinitionURL() |
boolean |
isSetEncoding() |
boolean |
isSetId() |
boolean |
isSetName() |
boolean |
isSetNumberType()
Returns
true if the number type is set. |
boolean |
isSetParentSBMLObject()
Checks if a parent SBML object, i.e., a
MathContainer , is set as a
parent SBML object for this ASTNode . |
boolean |
isSetStyle() |
boolean |
isSetUnits()
Returns
true if a unit is defined on this node. |
boolean |
isSqrt()
Returns
true if this node represents a square root function, false
otherwise. |
boolean |
isString()
Returns
true if this node is a name or refers to a
FunctionDefinition . |
boolean |
isSum()
Checks if this
ASTNode represents a sum. |
boolean |
isUMinus()
Returns
true if this node is a unary minus operator, false otherwise. |
boolean |
isUnary()
Checks whether the number of child nodes is exactly one.
|
boolean |
isUnknown()
Returns
true if this node has an ASTNode.Type.UNKNOWN type. |
boolean |
isVariable()
Returns
true if this node represents a Variable . |
boolean |
isZero()
Returns
true if this node represents the number zero (either as integer
or as real value). |
static ASTNode |
leq(ASTNode left,
ASTNode right)
Creates an
ASTNode representing less or equal for
the two given left and right child. |
static ASTNode |
log(ASTNode value)
Creates an
ASTNode representing a logarithm to base 10 of the given value. |
static ASTNode |
log(ASTNode base,
ASTNode value)
Creates an
ASTNode that represents the logarithm function with
the given base and value. |
static ASTNode |
lt(ASTNode left,
ASTNode right)
|
static ASTNode |
lt(java.lang.String variable,
ASTNode node)
|
ASTNode |
minus(ASTNode ast)
Subtracts the given ASTNode from this node.
|
ASTNode |
minus(double real)
Subtracts the given number from this node.
|
ASTNode |
minus(int integer)
Subtracts the given integer from this node.
|
ASTNode |
minus(int integer,
java.lang.String unitsID) |
ASTNode |
multiplyWith(ASTNode... nodes)
Multiplies this
ASTNode with the given nodes, i.e., all given nodes
will be children of this node, whose type will be set to ASTNode.Type.TIMES . |
ASTNode |
multiplyWith(ASTNode ast)
Multiplies this
ASTNode with the given node |
ASTNode |
multiplyWith(CallableSBase nsb)
Multiplies this
ASTNode with the given SBML element. |
static ASTNode |
neq(ASTNode left,
ASTNode right)
|
static ASTNode |
parseFormula(java.lang.String formula)
Parses a text-string mathematical formula and returns a representation as
an Abstract Syntax Tree.
|
static ASTNode |
parseFormula(java.lang.String formula,
IFormulaParser parser)
Parses a text-string mathematical formula and returns a representation as
an Abstract Syntax Tree.
|
static ASTNode |
piecewise(ASTNode node,
ASTNode... nodes)
Creates a piecewise
ASTNode . |
ASTNode |
plus(ASTNode ast)
Adds a given node to this node.
|
ASTNode |
plus(CallableSBase nsb)
Adds an SBML element to this node.
|
ASTNode |
plus(double real)
Adds a number to this node.
|
ASTNode |
plus(int integer)
Adds an integer number to this node.
|
static ASTNode |
pow(ASTNode basis,
ASTNode exponent)
Creates a power
ASTNode . |
static ASTNode |
pow(ASTNode basis,
double exponent)
Creates a power
ASTNode . |
static ASTNode |
pow(ASTNode basis,
int exponent)
Creates a power
ASTNode . |
static ASTNode |
pow(MathContainer container,
CallableSBase basis,
CallableSBase exponent)
Raises the given basis by the power of the given exponent.
|
void |
prependChild(ASTNode child)
Adds the given node as a child of this ASTNode.
|
ASTNode |
raiseByThePowerOf(ASTNode exponent)
Raises this ASTNode by the power of the value of the given node.
|
ASTNode |
raiseByThePowerOf(CallableSBase nsb)
Raises this ASTNode by the power of the value of this named SBase object.
|
ASTNode |
raiseByThePowerOf(double exponent)
Raises this
ASTNode by the power of the given number. |
static ASTNode |
readMathMLFromString(java.lang.String xml)
Reads the MathML from the given XML string.
|
private void |
reduceToBinary()
|
boolean |
refersTo(java.lang.String id)
Returns
true if this node or one of its descendants contains some
identifier with the given id. |
private static ASTNode |
relational(ASTNode.Type type,
ASTNode left,
ASTNode right)
Creates a relational
ASTNode of the given type with the two given
children left and right. |
boolean |
removeChild(int n)
Removes child n of this ASTNode.
|
void |
replaceArgument(java.lang.String bvar,
ASTNode arg)
Replaces occurrences of a name within this ASTNode with the
name/value/formula represented by the second argument ASTNode, e.g., if
the formula in this ASTNode is x + y; bvar is x and arg is an ASTNode
representing the real value 3 ReplaceArgument substitutes 3 for x within
this ASTNode.
|
ASTNode |
replaceChild(int n,
ASTNode newChild)
Replaces the nth child of this ASTNode with the given ASTNode.
|
private void |
resetParentSBMLObject(ASTNode node)
Resets the parentSBMLObject to null recursively.
|
static ASTNode |
root(ASTNode rootExponent,
ASTNode radicand)
Creates a root
ASTNode . |
void |
setCharacter(char value)
Sets the value of this ASTNode to the given character.
|
void |
setClassName(java.lang.String className)
Sets the class name of the mathML element represented by this ASTNode.
|
void |
setDefinitionURL(java.lang.String definitionURL) |
void |
setEncoding(java.lang.String encoding)
Sets the encoding of the mathML element represented by this ASTNode.
|
void |
setId(java.lang.String id)
Sets the id of the mathML element represented by this ASTNode.
|
void |
setIsSetNumberType(boolean isSetNumberType) |
void |
setName(java.lang.String name)
Sets the value of this
ASTNode to the given name. |
(package private) static void |
setParentSBMLObject(ASTNode node,
MathContainer parent)
Sets the Parent of the node and its children to the given value
|
private static void |
setParentSBMLObject(ASTNode node,
MathContainer parent,
int depth)
Sets the parent of the node and its children to the given value
|
void |
setStyle(java.lang.String style)
Sets the style of the mathML element represented by this
ASTNode . |
void |
setType(ASTNode.Type type)
Sets the type of this ASTNode to the given Type.
|
void |
setType(java.lang.String typeStr)
Sets the type from a String.
|
void |
setUnits(java.lang.String unitId)
Sets the units attribute.
|
void |
setUnits(Unit.Kind unit) |
void |
setUnits(UnitDefinition ud) |
void |
setValue(double value)
Sets the value of this ASTNode to the given double number and sets the
node type to REAL.
|
void |
setValue(double mantissa,
int exponent)
Sets the value of this ASTNode to the given real (double) in two parts:
the mantissa and the exponent.
|
void |
setValue(int value)
Sets the value of this ASTNode to the given (long) integer and sets the
node type to INTEGER.
|
void |
setValue(int numerator,
int denominator)
Sets the value of this ASTNode to the given rational in two parts: the
numerator and denominator.
|
void |
setVariable(CallableSBase variable)
Allows you to directly set an instance of
CallableSBase as the
variable of this ASTNode . |
ASTNode |
sqrt()
Applies the square root function on this syntax tree and returns the
resulting tree.
|
static ASTNode |
sqrt(ASTNode radicand)
Creates a root
ASTNode . |
static ASTNode |
sum(ASTNode... ast)
Creates a new
ASTNode of type Plus with the given nodes as children. |
static ASTNode |
sum(MathContainer parent,
CallableSBase... sbase)
Sum of several NamedSBase objects.
|
void |
swapChildren(ASTNode that)
|
static ASTNode |
times(ASTNode... ast)
Creates an
ASTNode of type times and adds the given nodes as children. |
static ASTNode |
times(MathContainer parent,
CallableSBase... sbase)
Multiplies several
CallableSBase objects. |
java.lang.String |
toFormula()
Converts this ASTNode to a text string using a specific syntax for
mathematical formulas.
|
java.lang.String |
toLaTeX()
Converts this node recursively into a LaTeX formatted String.
|
java.lang.String |
toMathML()
Converts this node recursively into a MathML string that corresponds to
the subset of MathML defined in the SBML specification.
|
java.lang.String |
toString() |
static ASTNode |
uMinus(ASTNode ast)
Creates a new
ASTNode that has exactly one child and which is of type
minus, i.e., this negates what is encoded in ast. |
static ASTNode |
uMinus(MathContainer container,
CallableSBase sbase)
Creates a new
ASTNode that has exactly one child and which is of type
minus, i.e., this negates what is encoded in ast. |
void |
unsetUnits()
Unset the units attribute.
|
void |
updateVariables()
For a better performance
ASTNode s can store a direct pointer to a
variable element. |
addAllChangeListeners, addTreeNodeChangeListener, addTreeNodeChangeListener, children, clearUserObjects, containsUserObjectKey, filter, filter, filter, fireNodeAddedEvent, fireNodeRemovedEvent, firePropertyChange, getIndex, getListOfTreeNodeChangeListeners, getNumChildren, getRoot, getTreeNodeChangeListenerCount, getUserObject, indexOf, isLeaf, isRoot, isSetParent, isSetUserObjects, notifyChildChange, putUserObject, removeAllTreeNodeChangeListeners, removeFromParent, removeTreeNodeChangeListener, removeTreeNodeChangeListener, removeUserObject, setParent, userObjectKeySet
public static final transient java.lang.String INVALID_OPERATOR_MSG
ASTNode.Type
type has been chosen
which cannot be used as an operator.private static final long serialVersionUID
public static final transient java.lang.String URI_AVOGADRO_DEFINITION
public static final transient java.lang.String URI_DELAY_DEFINITION
public static final transient java.lang.String URI_MATHML_DEFINITION
public static final java.lang.String URI_MATHML_PREFIX
public static final transient java.lang.String URI_TIME_DEFINITION
private java.lang.String definitionURL
private int denominator
private int exponent
private java.lang.String id
private java.lang.String style
private java.lang.String className
private java.lang.String encoding
private boolean isSetNumberType
private java.util.List<ASTNode> listOfNodes
private static final transient org.apache.log4j.Logger logger
Logger
for this class.private double mantissa
private java.lang.String name
setName(String)
is called, the given name is stored in this
field.private int numerator
true
, or the
value of an integer if this.isInteger() is true
.private MathContainer parentSBMLObject
private ASTNode.Type type
private java.lang.String unitId
UnitDefinition
in the
model can be stored here.private CallableSBase variable
public ASTNode()
ASTNode
of unspecified type and without a pointer
to its containing MathContainer
.public ASTNode(ASTNode astNode)
ASTNode
.astNode
- the ASTNode
to be copied.public ASTNode(CallableSBase nsb)
ASTNode
referring to the given CallableSBase
.nsb
- public ASTNode(CallableSBase nsb, MathContainer parent)
ASTNode
referring to the given CallableSBase
.nsb
- parent
- public ASTNode(char operator)
ASTNode
representing an operator, i.e., an internal
node.operator
- public ASTNode(char operator, MathContainer parent)
ASTNode
representing an operator, i.e., an internal
node.operator
- parent
- public ASTNode(double real)
ASTNode
.real
- public ASTNode(double mantissa, int exponent)
ASTNode
.mantissa
- exponent
- public ASTNode(double mantissa, int exponent, MathContainer parent)
ASTNode
.mantissa
- exponent
- parent
- public ASTNode(double real, MathContainer parent)
ASTNode
.real
- parent
- public ASTNode(int integer)
ASTNode
with the given integer value.integer
- public ASTNode(int integer, MathContainer parent)
ASTNode
with the given integer value for
the
given MathContainer
as its parent SBML object.integer
- parent
- public ASTNode(int integer, java.lang.String unitsID, MathContainer parent)
ASTNode
with the given integer value with
the given associated unitId
for the
given MathContainer
as its parent SBML object.integer
- unitsID
- parent
- public ASTNode(MathContainer parent)
ASTNode
.
By default, the returned node will have a type of ASTNode.Type.UNKNOWN
.
The calling code should set the node type to something else as soon as
possible using setType(int)parent
- the parent SBML objectpublic ASTNode(java.lang.String name)
ASTNode
with the given name.name
- the name of this ASTNodepublic ASTNode(java.lang.String name, MathContainer parent)
ASTNode
with the given name.name
- the name of this ASTNodeparent
- the parent SBML object.public ASTNode(ASTNode.Type type)
type
- public ASTNode(ASTNode.Type type, MathContainer parent)
ASTNode
.type
- the type of the ASTNode to create.parent
- the parent SBML object.public static ASTNode abs(double d, MathContainer parent)
ASTNode
that computes the absolute value
of the given double value.public static ASTNode abs(int integer, MathContainer parent)
ASTNode
that computes the absolute value
of the given integer value.private static ASTNode arithmethicOperation(ASTNode.Type operator, ASTNode... ast)
ASTNode
of type operator
and adds the given nodes as children.operator
- the type of arithmetic operationast
- the children of the new ASTNodeASTNode
of type operator
and adds the given nodes as children.public static ASTNode diff(ASTNode... ast)
ASTNode
of type MINUS and adds the given nodes as childrenast
- the children of the new ASTNodeASTNode
of type MINUS and adds the given nodes as childrenpublic static ASTNode eq(ASTNode left, ASTNode right)
ASTNode
of type RELATIONAL_EQ.left
- the left child.right
- the right child.ASTNode
of type RELATIONAL_EQ.public static ASTNode exp(ASTNode exponent)
ASTNode
that represents Euler's constant raised by the
power of the given exponent.exponent
- the exponentASTNode
that represents Euler's constant raised by the
power of the given exponent.public static java.lang.String formulaToString(ASTNode tree) throws SBMLException
tree
- the root of the ASTNode formula expression treenull
is
returned if the given argument is null
.SBMLException
toFormula()
public static ASTNode frac(ASTNode numerator, ASTNode denominator)
ASTNode
of type DIVIDE with the given nodes as children.numerator
- the numeratordenominator
- the denominatorASTNode
of type DIVIDE with the given nodes as children.public static ASTNode frac(int numerator, ASTNode denominator)
ASTNode
that of type DIVIDE with the given numerator and
denominator.numerator
- the numeratordenominator
- the denominatorASTNode
that of type DIVIDE with the given numerator and
denominator.public static ASTNode frac(MathContainer container, CallableSBase numerator, CallableSBase denominator)
ASTNode
that divides two CallableSBase
objects.container
- the parent objectnumerator
- the numeratordenominator
- the denominatorASTNode
that divides two CallableSBase
objects.public static ASTNode frac(MathContainer container, java.lang.String numeratorId, java.lang.String denominatorId)
ASTNode
that of type DIVIDE with the two entities as numerator and denominator.container
- the parent objectnumeratorId
- the numeratordenominatorId
- the numeratorASTNode
that of type DIVIDE with the two entities as numerator and denominator.public static ASTNode geq(ASTNode left, ASTNode right)
ASTNode
representing greater or equal for
the two given nodes.left
- the left child.right
- the right child.ASTNode
representing greater or equal.public static ASTNode gt(ASTNode left, ASTNode right)
ASTNode
representing greater than for
the two given left and right child.left
- the left child.right
- the right child.ASTNode
representing greater than for
the two given left and right child.public static ASTNode leq(ASTNode left, ASTNode right)
ASTNode
representing less or equal for
the two given left and right child.left
- the left child.right
- the right child.ASTNode
representing less or equal for
the two given left and right child.public static ASTNode log(ASTNode value)
ASTNode
representing a logarithm to base 10 of the given value.value
- the value which is the argument of the logarithm.ASTNode
representing a logarithm to base 10 of the given value.public static ASTNode log(ASTNode base, ASTNode value)
ASTNode
that represents the logarithm function with
the given base and value. The parent SBML object will be taken from the
ASTNode
value.base
- The basis of this logarithm. Can be null; then a base of 10
will be assumed.value
- Must not be null
.ASTNode
representing the logarithm of the given value
with respect to the given base or to the base 10 if base is null
.public static ASTNode parseFormula(java.lang.String formula) throws ParseException
formula
- a text-string mathematical formula.ASTNode
representing the formula.ParseException
- If the given formula is not of valid format or cannot be
parsed for other reasons.public static ASTNode parseFormula(java.lang.String formula, IFormulaParser parser) throws java.lang.Exception
formula
- a text-string mathematical formula.parser
- a formula parser.ASTNode
representing the formula.ParseException
- If the given formula is not of valid format or cannot be
parsed for other reasons.java.lang.Exception
public static ASTNode pow(ASTNode basis, ASTNode exponent)
ASTNode
.basis
- the basisexponent
- the exponentASTNode
.public static ASTNode pow(ASTNode basis, double exponent)
ASTNode
.basis
- the basisexponent
- the exponentASTNode
.public static ASTNode pow(ASTNode basis, int exponent)
ASTNode
.basis
- the basisexponent
- the exponentASTNode
.public static ASTNode pow(MathContainer container, CallableSBase basis, CallableSBase exponent)
container
- the parent objectbasis
- the basisexponent
- the exponentASTNode
.public static ASTNode readMathMLFromString(java.lang.String xml)
Constructs a corresponding abstract syntax tree, and returns a pointer to the root of the tree.
xml
- the MathML XML string.ASTNode
private static ASTNode relational(ASTNode.Type type, ASTNode left, ASTNode right)
ASTNode
of the given type with the two given
children left and right.
Sets the parent SBML object of all nodes to the one provided by the left child.
type
- the type of relational node.left
- the left child.right
- the right child.ASTNode
of the given type with the two given
children left and right.public static ASTNode root(ASTNode rootExponent, ASTNode radicand)
ASTNode
.radicand
- the radicandrootExponent
- the exponent of the root element.ASTNode
.static void setParentSBMLObject(ASTNode node, MathContainer parent)
node
- the orphan nodeparent
- the parentprivate static void setParentSBMLObject(ASTNode node, MathContainer parent, int depth)
node
- the orphan nodeparent
- the parentdepth
- the current depth in the ASTNode
tree.
It is just here for testing purposes to track the depth in the tree
during the process.public static ASTNode sqrt(ASTNode radicand)
ASTNode
.radicand
- ASTNode
.public static ASTNode sum(ASTNode... ast)
ASTNode
of type Plus with the given nodes as children.ast
- the children nodes.ASTNode
of type Plus with the given nodes as children.public static ASTNode sum(MathContainer parent, CallableSBase... sbase)
parent
- the parentsbase
- public static ASTNode times(ASTNode... ast)
ASTNode
of type times and adds the given nodes as children.ast
- ASTNode
of type times and adds the given nodes as children.public static ASTNode times(MathContainer parent, CallableSBase... sbase)
CallableSBase
objects.parent
- sbase
- CallableSBase
objects.public static ASTNode uMinus(ASTNode ast)
ASTNode
that has exactly one child and which is of type
minus, i.e., this negates what is encoded in ast.ast
- ASTNode
that has exactly one child and which is of type
minus, i.e., this negates what is encoded in ast.public static ASTNode uMinus(MathContainer container, CallableSBase sbase)
ASTNode
that has exactly one child and which is of type
minus, i.e., this negates what is encoded in ast.container
- sbase
- ASTNode
that has exactly one child and which is of type
minus, i.e., this negates what is encoded in ast.public void addChild(ASTNode child)
child
- the node to add as child.private void arithmeticOperation(ASTNode.Type operator, ASTNode astnode)
ASTNode
as the
right child of this node. The parentSBMLObject of the whole resulting
ASTNode
is then set to the parent of this node.operator
- The new type of this node. This has to be one of the
following: ASTNode.Type.PLUS
, ASTNode.Type.MINUS
, ASTNode.Type.TIMES
,
ASTNode.Type.DIVIDE
, ASTNode.Type.POWER
,
ASTNode.Type.FUNCTION_ROOT
. Otherwise an
IllegalArgumentException
is thrown.astnode
- The new right child of this nodejava.lang.IllegalArgumentException
- if
ASTNode
is zero (isZero()
) and the given
operator is ASTNode.Type.DIVIDE
ASTNode.Type.PLUS
,
ASTNode.Type.MINUS
, ASTNode.Type.TIMES
, ASTNode.Type.DIVIDE
,
ASTNode.Type.POWER
, ASTNode.Type.FUNCTION_ROOT
public ASTNode clone()
clone
in class AbstractTreeNode
public ASTNodeValue compile(ASTNodeCompiler compiler) throws SBMLException
ASTNode
and returns the result.compiler
- An instance of an ASTNodeCompiler
that provides
methods to translate this ASTNode
into something
different.ASTNodeValue
. The content of the
wrapper depends on the ASTNodeCompiler
used to create it.
However, this ASTNode
will ensure that level and version
are set appropriately according to this node's parent SBML
object.SBMLException
- Thrown if an error occurs during the compilation process.public boolean containsUndeclaredUnits()
true
or false
depending on whether this
ASTNode
refers to elements such as parameters or numbers with
undeclared units.
A return value of true
indicates that the UnitDefinition
returned by SBaseWithDerivedUnit.getDerivedUnitDefinition()
may not accurately
represent the units of the expression.true
if the math expression of this ASTNode
includes parameters/numbers with undeclared units,
false
otherwise.public UnitDefinition deriveUnit() throws SBMLException
SBMLException
- if they are problems going through the ASTNode tree.public ASTNode divideBy(ASTNode ast)
ast
- an ASTNodepublic ASTNode divideBy(CallableSBase namedSBase)
namedSBase
- an SBML element that can be represented by a value.public boolean equals(java.lang.Object object)
equals
in class AbstractTreeNode
public java.util.List<Parameter> findReferencedGlobalParameters()
public boolean getAllowsChildren()
public char getCharacter()
java.lang.IllegalArgumentException
- if the type of the node is not one of PLUS, MINUS, TIMES,
DIVIDE or POWER.public ASTNode getChild(int index)
index
- the index of the child to getASTNode
with the given index.java.lang.IndexOutOfBoundsException
- - if the index is out of range (index < 0 || index >=
size()).public javax.swing.tree.TreeNode getChildAt(int i)
public int getChildCount()
public java.util.List<ASTNode> getChildren()
public java.lang.String getClassName()
public java.lang.String getDefinitionURL()
public int getDenominator()
java.lang.IllegalArgumentException
- if the method is called on a node that is not of type
rational.public java.lang.String getEncoding()
public int getExponent()
java.lang.IllegalArgumentException
- if the method is called on a node that is not of type real.public java.lang.String getId()
public int getInteger()
java.lang.IllegalArgumentException
- if the node is not of type integer.public ASTNode getLeftChild()
public java.util.List<ASTNode> getListOfNodes()
public java.util.List<ASTNode> getListOfNodes(Filter filter)
filter
- public double getMantissa()
public java.lang.String getName()
isOperator() == false
) or numbers (isNumber() == false
).java.lang.IllegalArgumentException
- if the method is called on nodes that are operators or
numbers.public int getNumerator()
java.lang.IllegalArgumentException
- if this method is called on a node type other than rational.public javax.swing.tree.TreeNode getParent()
getParent
in interface javax.swing.tree.TreeNode
getParent
in class AbstractTreeNode
public MathContainer getParentSBMLObject()
MathContainer
; element containing it. From this
MathContainer
even the overall Model
can be accessed.public double getReal()
isReal() == true
, otherwise and Exception is thrown.
This function performs the necessary arithmetic if the node type is
REAL_E (mantissa^exponent) or RATIONAL (numerator / denominator).java.lang.IllegalArgumentException
- if this node is not of type real.public java.util.Set<NamedSBase> getReferencedNamedSBases()
NamedSBase
referenced on this node and
all his descendant.
Just for testing purposes...NamedSBase
referenced on this node and
all his descendant.public ASTNode getRightChild()
getListOfNodes().getLast()
.public java.lang.String getStyle()
public ASTNode.Type getType()
public java.lang.String getUnits()
public UnitDefinition getUnitsInstance()
UnitDefinition
corresponding to the unit
that has been set for this ASTNode
and returns a pointer to it.
Note that in case that this ASTNode
is associated with a
Unit.Kind
, the created UnitDefinition
will not be part of the
model, it is just a container for the Unit.Kind
.UnitDefinition
or null
.public CallableSBase getVariable()
isVariable()
== true}, otherwise an Exception is thrown.java.lang.RuntimeException
- if isVariable()
returns false
.public int hashCode()
hashCode
in class AbstractTreeNode
public boolean hasUnits()
true
if the current ASTNode or any of his descendant has a unit
defined.true
if the current ASTNode or any of his descendant has a unit
defined.private void initDefaults()
public void insertChild(int n, ASTNode newChild)
public boolean isBoolean()
true
if this node has a boolean type (a logical operator, a
relational operator, or the constants true
or false
).true
if this ASTNode is a boolean, false
otherwise.public boolean isConstant()
true
if this node represents a MathML constant (e.g., true
, Pi).true
if this ASTNode is a MathML constant, false
otherwise.public boolean isDifference()
ASTNode
represents a difference.true
if this ASTNode
represents a difference, false
otherwise.public boolean isFunction()
true
if this node represents a function. In this context, the
term function means pre-defined functions such as "ceil", "abs" or "sin"
or whether this ASTNode
refers to a user-defined
FunctionDefinition
object. Without having a valid reference to
the MathContainer
that owns this ASTNode
it is impossible
to identify the referenced FunctionDefinition
.true
if this ASTNode
is a function, false
otherwise.public boolean isInfinity()
true
if this node represents the special IEEE 754 value infinity,
false
otherwise.true
if this ASTNode is the special IEEE 754 value infinity,
false
otherwise.public boolean isInteger()
true
if this node contains an integer value, false
otherwise.true
if this ASTNode is of type INTEGER, false
otherwise.public boolean isLambda()
true
if this node is a MathML <lambda>, false
otherwise.true
if this ASTNode is of type LAMBDA, false
otherwise.public boolean isLog10()
true
if this node represents a log10() function, false
otherwise.
More precisely, this predicate returns true
if the node type is
FUNCTION_LOG with two children, the first of which is an INTEGER equal to
10.true
if the given ASTNode represents a log10() function, false
otherwise.public boolean isLogical()
true
if this node is a MathML logical operator (i.e., and, or,
not, xor).true
if this ASTNode is a MathML logical operator.public boolean isMinusOne()
true
if this astnode represents the number minus one (either as
integer or as real value).true
if this astnode represents the number minus one (either as
integer or as real value).public boolean isName()
true
if this node is a user-defined Variable
name in SBML L1, L2
(MathML), or the special symbols delay or time. The predicate returns
false
otherwise.true
if this ASTNode
is a user-defined variable name in SBML L1,
L2 (MathML) or the special symbols time or Avogadro.public boolean isNaN()
true
if this node is a type Real and represents the special IEEE
754 value 'not a number' Double.NaN
, false
otherwise.true
if this ASTNode is the Double.NaN
public boolean isNegInfinity()
true
if this node represents the special IEEE 754 value 'negative
infinity' Double.NEGATIVE_INFINITY
, false
otherwise.true
if this ASTNode is Double.NEGATIVE_INFINITY
, false
otherwise.public boolean isNumber()
true
if this node contains a number, false
otherwise. This is
functionally equivalent to the following code:
isInteger() || isReal()
true
if this ASTNode is a number, false
otherwise.public boolean isOne()
true
if this ASTNode
represents the number one (either as
integer or as real value).true
if this ASTNode
represents the number one.public boolean isOperator()
true
if this node is a mathematical operator, meaning, +, -, *, /
or ^ (power).true
if this ASTNode is an operator.public boolean isPiecewise()
true
if this node is the MathML <piecewise> construct,
false
otherwise.true
if this ASTNode is a MathML piecewise functionpublic boolean isRational()
true
if this node represents a rational number, false
otherwise.true
if this ASTNode is of type ASTNode.Type.RATIONAL
.public boolean isReal()
true
if this node can represent a real number, false
otherwise.
More precisely, this node must be of one of the following types: REAL,
REAL_E or RATIONAL.true
if the value of this ASTNode can represented a real number,
false
otherwise.public boolean isRelational()
true
if this node is a MathML relational operator, meaning ==,
>=, >, <, and !=.true
if this ASTNode is a MathML relational operator, false
otherwise.public boolean isSetClassName()
public boolean isSetDefinitionURL()
public boolean isSetEncoding()
public boolean isSetId()
public boolean isSetName()
public boolean isSetNumberType()
true
if the number type is set.true
if the number type is set.public boolean isSetParentSBMLObject()
MathContainer
, is set as a
parent SBML object for this ASTNode
.public boolean isSetStyle()
public boolean isSetUnits()
true
if a unit is defined on this node.true
if a unit is defined on this node.public boolean isSqrt()
true
if this node represents a square root function, false
otherwise.
More precisely, the node type must be ASTNode.Type.FUNCTION_ROOT
with two
children, the first of which is an ASTNode.Type.INTEGER
node having value
equal to 2.true
if the given ASTNode represents a sqrt() function, false
otherwise.public boolean isString()
true
if this node is a name or refers to a
FunctionDefinition
.public boolean isSum()
ASTNode
represents a sum.true
if this ASTNode
represents a sum, false
otherwise.public boolean isUMinus()
true
if this node is a unary minus operator, false
otherwise. A
node is defined as a unary minus node if it is of type MINUS and has
exactly one child.
For numbers, unary minus nodes can be 'collapsed' by negating the number.
In fact, SBML_parseFormula() does this during its parse. However, unary
minus nodes for symbols (NAMES) cannot be 'collapsed', so this predicate
function is necessary.true
if this ASTNode is a unary minus, false
otherwise.public boolean isUnary()
true
if the number of child nodes is exactly one.public boolean isUnknown()
true
if this node has an ASTNode.Type.UNKNOWN
type.
'Unknown' nodes have the type ASTNode.Type.UNKNOWN
. Nodes with unknown types will not
appear in an ASTNode tree returned by JSBML based upon valid SBML
input; the only situation in which a node with type UNKNOWN may appear is
immediately after having created a new, untyped node using the ASTNode
constructor. Callers creating nodes should endeavor to set the type to a
valid node type as soon as possible after creating new nodes.true
if this ASTNode is of type ASTNode.Type.UNKNOWN
, false
otherwise.public boolean isVariable()
true
if this node represents a Variable
.true
if this node represents a Variable
.public boolean isZero()
true
if this node represents the number zero (either as integer
or as real value).true
if this node represents the number zero.public ASTNode minus(ASTNode ast)
ast
- an ASTNode
public ASTNode minus(double real)
real
- a double number.public ASTNode minus(int integer)
integer
- an integer number.public ASTNode minus(int integer, java.lang.String unitsID)
integer
- unitsID
- public ASTNode multiplyWith(ASTNode ast)
ASTNode
with the given nodeast
- an ASTNode
public ASTNode multiplyWith(ASTNode... nodes)
ASTNode
with the given nodes, i.e., all given nodes
will be children of this node, whose type will be set to ASTNode.Type.TIMES
.nodes
- some ASTNode
public ASTNode multiplyWith(CallableSBase nsb)
ASTNode
with the given SBML element.nsb
- an SBML element that can be represented by a value.public ASTNode plus(ASTNode ast)
ast
- an ASTNode
public ASTNode plus(CallableSBase nsb)
nsb
- an SBML element that can be represented by a value.public ASTNode plus(double real)
real
- a double number.public ASTNode plus(int integer)
integer
- an integer number.public void prependChild(ASTNode child)
child
- an ASTNode
public ASTNode raiseByThePowerOf(ASTNode exponent)
exponent
- an ASTNode
public ASTNode raiseByThePowerOf(CallableSBase nsb)
nsb
- an SBML element that can be represented by a value.public ASTNode raiseByThePowerOf(double exponent)
ASTNode
by the power of the given number.exponent
- a double number.private void reduceToBinary()
Reduces this ASTNode
to a binary tree, e.g., if the formula in this
ASTNode
is and(x, y, z) then the formula of the reduced node would
be and(and(x, y), z).
This method is not yet completed. Currently, only ASTNode.Type.PLUS
,
ASTNode.Type.TIMES
, ASTNode.Type.LOGICAL_AND
, ASTNode.Type.LOGICAL_OR
are
touched by the method. All other nodes are left unchanged, but it traverses
the entire tree rooted at this node.
public boolean refersTo(java.lang.String id)
true
if this node or one of its descendants contains some
identifier with the given id. This method can be used to scan a formula
for a specific parameter or species and detect whether this component is
used by this formula. This search is done using a DFS.id
- the id of an SBML element.true
if this node or one of its descendants contains the
given id.public boolean removeChild(int n)
n
- the index of the child to removepublic void replaceArgument(java.lang.String bvar, ASTNode arg)
bvar
- a string representing the variable name to be substitutedarg
- an ASTNode representing the name/value/formula to substitutepublic ASTNode replaceChild(int n, ASTNode newChild)
n
- long the index of the child to replacenewChild
- ASTNode
to replace the nth childprivate void resetParentSBMLObject(ASTNode node)
removed
- public void setCharacter(char value)
value
- the character value to which the node's value should be set.public void setClassName(java.lang.String className)
className
- the class name.public void setDefinitionURL(java.lang.String definitionURL)
definitionURL
- public void setEncoding(java.lang.String encoding)
encoding
- the encodingpublic void setId(java.lang.String id)
id
- the id.public void setIsSetNumberType(boolean isSetNumberType)
isSetNumberType
- public void setName(java.lang.String name)
ASTNode
to the given name.
The node type will be set (to ASTNode.Type.NAME
) only if the ASTNode
was previously an
operator (isOperator(node) == true
) or number (isNumber(node) == true
).
This allows names to be set for ASTNode.Type.FUNCTION
s and the like.name
- public void setStyle(java.lang.String style)
ASTNode
.style
- the style.public void setType(java.lang.String typeStr)
typeStr
- the type as a String.public void setType(ASTNode.Type type)
type
- the type to which this node should be setpublic void setUnits(java.lang.String unitId)
unitId
- java.lang.IllegalArgumentException
- if the ASTNode is not a kind of numbers (<cn> in mathml) or
if the unitId
is not a valid unit kind or the id
of a unit definition.public void setUnits(Unit.Kind unit)
unit
- public void setUnits(UnitDefinition ud)
ud
- public void setValue(double value)
setValue(value, 0);
value
- the double format number to which this node's value should be
setpublic void setValue(double mantissa, int exponent)
mantissa
- the mantissa of this node's real-numbered valueexponent
- the exponent of this node's real-numbered valuepublic void setValue(int value)
value
- public void setValue(int numerator, int denominator)
numerator
- the numerator value of the rationaldenominator
- the denominator value of the rationalpublic void setVariable(CallableSBase variable)
CallableSBase
as the
variable of this ASTNode
. Note that if the given variable
does not have a declared id
field, the pointer to this variable
will get lost when cloning this node. Only references to identifiers are
permanently stored. The pointer can also not be written to an SBML file
without a valid identifier.variable
- a pointer to a CallableSBase
.public ASTNode sqrt()
public void swapChildren(ASTNode that)
Swaps the children of this ASTNode
with the children of that
ASTNode
.
Unfortunately, when swapping child nodes, we have to recursively traverse the entire subtrees in order to make sure that all pointers to the parent SBML object are correct. However, this must only be done if the parent SBML object of that differs from the one surrounding this node.
In any case, the pointer from each sub-node to its parent must be changed.
In contrast to other SBML elements, ASTNode
s have sub-nodes as
direct children, i.e., there is no child called 'ListOfNodes'. The
setParent
method is also not recursive.
However, this might cause many calls to listeners.
that
- the other node whose children should be used to replace this
node's childrenpublic java.lang.String toFormula() throws SBMLException
Converts this ASTNode to a text string using a specific syntax for mathematical formulas.
The text-string form of mathematical formulas produced by formulaToString() and read by parseFormula() are simple C-inspired infix notation taken from SBML Level 1. A formula in this text-string form therefore can be handed to a program that understands SBML Level 1 mathematical expressions, or used as part of a formula translation system. The syntax is described in detail in the documentation for ASTNode.
null
is
returned if the given argument is null
.SBMLException
- if there is a problem in the ASTNode tree.public java.lang.String toLaTeX() throws SBMLException
SBMLException
- if there is a problem in the ASTNode tree.public java.lang.String toMathML()
public java.lang.String toString()
toString
in class AbstractTreeNode
public void unsetUnits()
public void updateVariables()
ASTNode
s can store a direct pointer to a
variable element. This is particularly useful when performing more
complex computation on these data structures. However, if the model is
changed, it may happen that these pointer become invalid. For instance, a
previously local parameter may be added to the model in form of a global
parameter while keeping the same identifier. The local parameter may then
be removed. Whenever performing changes like this, you may want to update
pointers within ASTNode
constructs as well.