|
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.SequenceExpression<E,E> dk.rode.thesis.interpreter.SetExpression<E>
E
- The type of value the evaluation of this expression
produces. The value corresponds to the (super-) type of
values delivered by the manipulated sequence
.@Participant(value="TerminalExpression") public class SetExpression<E extends Comparable<? super E>>
A set expression will fast-forward the value
of a given bounded sequence
to match
a specific value, if possible.
The value to fast-forward to can be a
constant
value, or supplied as an expression
of type Expression<Comparable>
. The
evaluation will fail if no such value can be found at evaluation
time!
Implementation notes:
The value is set by invoking Sequence.next()
until a
matching value is found, or until all sequence values have
been traversed and a match cannot be found, in which case
an exception is thrown. The worst-case running time is thus
proportional to the number of values in the sequence, n,
i.e. O(n).
CurrentExpression
,
NextExpression
,
ResetExpression
,
ReverseExpression
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.interpreter.Expression |
---|
Expression.SymbolIdiom |
Field Summary | |
---|---|
private Expression<E> |
value
The comparable value to set for the sequence. |
Fields inherited from class dk.rode.thesis.interpreter.SequenceExpression |
---|
includeHashCode, sequence |
Constructor Summary | |
---|---|
SetExpression(Sequence<? extends E> sequence,
Class<E> type,
E value)
Constructor. |
|
SetExpression(Sequence<? extends E> sequence,
Class<E> type,
E value,
boolean includeHashCode)
Constructor. |
|
SetExpression(Sequence<? extends E> sequence,
Expression<E> value)
Constructor. |
|
SetExpression(Sequence<? extends E> sequence,
Expression<E> value,
boolean includeHashCode)
Constructor. |
|
SetExpression(SetExpression<E> expression)
Copy constructor. |
Method Summary | |
---|---|
String |
asSymbol(Context context)
Returns set[x] , where x is the symbolic
representation of the expression that will determine the
value, or set#123[x] , where 123 is the
identity hash code of the manipulated sequence. |
SetExpression<E> |
copy()
Returns a deep copy of this object. |
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.SequenceExpression |
---|
equals, hashCode |
Methods inherited from class dk.rode.thesis.interpreter.AbstractExpression |
---|
contains |
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<E extends Comparable<? super E>> value
Never null.
Constructor Detail |
---|
public SetExpression(Sequence<? extends E> sequence, Class<E> type, E value)
The value to fast-forward to is supplied as the
constant value
.
The identity hash code of sequence
is not included
in the symbolic
representation of
this expression.
sequence
- The sequence manipulated by this expression;
cannot be null.type
- The type of value
; cannot be null.value
- The value to fast-forward to;
cannot be null.
NullPointerException
- If either argument is null.
IllegalArgumentException
- If sequence
is not bounded.public SetExpression(Sequence<? extends E> sequence, Class<E> type, E value, boolean includeHashCode)
The value to fast-forward to is supplied as the
constant value
.
The identity hash code of sequence
is included
in the symbolic
representation of
this expression if includeHashCode
is true.
sequence
- The sequence manipulated by this expression;
cannot be null.type
- The type of value
; cannot be null.value
- The value to fast-forward to;
cannot be null.includeHashCode
- True to include the identity hash code
of sequence
in the symbolic
representation, false not to.
NullPointerException
- If sequence
, type
, or value
are null.
IllegalArgumentException
- If sequence
is not bounded.public SetExpression(Sequence<? extends E> sequence, Expression<E> value)
The identity hash code of sequence
is not included
in the symbolic
representation of
this expression.
sequence
- The sequence manipulated by this expression;
cannot be null.value
- The expression that will determine the value to
fast-forward to for sequence
;
cannot be null.
NullPointerException
- If either argument is null.
IllegalArgumentException
- If sequence
is not bounded.public SetExpression(Sequence<? extends E> sequence, Expression<E> value, boolean includeHashCode)
The identity hash code of sequence
is included
in the symbolic
representation of
this expression if includeHashCode
is true.
sequence
- The sequence manipulated by this expression;
cannot be null.value
- The expression that will determine the value to
fast-forward to for sequence
;
cannot be null.includeHashCode
- True to include the identity hash code
of sequence
in the symbolic
representation, false not to.
NullPointerException
- If sequence
or value
are null.
IllegalArgumentException
- If sequence
is not bounded.public SetExpression(SetExpression<E> expression)
The actual sequence
manipulated by
expression
is not copied, but used
as is.
expression
- The expression to copy; cannot be null.
NullPointerException
- If expression
is null.Method Detail |
---|
public String asSymbol(Context context) throws ExpressionException
set[x]
, where x
is the symbolic
representation of the expression that will determine the
value, or set#123[x]
, where 123
is the
identity hash code of the manipulated sequence.
asSymbol
in interface Expression<E extends Comparable<? super E>>
asSymbol
in class SequenceExpression<E extends Comparable<? super E>,E extends Comparable<? super E>>
context
- The context to use; never null.
ExpressionException
- If the symbol cannot be generated.Expression.contains(Expression)
public SetExpression<E> copy()
Copyable
public E evaluate(Context context) throws ExpressionException
Expression
There is no guarantee that the evaluation of this expression will terminate!
context
- The context to use; cannot be null.
ExpressionException
- If the value to fast-forward
to cannot be matched to a sequence value.public final String name()
Expression
set
public List<Expression<?>> operands()
Expression
Modifying the returned list will not affect this expression.
operands
in interface Expression<E extends Comparable<? super E>>
operands
in class SequenceExpression<E extends Comparable<? super E>,E extends Comparable<? super E>>
public String toString()
AbstractExpression
toString
in interface Expression<E extends Comparable<? super E>>
toString
in class SequenceExpression<E extends Comparable<? super E>,E extends Comparable<? super E>>
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |