Class CompareNode

All Implemented Interfaces:
IParsedExpression, Node, Serializable

public class CompareNode extends ExpressionNode
Compare node compares it's (two) child nodes. Also supports instanceof operator (second child has to evaluate to class object).
See Also:
  • Field Details

    • EQUAL

      public static final int EQUAL
      The equal (==) operator.
      See Also:
    • UNEQUAL

      public static final int UNEQUAL
      The unequal (!=) operator.
      See Also:
    • GREATER

      public static final int GREATER
      The greater-than (>) operator.
      See Also:
    • LESS

      public static final int LESS
      The less-than (invalid input: '<') operator.
      See Also:
    • GREATEREQUAL

      public static final int GREATEREQUAL
      The greater-equal (>=) operator.
      See Also:
    • LESSEQUAL

      public static final int LESSEQUAL
      The less-equal (invalid input: '<'=) operator.
      See Also:
    • INSTANCEOF

      public static final int INSTANCEOF
      The instanceof operator.
      See Also:
    • op

      protected int op
      The operation.
  • Constructor Details

    • CompareNode

      public CompareNode(jadex.javaparser.javaccimpl.ParserImpl p, int id)
      Create a node.
      Parameters:
      p - The parser.
      id - The id.
  • Method Details

    • setText

      public void setText(String text)
      Set the token text.
      Overrides:
      setText in class ExpressionNode
      Parameters:
      text - The token text.
    • precompile

      public void precompile()
      Check argument number, and precompute expression when all children are constant.
      Overrides:
      precompile in class ExpressionNode
    • getValue

      public Object getValue(jadex.common.IValueFetcher fetcher)
      Evaluate the expression in the given state with respect to given parameters.
      Specified by:
      getValue in interface IParsedExpression
      Specified by:
      getValue in class ExpressionNode
      Parameters:
      params - The parameters (string, value pairs), if any.
      Returns:
      The value of the term.
    • toPlainString

      public String toPlainString()
      Create a string representation of this node and its subnodes.
      Specified by:
      toPlainString in interface Node
      Overrides:
      toPlainString in class ExpressionNode
      Returns:
      A string representation of this node.
    • compare

      protected int compare(Object val1, Object val2)
      Compare two values.
      Parameters:
      val1 - The first value.
      val2 - The second value.
      Returns:
      A negative integer, zero, or a positive integer as the first value is less than, equal to, or greater than the second value.
      Throws:
      ClassCastException - when the values are not comparable.
    • toString

      public static String toString(int operator)
      Convert an operator to a string representation.
      Parameters:
      operator - The operator
      Returns:
      A string representation of the operator.
    • fromString

      public static int fromString(String operator)
      Convert an operator from a string representation.
      Parameters:
      operator - The operator as string.
      Returns:
      The int value of the operator.
    • equals

      public boolean equals(Object o)
      Test if two nodes are equal.
      Overrides:
      equals in class ExpressionNode
    • hashCode

      public int hashCode()
      Get the hash code for the node.
      Overrides:
      hashCode in class ExpressionNode