|
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.AbstractExpression<E> dk.rode.thesis.interpreter.AssignmentExpression<E>
E
- The type of value the evaluation of this expression
produces.public class AssignmentExpression<E>
An assignment expression assigns the result of the
evaluation of an expression to a variable
.
Implementation notes:
The assignment expression cannot inherit BinaryExpression
because of the Expression<? extends E>
bound on
the first operand for any sub-class of it. Hence, it cannot
be guaranteed to store a variable of type E
, which
is required when assigning the value to the context
on evaluation.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.interpreter.Expression |
---|
Expression.SymbolIdiom |
Field Summary | |
---|---|
private Expression<? extends E> |
expression
The second operand. |
private VariableExpression<E> |
variable
The variable expression to be assigned the value of expression . |
Constructor Summary | |
---|---|
AssignmentExpression(AssignmentExpression<E> expression)
Copy constructor. |
|
AssignmentExpression(VariableExpression<E> variable,
Expression<? extends E> expression)
Constructor. |
Method Summary | |
---|---|
String |
asSymbol(Context context)
Returns x = y , where x is the symbolic
representation of the first expression operand and y
of the the second. |
AssignmentExpression<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. |
List<Expression<?>> |
operands()
Returns the expression operands used by this expression, in order. |
String |
toString()
Returns the string representation of this expression. |
Methods inherited from class dk.rode.thesis.interpreter.AbstractExpression |
---|
contains, equals, hashCode |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface dk.rode.thesis.interpreter.Expression |
---|
contains |
Field Detail |
---|
private final Expression<? extends E> expression
Never null.
private final VariableExpression<E> variable
expression
. Never null.
Constructor Detail |
---|
public AssignmentExpression(AssignmentExpression<E> expression)
expression
- The expression to copy; cannot be null.
NullPointerException
- If expression
is null.public AssignmentExpression(VariableExpression<E> variable, Expression<? extends E> expression)
variable
- The variable to be assigned the result of the
evaluation of expression
; cannot be null,
or be a constant
.expression
- The expression to deliver the variable value when
evaluated; cannot be null.
NullPointerException
- If either argument is null.
IllegalArgumentException
- If variable
is a constant.Method Detail |
---|
public String asSymbol(Context context) throws ExpressionException
x = y
, where x
is the symbolic
representation of the first expression operand and y
of the the second.
asSymbol
in interface Expression<E>
context
- The context to use; never null.
ExpressionException
- If the symbol cannot be generated.Expression.contains(Expression)
public AssignmentExpression<E> copy()
Expression
Unlike Expression.asSymbol(Context)
, copying
cannot handle cyclic expression references!
copy
in interface Expression<E>
copy
in interface Copyable<Expression<E>>
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 final String name()
Expression
name
in interface Expression<E>
assignment
public List<Expression<?>> operands()
Expression
Modifying the returned list will not affect this expression.
operands
in interface Expression<E>
public String toString()
AbstractExpression
toString
in interface Expression<E>
toString
in class AbstractExpression<E>
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |