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
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
interface.
The Parser
class provides a default
implementation of such a parser.ParserImpl
- Version:
- $Revision$ $Date$
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
The numerical ADD operation: n-term+
n-termstatic final class
The logical AND operation: b-term&&
b-termstatic final class
The bitwise AND operation: i-term&
i-termstatic final class
The assignment operation variable-ref-term=
termstatic class
static class
An abstract binary (= 2 operands) operation.static class
An abstract binary (= 2 operands) operation with a return type ofint
.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:
termstatic 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-termstatic final class
The boolean EQ operation: b-term==
b-termstatic final class
The double EQ operation: d-term==
d-termstatic final class
The integer EQ operation: i-term==
i-termstatic final class
The double GE operation: d-term>=
d-termstatic final class
The integer GE operation: i-term>=
i-termstatic final class
The double GT operation: d-term>
d-termstatic final class
The integer GT operation: i-term>
i-termstatic final class
The double LE operation: d-term<=
d-termstatic final class
The integer LE operation: i-term<=
i-termstatic final class
The double LT operation: d-term<
d-termstatic final class
The integer LT operation: i-term<
i-termstatic final class
The numerical MOD (modulo) operation: n-term%
n-termstatic final class
The numerical MUL operation: n-term*
n-termstatic final class
The numerical NEG operation:-
d-termstatic final class
The boolean NEQ operation: b-term!=
b-termstatic final class
The double NEQ operation: d-term!=
d-termstatic final class
The integer NEQ operation: i-term!=
i-termstatic final class
The logical NOT operation!
b-termstatic final class
The bitwise NOT operation:~
i-termstatic class
An abstract operation.static final class
The logical OR operation: b-term||
b-termstatic final class
The bitwise OR operation: i-term¦
i-termstatic final class
A reference to a
.Symbol
static final class
The numerical SUB operation: n-term-
n-termstatic class
An abstract unary (= 1 operand) operation.static class
An abstract unary (= 1 operand) operation with return type ofboolean
.static class
An abstract unary (= 1 operand) operation with return type ofint
.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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract <T> T
accept
(TermVisitor<T> visitor) Visitor support.abstract int
abstract boolean
Evaluates this term to aboolean
value.abstract double
Evaluates this term to adouble
value.abstract int
Evaluates this term to anint
value.Evaluates this term to aString
value.Term[]
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 aboolean
.abstract boolean
isConst()
final boolean
isD()
Tests whether or not this term "naturally" returns adouble
.final boolean
isI()
Tests whether or not this term "naturally" returns anint
.final boolean
isN()
Tests whether or not this term "naturally" returns a numeric value.final 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 Details
-
TYPE_B
public static final int TYPE_BThe ID for theboolean
type.- See Also:
-
TYPE_I
public static final int TYPE_IThe ID for theint
type.- See Also:
-
TYPE_D
public static final int TYPE_DThe ID for thedouble
type.- See Also:
-
TYPE_S
public static final int TYPE_SThe ID for thestring
type.- See Also:
-
-
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
Evaluates this term to aboolean
value.- Parameters:
context
- the application dependant environment.- Returns:
- a
boolean
value - Throws:
EvalException
- if the evaluation fails
-
evalI
Evaluates this term to anint
value.- Parameters:
env
- the application dependant environment.- Returns:
- an
int
value - Throws:
EvalException
- if the evaluation fails
-
evalD
Evaluates this term to adouble
value.- Parameters:
env
- the application dependant environment.- Returns:
- a
double
value - Throws:
EvalException
- if the evaluation fails
-
accept
Visitor support.- Parameters:
visitor
- A visitor.
-
evalS
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
Returns an array of terms which are children of this term.- Returns:
- an array of terms, never
null
but can be empty
-
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
Converts aboolean
to aString
.- Parameters:
value
- the value to be converted- Returns:
- the conversion result, which is
value ? 1.0 : 0.0
.
-
toS
Converts ainteger
to aString
.- Parameters:
value
- the value to be converted- Returns:
- the conversion result, which is
value ? 1.0 : 0.0
.
-
toS
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
-
pre
public abstract int pre()
-