|
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.Objectdk.rode.thesis.interpreter.AbstractExpression<E>
dk.rode.thesis.interpreter.BinaryExpression<E,E>
dk.rode.thesis.interpreter.ConditionalExpression<E>
E - The type of value the evaluation of this expression
produces.@Participant(value="NonTerminalExpression") public class ConditionalExpression<E>
A conditional expression represents an if-then-else expression.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface dk.rode.thesis.interpreter.Expression |
|---|
Expression.SymbolIdiom |
| Field Summary | |
|---|---|
private Expression<Boolean> |
condition
The condition in form of an expression that returns a Boolean value when evaluated. |
| Fields inherited from class dk.rode.thesis.interpreter.BinaryExpression |
|---|
first, second |
| Constructor Summary | |
|---|---|
ConditionalExpression(ConditionalExpression<E> expression)
Copy constructor. |
|
ConditionalExpression(Expression<Boolean> condition,
Expression<? extends E> first,
Expression<? extends E> second)
Constructor. |
|
| Method Summary | |
|---|---|
String |
asSymbol(Context context)
Returns {@code (c ? |
boolean |
contains(Expression<?> expression)
Returns true if this expression is or contains the expression supplied as expression, false if not. |
ConditionalExpression<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.BinaryExpression |
|---|
asSymbol, asSymbol |
| Methods inherited from class dk.rode.thesis.interpreter.AbstractExpression |
|---|
equals, hashCode |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private final Expression<Boolean> condition
Boolean value when evaluated. Never null.
| Constructor Detail |
|---|
public ConditionalExpression(ConditionalExpression<E> expression)
expression - The expression to copy; cannot be null.
NullPointerException - If expression is null.
public ConditionalExpression(Expression<Boolean> condition,
Expression<? extends E> first,
Expression<? extends E> second)
condition - The condition expression; cannot be null.first - The first expression operand; cannot be null.second - The second expression operand; cannot be null.
NullPointerException - If either expression is null.| Method Detail |
|---|
public String asSymbol(Context context)
throws ExpressionException
(c ? x : y), where c is the symbolic
representation of the condition, x 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 boolean contains(Expression<?> expression)
Expressionexpression, 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>contains in class AbstractExpression<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 ConditionalExpression<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
ExpressionThere 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>conditionalpublic List<Expression<?>> operands()
ExpressionModifying the returned list will not affect this expression.
operands in interface Expression<E>operands in class BinaryExpression<E,E>public String toString()
AbstractExpression
toString in interface Expression<E>toString in class BinaryExpression<E,E>
|
Gunni Rode / rode.dk | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||