Class FormulaAst

java.lang.Object
org.yamcs.studio.data.formula.FormulaAst

public class FormulaAst extends Object
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.
  • Method Details

    • getType

      public FormulaAst.Type getType()
    • getValue

      public Object 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

      public List<FormulaAst> getChildren()
      The children of this node, if IO, null otherwise.
      Returns:
      the node children; null if no children
    • listChannelNames

      public List<String> listChannelNames()
      Lists all the channel names used in the AST.
      Returns:
      a list of channel names
    • stringFromToken

      public static FormulaAst stringFromToken(String token)
      A STRING node from a quoted token.
      Parameters:
      token - the quoted string
      Returns:
      the new node
    • string

      public static FormulaAst string(String unquotedString)
      A STRING node representing the given string.
      Parameters:
      unquotedString - the string
      Returns:
      the new node
    • integerFromToken

      public static FormulaAst integerFromToken(String token)
      An INTEGER node from a token.
      Parameters:
      token - a string parsable to an integer
      Returns:
      the new node
    • integer

      public static FormulaAst integer(int integer)
      An INTEGER node from the given value.
      Parameters:
      integer - the integer value
      Returns:
      the new node
    • floatingPointFromToken

      public static FormulaAst floatingPointFromToken(String token)
      A FLOATING_POINT node from a token.
      Parameters:
      token - a string parseable to a double
      Returns:
      the new node
    • floatingPoint

      public static FormulaAst floatingPoint(double floatingPoint)
      A FLOATING_POINT node from the given value.
      Parameters:
      floatingPoint - the double value
      Returns:
      the new node
    • channelFromToken

      public static FormulaAst channelFromToken(String token)
      A CHANNEL node from a quoted token.
      Parameters:
      token - the quoted channel name
      Returns:
      the new node
    • channel

      public static FormulaAst channel(String channelName)
      A CHANNEL node representing the given channel name.
      Parameters:
      channelName - the channel name
      Returns:
      the new node
    • id

      public static FormulaAst id(String id)
      An ID node representing the given id.
      Parameters:
      id - the id
      Returns:
      the new node
    • op

      public static FormulaAst op(String opName, FormulaAst... children)
      An OP node representing the given operator/function with the given arguments.
      Parameters:
      opName - the name of the operator/function
      children - the node children
      Returns:
      the new node
    • op

      public static FormulaAst op(String opName, List<FormulaAst> children)
      An OP node representing the given operator/function with the given arguments.
      Parameters:
      opName - the name of the operator/function
      children - the node children
      Returns:
      the new node
    • formula

      public static FormulaAst formula(String formula)
      The AST corresponding to the parsed formula.
      Parameters:
      formula - the string to be parsed
      Returns:
      the parsed AST
    • singleChannel

      public 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.
      Parameters:
      formula - the string to be parsed
      Returns:
      the parsed AST
    • substituteChannels

      public FormulaAst 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.
      Parameters:
      substitutions - from channel name to new AST
      Returns:
      a new AST
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object