Class Term

java.lang.Object
org.esa.snap.core.jexp.Term
Direct Known Subclasses:
Term.Call, Term.Const, Term.Op, Term.Ref

public abstract class Term extends Object
The abstract Term class is an in-memory representation of an element within an arbitrary expression tree. The class defines a number of concrete Term implementations each representing either an an atomic leave (number constant, symbol reference) or a node (e.g. binary operator, function call) within an expression tree.

Instances of this class are normally created using an expression parser which implements the Parser interface. The ParserImpl class provides a default implementation of such a parser.

Version:
$Revision$ $Date$
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    The numerical ADD operation: n-term + n-term
    static final class 
    The logical AND operation: b-term && b-term
    static final class 
    The bitwise AND operation: i-term & i-term
    static final class 
    The assignment operation variable-ref-term = term
    static class 
     
    static class 
    An abstract binary (= 2 operands) operation.
    static class 
    An abstract binary (= 2 operands) operation with a return type of int.
    static class 
    An abstract binary (= 2 operands) operation with a numeric return type.
    static final class 
    A call of a (or reference to a) Function.
    static final class 
    The conditional operation b-term ? term : term
    static class 
    A boolean constant, e.g.
    static final class 
    A boolean constant, e.g.
    static final class 
    A floating point constant, e.g.
    static final class 
    An integer constant, e.g.
    static class 
     
    static final class 
    The numerical DIV operation: n-term / n-term
    static final class 
    The boolean EQ operation: b-term == b-term
    static final class 
    The double EQ operation: d-term == d-term
    static final class 
    The integer EQ operation: i-term == i-term
    static final class 
    The double GE operation: d-term >= d-term
    static final class 
    The integer GE operation: i-term >= i-term
    static final class 
    The double GT operation: d-term > d-term
    static final class 
    The integer GT operation: i-term > i-term
    static final class 
    The double LE operation: d-term <= d-term
    static final class 
    The integer LE operation: i-term <= i-term
    static final class 
    The double LT operation: d-term < d-term
    static final class 
    The integer LT operation: i-term < i-term
    static final class 
    The numerical MOD (modulo) operation: n-term % n-term
    static final class 
    The numerical MUL operation: n-term * n-term
    static final class 
    The numerical NEG operation: - d-term
    static final class 
    The boolean NEQ operation: b-term != b-term
    static final class 
    The double NEQ operation: d-term != d-term
    static final class 
    The integer NEQ operation: i-term != i-term
    static final class 
    The logical NOT operation ! b-term
    static final class 
    The bitwise NOT operation: ~ i-term
    static class 
    An abstract operation.
    static final class 
    The logical OR operation: b-term || b-term
    static final class 
    The bitwise OR operation: i-term ¦ i-term
    static final class 
    A reference to a Symbol.
    static final class 
    The numerical SUB operation: n-term - n-term
    static class 
    An abstract unary (= 1 operand) operation.
    static class 
    An abstract unary (= 1 operand) operation with return type of boolean.
    static class 
    An abstract unary (= 1 operand) operation with return type of int.
    static class 
    An abstract unary (= 1 operand) operation with a numeric return type.
    static final class 
    The bitwise XOR operation: i-term ^ i-term
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The ID for the boolean type.
    static final int
    The ID for the double type.
    static final int
    The ID for the int type.
    static final int
    The ID for the string type.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract <T> T
    accept(TermVisitor<T> visitor)
    Visitor support.
    abstract int
    compare(Term other)
     
    abstract boolean
    evalB(EvalEnv context)
    Evaluates this term to a boolean value.
    abstract double
    Evaluates this term to a double value.
    abstract int
    Evaluates this term to an int value.
    Evaluates this term to a String value.
    Returns an array of terms which are children of this term.
    abstract int
    Gets the term's "natural" return type.
    final boolean
    isB()
    Tests whether or not this term "naturally" returns a boolean.
    abstract boolean
     
    final boolean
    isD()
    Tests whether or not this term "naturally" returns a double.
    final boolean
    isI()
    Tests whether or not this term "naturally" returns an int.
    final boolean
    isN()
    Tests whether or not this term "naturally" returns a numeric value.
    final boolean
    isS()
    Tests whether or not this term returns a String.
    abstract int
    pre()
     
    static boolean
    toB(double value)
    Converts a double to a boolean.
    static boolean
    toB(int value)
    Converts an int to a boolean.
    static double
    toD(boolean value)
    Converts a boolean to an double.
    static int
    toI(boolean value)
    Converts a boolean to an int.
    static int
    toI(double value)
    Converts a double to an int.
    static String
    toS(boolean value)
    Converts a boolean to a String.
    static String
    toS(double value)
    Converts a double to a String.
    static String
    toS(int value)
    Converts a integer to a String.
    abstract String
    Returns a string representation of this term which can be used for debugging.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • Term

      public Term()
  • Method Details

    • getRetType

      public abstract int getRetType()
      Gets the term's "natural" return type.
      Returns:
      the type, should always be one of the TYPE_X constants defined in this class.
    • evalB

      public abstract boolean evalB(EvalEnv context)
      Evaluates this term to a boolean value.
      Parameters:
      context - the application dependant environment.
      Returns:
      a boolean value
      Throws:
      EvalException - if the evaluation fails
    • evalI

      public abstract int evalI(EvalEnv env)
      Evaluates this term to an int value.
      Parameters:
      env - the application dependant environment.
      Returns:
      an int value
      Throws:
      EvalException - if the evaluation fails
    • evalD

      public abstract double evalD(EvalEnv env)
      Evaluates this term to a double value.
      Parameters:
      env - the application dependant environment.
      Returns:
      a double value
      Throws:
      EvalException - if the evaluation fails
    • accept

      public abstract <T> T accept(TermVisitor<T> visitor)
      Visitor support.
      Parameters:
      visitor - A visitor.
    • evalS

      public String evalS(EvalEnv env)
      Evaluates this term to a String value. The default implementation simply returns the value of toString().
      Parameters:
      env - the application dependant environment.
      Returns:
      a String value
      Throws:
      EvalException - if the evaluation fails
    • getChildren

      public Term[] getChildren()
      Returns an array of terms which are children of this term.
      Returns:
      an array of terms, never null but can be empty
    • toString

      public abstract String toString()
      Returns a string representation of this term which can be used for debugging.
      Overrides:
      toString in class Object
    • isB

      public final boolean isB()
      Tests whether or not this term "naturally" returns a boolean.
      Returns:
      true if so
    • isI

      public final boolean isI()
      Tests whether or not this term "naturally" returns an int.
      Returns:
      true if so
    • isD

      public final boolean isD()
      Tests whether or not this term "naturally" returns a double.
      Returns:
      true if so
    • isN

      public final boolean isN()
      Tests whether or not this term "naturally" returns a numeric value.
      Returns:
      true if so
    • isS

      public final boolean isS()
      Tests whether or not this term returns a String.
      Returns:
      true if so
    • toB

      public static boolean toB(int value)
      Converts an int to a boolean.
      Parameters:
      value - the value to be converted
      Returns:
      the conversion result, which is value != 0.
    • toB

      public static boolean toB(double value)
      Converts a double to a boolean.
      Parameters:
      value - the value to be converted
      Returns:
      the conversion result, which is value != 0.0.
    • toI

      public static int toI(boolean value)
      Converts a boolean to an int.
      Parameters:
      value - the value to be converted
      Returns:
      the conversion result, which is value ? 1 : 0.
    • toI

      public static int toI(double value)
      Converts a double to an int.
      Parameters:
      value - the value to be converted
      Returns:
      the conversion result, which is (int) value.
    • toD

      public static double toD(boolean value)
      Converts a boolean to an double.
      Parameters:
      value - the value to be converted
      Returns:
      the conversion result, which is value ? 1.0 : 0.0.
    • toS

      public static String toS(boolean value)
      Converts a boolean to a String.
      Parameters:
      value - the value to be converted
      Returns:
      the conversion result, which is value ? 1.0 : 0.0.
    • toS

      public static String toS(int value)
      Converts a integer to a String.
      Parameters:
      value - the value to be converted
      Returns:
      the conversion result, which is value ? 1.0 : 0.0.
    • toS

      public static String toS(double value)
      Converts a double to a String.
      Parameters:
      value - the value to be converted
      Returns:
      the conversion result, which is value ? 1.0 : 0.0.
    • isConst

      public abstract boolean isConst()
      Returns:
      true, if this term evaluates to the same constant value regardless of any EvalEnv, even null.
    • compare

      public abstract int compare(Term other)
    • pre

      public abstract int pre()