
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
E
 The type of value the evaluation of this expression
produces.@Participant(value="AbstractExpression") public interface Expression<E>
An expression represents grammar rules in form
or non terminal expressions
and actual functionality in form of terminal expressions
that will be enforced when the expression
is evaluated
.
Expressions are considered immutable, but can be copied
.
Each unique expression type have a name
and each
instance symbolic
representation. Expressions
that cannot be constructed in a single step must be
initialised
before use; once
initialised, they are considered immutable.
Expressions may use other expressions as operands
.
If a given expression uses or contains another expression
can be tested using the contains(Expression)
method, based
on identity. An expression containing cyclic expression references
can still be evaluated and generate a symbolic representation, but
cannot be copied, queried for containment, or generate its
toString()
representation.
Expression
is the common super type for all expressions
that can be evaluated by an interpreter
.
Implementation notes:
As expressions are considered immutable, all but a few internal
attributes can be declared final. Simple immutable flags or values
can therefore be exposed directly through a final public instance
variable, such as the value of a constant
or the comparison
type used.
TypedExpression
,
InitialisableExpression
Nested Class Summary  

static class 
Expression.SymbolIdiom
The symbol idiom ensures that cyclic expression references will be represented correctly in symbolic
representation starting from a given expression. 
Method Summary  

String 
asSymbol(Context context)
Returns a short symbolic representation of this expression that describes it in a concise form. 
boolean 
contains(Expression<?> expression)
Returns true if this expression is or contains the expression supplied as expression , false if not. 
Expression<E> 
copy()
Copies this expression. 
E 
evaluate(Context context)
Evaluates this expression and returns the result. 
String 
name()
The standalone symbol name for this expression. 
List<Expression<?>> 
operands()
Returns the expression operands used by this expression, in order. 
String 
toString()
Returns the string representation of this expression. 
Method Detail 

String asSymbol(Context context) throws ExpressionException
The caller of this method should always ensure
that context
is reset properly before use
by calling Context.reset()
. This ensures that
cyclic expression references are handled properly!
General semantics:
&&
and }}
for logical shortcircuit AND and OR, respectively;
&
and }} for logical non shortcircuit
AND and OR, respectively; <
, <=
, ==
,
!=
, >=
, and >
for comparison; =
for assignment; !
for negation; and x ? y : z
for
conditional expressions, where x
, y
, and z
are expressions.
terminal
expressions
are enclosed in square brackets, not parentheses, like
x[y]
, where x
is the terminal expression
taking expression y
as an argument.
typed
expressions may expose the type
like Type{x}
, where Type
is the simple
class name of the type, and x
the symbolic
representation of the expression.
{{from > to}}
, where from
and to
are the names
of the expressions, respectively.
context
 The context to use; never null.
NullPointerException
 If context
is null.
ExpressionException
 If the symbol cannot be generated.contains(Expression)
boolean contains(Expression<?> expression)
expression
, false if not. The test is performed using identity (==).
Unlike asSymbol(Context)
, querying for containment
cannot handle cyclic expression references!
expression
 The expression to test; cannot be null.
expression
is this expression or
contained within this expression, false if not.
NullPointerException
 If expression
is null.asSymbol(Context)
,
Context.touch(Expression)
Expression<E> copy()
Unlike asSymbol(Context)
, copying
cannot handle cyclic expression references!
copy
in interface Copyable<Expression<E>>
E evaluate(Context context) throws ExpressionException
There is no guarantee that the evaluation of this expression will terminate!
context
 The context to use; cannot be null.
NullPointerException
 If context
is null.
ExpressionException
 If the evaluation fails.String name()
List<Expression<?>> operands()
Modifying the returned list will not affect this expression.
String toString()
Unlike asSymbol(Context)
, the string generation
cannot handle cyclic expression references!
toString
in class Object

Gunni Rode / rode.dk  
PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 