|
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 |
java.lang.Object dk.rode.thesis.interpreter.TypedExpressionDecorator<E>
E
- The type of value the evaluation of the decorated
expression produces.public class TypedExpressionDecorator<E>
A type expression decorator allows any expression to be explicitly associated with the type of the values the evaluation of it will produce.
In case the decorated expression is initialisable
, it will be initialised by the initialise()
method defined in this decorator. If the decorated expression is not
initialisable, the initialise()
and
isInitialised()
methods does nothing.
Implementation notes:
This is a fine example of the
Decorator pattern
at work.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.interpreter.Expression |
---|
Expression.SymbolIdiom |
Field Summary | |
---|---|
protected Expression<E> |
expression
The decorated expression. |
protected boolean |
includeTypeInfo
True if the evaluation type of expression will be
included in the symbolic representation of it, false if not. |
protected Class<E> |
type
The type of values the evaluation of expression
produces. |
Constructor Summary | |
---|---|
TypedExpressionDecorator(Expression<E> expression,
Class<E> type)
Constructor, which decorates the expression supplied as expression having the type
supplied as type . |
|
TypedExpressionDecorator(Expression<E> expression,
Class<E> type,
boolean includeTypeInfo)
Constructor, which decorates the expression supplied as expression having the type
supplied as type . |
|
TypedExpressionDecorator(TypedExpression<E> expression)
Constructor, which decorates the typed expression supplied as expression . |
|
TypedExpressionDecorator(TypedExpressionDecorator<E> expression)
Copy constructor. |
Method Summary | |
---|---|
String |
asSymbol(Context context)
Returns x , where x is the symbolic
representation of the decorated expression, or if type information
is included, Type{x} , where Type is the simple
name of the type. |
boolean |
contains(Expression<?> expression)
Returns true if this expression is or contains the expression supplied as expression , false if not. |
TypedExpressionDecorator<E> |
copy()
Copies this typed expression. |
boolean |
equals(Object object)
Returns true if object is a typed expression
decorator decorating the same expressions as this
decorator, tested using equals(Object) , false
if not. |
E |
evaluate(Context context)
Evaluates this expression and returns the result. |
int |
hashCode()
Returns the hash code of this expression. |
TypedExpressionDecorator<E> |
initialise()
Initialises this expression before evaluation. |
boolean |
isInitialised()
Returns true if this expression has been initialised , and hence ready to be evaluated, false if not. |
String |
name()
The stand-alone 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. |
Class<E> |
type()
Return the type of value the evaluation of this expression produces. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected final Expression<E> expression
Never null.
protected final boolean includeTypeInfo
expression
will be
included in the symbolic representation of it, false if not. Default false.
protected final Class<E> type
expression
produces. Never null.
Constructor Detail |
---|
public TypedExpressionDecorator(Expression<E> expression, Class<E> type)
expression
having the type
supplied as type
.
The symbolic representation of expression
will
include type information regarding type
.
expression
- The expression to decorate; cannot be null.type
- The actual type; cannot be null.
NullPointerException
- If either argument is null.public TypedExpressionDecorator(Expression<E> expression, Class<E> type, boolean includeTypeInfo)
expression
having the type
supplied as type
.
The symbolic representation of expression
will
include type information regarding type
if includeTypeInfo
is true, not if false.
expression
- The expression to decorate; cannot be null.type
- The type of values the evaluation of
expression
produces.includeTypeInfo
- True to include type information in
the symbolic representation of
expression
, false if not.
NullPointerException
- If expression
or type
is null.public TypedExpressionDecorator(TypedExpression<E> expression)
expression
.
The symbolic representation of expression
will
include type information regarding the type of
expression
.
expression
- The typed expression to decorate; cannot be null.
NullPointerException
- If expression
is null.public TypedExpressionDecorator(TypedExpressionDecorator<E> expression)
expression
- The expression to copy; cannot be null.
NullPointerException
- If expression
is null.Method Detail |
---|
public String asSymbol(Context context) throws ExpressionException
x
, where x
is the symbolic
representation of the decorated expression, or if type information
is included, Type{x}
, where Type
is the simple
name of the type.
asSymbol
in interface Expression<E>
context
- The context to use; never null.
ExpressionException
- If the symbol cannot be generated.Expression.contains(Expression)
public boolean contains(Expression<?> expression)
Expression
expression
, false if not. The test is performed using identity (==).
Unlike Expression.asSymbol(Context)
, querying for containment
cannot handle cyclic expression references!
contains
in interface Expression<E>
expression
- The expression to test; cannot be null.
expression
is this expression or
contained within this expression, false if not.Expression.asSymbol(Context)
,
Context.touch(Expression)
public TypedExpressionDecorator<E> copy()
TypedExpression
Unlike Expression.asSymbol(Context)
, copying
cannot handle cyclic expression references!
copy
in interface Expression<E>
copy
in interface InitialisableExpression<E>
copy
in interface TypedExpression<E>
copy
in interface Copyable<Expression<E>>
public boolean equals(Object object)
object
is a typed expression
decorator decorating the same expressions as this
decorator, tested using equals(Object)
, false
if not.
equals
in class Object
object
- The object to test; can be null.
public E evaluate(Context context) throws ExpressionException
Expression
There is no guarantee that the evaluation of this expression will terminate!
evaluate
in interface Expression<E>
context
- The context to use; cannot be null.
ExpressionException
- If the evaluation fails.public int hashCode()
hashCode
in class Object
public TypedExpressionDecorator<E> initialise() throws ExpressionException
InitialisableExpression
Contained initialisable expressions are not initialised!
initialise
in interface InitialisableExpression<E>
ExpressionException
- If this expression has already
been initialised.public boolean isInitialised()
InitialisableExpression
initialised
, and hence ready to be evaluated, false if not. If this expression has not been initialised when evaluated, the evaluation will throw an exception.
isInitialised
in interface InitialisableExpression<E>
public String name()
Expression
name
in interface Expression<E>
public List<Expression<?>> operands()
Expression
Modifying the returned list will not affect this expression.
operands
in interface Expression<E>
public String toString()
Expression
Unlike Expression.asSymbol(Context)
, the string generation
cannot handle cyclic expression references!
toString
in interface Expression<E>
toString
in class Object
public Class<E> type()
TypedExpression
type
in interface TypedExpression<E>
BreakExpression
!
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |