|
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,Boolean> dk.rode.thesis.interpreter.ReverseExpression<E>
E
- The (super-) type of values delivered by the manipulated
sequence
.@Participant(value="TerminalExpression") public class ReverseExpression<E>
A reverse expression will invoke
reverse()
on a given reversible
sequence when
evaluated, if so specified and only if possible.
In order to reverse the sequence, the sequence must
not only be reversible
,
but an expression can also be supplied
to determine whether or not to reverse at evaluation time.
Any expression of the type Expression<Boolean>
can be used.
CurrentExpression
,
NextExpression
,
SetExpression
,
ResetExpression
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.interpreter.Expression |
---|
Expression.SymbolIdiom |
Field Summary | |
---|---|
private Expression<Boolean> |
reverse
If this expression evaluates to true, the sequence will be tried reversed, not if it evaluates to false. |
Fields inherited from class dk.rode.thesis.interpreter.SequenceExpression |
---|
includeHashCode, sequence |
Constructor Summary | |
---|---|
ReverseExpression(ReverseExpression<E> expression)
Copy constructor. |
|
ReverseExpression(Sequence<? extends E> sequence)
Constructor. |
|
ReverseExpression(Sequence<? extends E> sequence,
boolean reverse)
Constructor. |
|
ReverseExpression(Sequence<? extends E> sequence,
boolean reverse,
boolean includeHashCode)
Constructor. |
|
ReverseExpression(Sequence<? extends E> sequence,
Expression<Boolean> reverse)
Constructor. |
|
ReverseExpression(Sequence<? extends E> sequence,
Expression<Boolean> reverse,
boolean includeHashCode)
Constructor. |
Method Summary | |
---|---|
String |
asSymbol(Context context)
Returns reverse[x] , where x is the symbolic
representation of the expression used to determine if the
sequence should be reversed, or reverse#123[x] ,
where 123 is the identity hash code of the
manipulated sequence. |
ReverseExpression<E> |
copy()
Returns a deep copy of this object. |
Boolean |
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<Boolean> reverse
Constructor Detail |
---|
public ReverseExpression(ReverseExpression<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.public ReverseExpression(Sequence<? extends E> sequence)
This expression will try and reverse sequence
.
The identity hash code of sequence
is not included
in the symbolic
representation of
this expression.
sequence
- The sequence to manipulate by this expression;
cannot be null.
NullPointerException
- If sequence
is null.public ReverseExpression(Sequence<? extends E> sequence, boolean reverse)
This expression will try and reverse sequence
if
reverse
is true, not if false (no-op).
The identity hash code of sequence
is not included
in the symbolic
representation of
this expression.
sequence
- The sequence to manipulate by this expression;
cannot be null.reverse
- True to try and reverse sequence
,
false not to (no-op).
NullPointerException
- If sequence
is null.public ReverseExpression(Sequence<? extends E> sequence, boolean reverse, boolean includeHashCode)
This expression will try and reverse sequence
if
reverse
is true, not if false (no-op).
The identity hash code of sequence
is included
in the symbolic
representation of
this expression if includeHashCode
is true.
sequence
- The sequence to manipulate by this expression;
cannot be null.reverse
- True to try and reverse sequence
,
false not to (no-op).includeHashCode
- True to include the identity hash code
of sequence
in the symbolic
representation, false not to.
NullPointerException
- If sequence
is null.public ReverseExpression(Sequence<? extends E> sequence, Expression<Boolean> reverse)
This expression will try and reverse sequence
if
reverse
evaluates to true when this expression is
evaluated.
The identity hash code of sequence
is not included
in the symbolic
representation of
this expression.
sequence
- The sequence to manipulate by this expression;
cannot be null.reverse
- The expression that will determine if sequence
is tried reversed when this expression is evaluated.
NullPointerException
- If either argument is null.public ReverseExpression(Sequence<? extends E> sequence, Expression<Boolean> reverse, boolean includeHashCode)
This expression will try and reverse sequence
if
reverse
evaluates to true when this expression is
evaluated.
The identity hash code of sequence
is included
in the symbolic
representation of
this expression if includeHashCode
is true.
sequence
- The sequence to manipulate by this expression;
cannot be null.reverse
- The expression that will determine if sequence
is tried reversed when this expression is evaluated.includeHashCode
- True to include the identity hash code
of sequence
in the symbolic
representation, false not to.
NullPointerException
- If sequence
or reverse
are null.Method Detail |
---|
public String asSymbol(Context context) throws ExpressionException
reverse[x]
, where x
is the symbolic
representation of the expression used to determine if the
sequence should be reversed, or reverse#123[x]
,
where 123
is the identity hash code of the
manipulated sequence.
asSymbol
in interface Expression<Boolean>
asSymbol
in class SequenceExpression<E,Boolean>
context
- The context to use; never null.
ExpressionException
- If the symbol cannot be generated.Expression.contains(Expression)
public ReverseExpression<E> copy()
Copyable
public Boolean 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 evaluation fails.ReversibleSequence.reverse()
public final String name()
Expression
reverse
public List<Expression<?>> operands()
Expression
Modifying the returned list will not affect this expression.
operands
in interface Expression<Boolean>
operands
in class SequenceExpression<E,Boolean>
public String toString()
AbstractExpression
toString
in interface Expression<Boolean>
toString
in class SequenceExpression<E,Boolean>
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |