Package org.yamcs.studio.data.formula
Class FormulaAst
java.lang.Object
org.yamcs.studio.data.formula.FormulaAst
The abstract syntax tree corresponding to a formula expression. This class provides a logical representation of the
expression, static factory methods to create such expressions from text representation (i.e. parsing) and the ability
to convert to datasource expressions.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic FormulaAst
A CHANNEL node representing the given channel name.static FormulaAst
channelFromToken
(String token) A CHANNEL node from a quoted token.boolean
static FormulaAst
floatingPoint
(double floatingPoint) A FLOATING_POINT node from the given value.static FormulaAst
floatingPointFromToken
(String token) A FLOATING_POINT node from a token.static FormulaAst
The AST corresponding to the parsed formula.The children of this node, if IO, null otherwise.getType()
getValue()
The value corresponding to the node.int
hashCode()
static FormulaAst
An ID node representing the given id.static FormulaAst
integer
(int integer) An INTEGER node from the given value.static FormulaAst
integerFromToken
(String token) An INTEGER node from a token.Lists all the channel names used in the AST.static FormulaAst
op
(String opName, List<FormulaAst> children) An OP node representing the given operator/function with the given arguments.static FormulaAst
op
(String opName, FormulaAst... children) An OP node representing the given operator/function with the given arguments.static FormulaAst
singleChannel
(String formula) The AST corresponding to a single channel, if the formula represents one, or null, if the formula is not a single channel.static FormulaAst
A STRING node representing the given string.static FormulaAst
stringFromToken
(String token) A STRING node from a quoted token.substituteChannels
(Map<String, FormulaAst> substitutions) Returns a new AST where the channel nodes that match the keys of the map are substituted with the values of the map.toString()
-
Method Details
-
getType
-
getValue
The value corresponding to the node. The value depends on the type as follows:- OP: String with the name of the function/operator
- STRING: the String constant (unquoted)
- INTEGER: the Integer constant
- FLOATING_POINT: the Double constant
- CHANNEL: String with the channel name (unquoted)
- ID: String with the name of the id
- Returns:
- the value of the node
-
getChildren
The children of this node, if IO, null otherwise.- Returns:
- the node children; null if no children
-
listChannelNames
Lists all the channel names used in the AST.- Returns:
- a list of channel names
-
stringFromToken
A STRING node from a quoted token.- Parameters:
token
- the quoted string- Returns:
- the new node
-
string
A STRING node representing the given string.- Parameters:
unquotedString
- the string- Returns:
- the new node
-
integerFromToken
An INTEGER node from a token.- Parameters:
token
- a string parsable to an integer- Returns:
- the new node
-
integer
An INTEGER node from the given value.- Parameters:
integer
- the integer value- Returns:
- the new node
-
floatingPointFromToken
A FLOATING_POINT node from a token.- Parameters:
token
- a string parseable to a double- Returns:
- the new node
-
floatingPoint
A FLOATING_POINT node from the given value.- Parameters:
floatingPoint
- the double value- Returns:
- the new node
-
channelFromToken
A CHANNEL node from a quoted token.- Parameters:
token
- the quoted channel name- Returns:
- the new node
-
channel
A CHANNEL node representing the given channel name.- Parameters:
channelName
- the channel name- Returns:
- the new node
-
id
An ID node representing the given id.- Parameters:
id
- the id- Returns:
- the new node
-
op
An OP node representing the given operator/function with the given arguments.- Parameters:
opName
- the name of the operator/functionchildren
- the node children- Returns:
- the new node
-
op
An OP node representing the given operator/function with the given arguments.- Parameters:
opName
- the name of the operator/functionchildren
- the node children- Returns:
- the new node
-
formula
The AST corresponding to the parsed formula.- Parameters:
formula
- the string to be parsed- Returns:
- the parsed AST
-
singleChannel
The AST corresponding to a single channel, if the formula represents one, or null, if the formula is not a single channel.- Parameters:
formula
- the string to be parsed- Returns:
- the parsed AST
-
substituteChannels
Returns a new AST where the channel nodes that match the keys of the map are substituted with the values of the map.- Parameters:
substitutions
- from channel name to new AST- Returns:
- a new AST
-
toString
-
equals
-
hashCode
public int hashCode()
-