Package org.esa.snap.core.jexp
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 abstractTerm
class is an in-memory representation of an element within an arbitrary expression tree. The class defines a number of concreteTerm
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
interface. TheParser
class provides a default implementation of such a parser.ParserImpl
- Version:
- $Revision$ $Date$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Term.Add
The numerical ADD operation: n-term+
n-termstatic class
Term.AndB
The logical AND operation: b-term&&
b-termstatic class
Term.AndI
The bitwise AND operation: i-term&
i-termstatic class
Term.Assign
The assignment operation variable-ref-term=
termstatic class
Term.Binary
static class
Term.BinaryB
An abstract binary (= 2 operands) operation.static class
Term.BinaryI
An abstract binary (= 2 operands) operation with a return type ofint
.static class
Term.BinaryN
An abstract binary (= 2 operands) operation with a numeric return type.static class
Term.Call
A call of a (or reference to a)
.Function
static class
Term.Cond
The conditional operation b-term?
term:
termstatic class
Term.Const
A boolean constant, e.g.static class
Term.ConstB
A boolean constant, e.g.static class
Term.ConstD
A floating point constant, e.g.static class
Term.ConstI
An integer constant, e.g.static class
Term.ConstS
static class
Term.Div
The numerical DIV operation: n-term/
n-termstatic class
Term.EqB
The boolean EQ operation: b-term==
b-termstatic class
Term.EqD
The double EQ operation: d-term==
d-termstatic class
Term.EqI
The integer EQ operation: i-term==
i-termstatic class
Term.GeD
The double GE operation: d-term>=
d-termstatic class
Term.GeI
The integer GE operation: i-term>=
i-termstatic class
Term.GtD
The double GT operation: d-term>
d-termstatic class
Term.GtI
The integer GT operation: i-term>
i-termstatic class
Term.LeD
The double LE operation: d-term<=
d-termstatic class
Term.LeI
The integer LE operation: i-term<=
i-termstatic class
Term.LtD
The double LT operation: d-term<
d-termstatic class
Term.LtI
The integer LT operation: i-term<
i-termstatic class
Term.Mod
The numerical MOD (modulo) operation: n-term%
n-termstatic class
Term.Mul
The numerical MUL operation: n-term*
n-termstatic class
Term.Neg
The numerical NEG operation:-
d-termstatic class
Term.NEqB
The boolean NEQ operation: b-term!=
b-termstatic class
Term.NEqD
The double NEQ operation: d-term!=
d-termstatic class
Term.NEqI
The integer NEQ operation: i-term!=
i-termstatic class
Term.NotB
The logical NOT operation!
b-termstatic class
Term.NotI
The bitwise NOT operation:~
i-termstatic class
Term.Op
An abstract operation.static class
Term.OrB
The logical OR operation: b-term||
b-termstatic class
Term.OrI
The bitwise OR operation: i-term¦
i-termstatic class
Term.Ref
A reference to a
.Symbol
static class
Term.Sub
The numerical SUB operation: n-term-
n-termstatic class
Term.Unary
An abstract unary (= 1 operand) operation.static class
Term.UnaryB
An abstract unary (= 1 operand) operation with return type ofboolean
.static class
Term.UnaryI
An abstract unary (= 1 operand) operation with return type ofint
.static class
Term.UnaryN
An abstract unary (= 1 operand) operation with a numeric return type.static class
Term.XOrI
The bitwise XOR operation: i-term^
i-term
-
Constructor Summary
Constructors Constructor Description Term()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 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 aboolean
value.abstract double
evalD(EvalEnv env)
Evaluates this term to adouble
value.abstract int
evalI(EvalEnv env)
Evaluates this term to anint
value.String
evalS(EvalEnv env)
Evaluates this term to aString
value.Term[]
getChildren()
Returns an array of terms which are children of this term.abstract int
getRetType()
Gets the term's "natural" return type.boolean
isB()
Tests whether or not this term "naturally" returns aboolean
.abstract boolean
isConst()
boolean
isD()
Tests whether or not this term "naturally" returns adouble
.boolean
isI()
Tests whether or not this term "naturally" returns anint
.boolean
isN()
Tests whether or not this term "naturally" returns a numeric value.boolean
isS()
Tests whether or not this term returns aString
.abstract int
pre()
static boolean
toB(double value)
Converts adouble
to aboolean
.static boolean
toB(int value)
Converts anint
to aboolean
.static double
toD(boolean value)
Converts aboolean
to andouble
.static int
toI(boolean value)
Converts aboolean
to anint
.static int
toI(double value)
Converts adouble
to anint
.static String
toS(boolean value)
Converts aboolean
to aString
.static String
toS(double value)
Converts adouble
to aString
.static String
toS(int value)
Converts ainteger
to aString
.abstract String
toString()
Returns a string representation of this term which can be used for debugging.
-
-
-
Field Detail
-
TYPE_B
public static final int TYPE_B
The ID for theboolean
type.- See Also:
- Constant Field Values
-
TYPE_I
public static final int TYPE_I
The ID for theint
type.- See Also:
- Constant Field Values
-
TYPE_D
public static final int TYPE_D
The ID for thedouble
type.- See Also:
- Constant Field Values
-
TYPE_S
public static final int TYPE_S
The ID for thestring
type.- See Also:
- Constant Field Values
-
-
Method Detail
-
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 aboolean
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 anint
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 adouble
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 aString
value. The default implementation simply returns the value oftoString()
.- 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.
-
isB
public final boolean isB()
Tests whether or not this term "naturally" returns aboolean
.- Returns:
true
if so
-
isI
public final boolean isI()
Tests whether or not this term "naturally" returns anint
.- Returns:
true
if so
-
isD
public final boolean isD()
Tests whether or not this term "naturally" returns adouble
.- 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 aString
.- Returns:
true
if so
-
toB
public static boolean toB(int value)
Converts anint
to aboolean
.- Parameters:
value
- the value to be converted- Returns:
- the conversion result, which is
value != 0
.
-
toB
public static boolean toB(double value)
Converts adouble
to aboolean
.- Parameters:
value
- the value to be converted- Returns:
- the conversion result, which is
value != 0.0
.
-
toI
public static int toI(boolean value)
Converts aboolean
to anint
.- Parameters:
value
- the value to be converted- Returns:
- the conversion result, which is
value ? 1 : 0
.
-
toI
public static int toI(double value)
Converts adouble
to anint
.- Parameters:
value
- the value to be converted- Returns:
- the conversion result, which is
(int) value
.
-
toD
public static double toD(boolean value)
Converts aboolean
to andouble
.- 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 aboolean
to aString
.- 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 ainteger
to aString
.- 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 adouble
to aString
.- 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 anyEvalEnv
, evennull
.
-
compare
public abstract int compare(Term other)
-
pre
public abstract int pre()
-
-