|
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.VariableExpression<E> dk.rode.thesis.interpreter.ConstantExpression<E>
E
- The type of value the evaluation of this expression
produces.@Participant(value="NonTerminalExpression") public class ConstantExpression<E>
A constant expression represents an expression that can be assigned a constant value.
Constants can be stored in a context
as well,
but this is not a requirement.
This class does not declare a copy constructor, and will when
copied
return the same instance since the
value is constant.
Implementation notes:
The auto-generated name
of a
constant ensures that two constants of the same
type
, E
, having the
same actual value will also have the same name. Hence, look-up
of different constant instances in a Context
will
result in a match if same type and value; equals(Object)
works in a similar manner. However, this also means that a constant
cannot be assigned a value during evaluation, not even once,
because the name depends on the value. Trying to create an
assignment
expression using a constant
as the target of the evaluation is an error, and will cause an
exception to be thrown at construction time.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.interpreter.Expression |
---|
Expression.SymbolIdiom |
Field Summary | |
---|---|
E |
value
The value of this constant. |
Fields inherited from class dk.rode.thesis.interpreter.VariableExpression |
---|
includeTypeInfo, name |
Constructor Summary | |
---|---|
ConstantExpression(Class<E> type,
E value)
Constructor. |
|
ConstantExpression(Class<E> type,
E value,
boolean includeTypeInfo)
Constructor. |
Method Summary | |
---|---|
String |
asSymbol(Context context)
Returns x , where x is the value of
this constant, or if type information is included,
Type{x} , where Type is the simple
name of the type. |
ConstantExpression<E> |
copy()
Copies this expression. |
E |
evaluate(Context context)
Evaluates this expression and returns the result. |
String |
name()
The stand-alone symbol name for this expression. |
Methods inherited from class dk.rode.thesis.interpreter.VariableExpression |
---|
contains, equals, hashCode, operands, toString, type |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final E value
Never null.
Constructor Detail |
---|
public ConstantExpression(Class<E> type, E value)
The symbolic representation of this variable will not
include type information regarding type
.
type
- The type of the value this expression represents;
cannot be null.value
- The constant value; cannot be null.
NullPointerException
- If either argument is null.public ConstantExpression(Class<E> type, E value, boolean includeTypeInfo)
The symbolic representation of this constant will
include type information regarding type
if includeTypeInfo
is true, not if false.
type
- The type of the value this expression represents;
cannot be null.value
- The constant value; cannot be null.includeTypeInfo
- True to include type information in
the symbolic representation, false if not.
NullPointerException
- If either argument is null.Method Detail |
---|
public String asSymbol(Context context)
x
, where x
is the value of
this constant, or if type information is included,
Type{x}
, where Type
is the simple
name of the type.
asSymbol
in interface Expression<E>
asSymbol
in class VariableExpression<E>
context
- The context to use; never null.
Expression.contains(Expression)
public ConstantExpression<E> copy()
Expression
Unlike Expression.asSymbol(Context)
, copying
cannot handle cyclic expression references!
copy
in interface Expression<E>
copy
in interface TypedExpression<E>
copy
in interface Copyable<Expression<E>>
copy
in class VariableExpression<E>
public E evaluate(Context context)
Expression
There is no guarantee that the evaluation of this expression will terminate!
evaluate
in interface Expression<E>
evaluate
in class VariableExpression<E>
context
- The context to use; cannot be null.
public final String name()
Expression
name
in interface Expression<E>
name
in class VariableExpression<E>
constant
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |