Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.interpreter
Class CurrentExpression<E>

java.lang.Object
  extended by dk.rode.thesis.interpreter.AbstractExpression<E>
      extended by dk.rode.thesis.interpreter.SequenceExpression<E,E>
          extended by dk.rode.thesis.interpreter.CurrentExpression<E>
Type Parameters:
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.
All Implemented Interfaces:
Expression<E>, TerminalExpression<E>, Copyable<Expression<E>>, StrictCopyable<Expression<E>>

@Participant(value="TerminalExpression")
public class CurrentExpression<E>
extends SequenceExpression<E,E>

A current expression will invoke current() on a given sequence when evaluated.

Author:
Gunni Rode / rode.dk
See Also:
NextExpression, SetExpression, ResetExpression, ReverseExpression

Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.rode.thesis.interpreter.Expression
Expression.SymbolIdiom
 
Field Summary
 
Fields inherited from class dk.rode.thesis.interpreter.SequenceExpression
includeHashCode, sequence
 
Constructor Summary
CurrentExpression(CurrentExpression<E> expression)
          Copy constructor.
CurrentExpression(Sequence<? extends E> sequence)
          Constructor.
CurrentExpression(Sequence<? extends E> sequence, boolean includeHashCode)
          Constructor.
 
Method Summary
 CurrentExpression<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.
 
Methods inherited from class dk.rode.thesis.interpreter.SequenceExpression
asSymbol, equals, hashCode, operands, toString
 
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
 

Constructor Detail

CurrentExpression

public CurrentExpression(CurrentExpression<E> expression)
Copy constructor.

The actual sequence manipulated by expression is not copied, but used as is.

Parameters:
expression - The expression to copy; cannot be null.
Throws:
NullPointerException - If expression is null.

CurrentExpression

public CurrentExpression(Sequence<? extends E> sequence)
Constructor.

The identity hash code of sequence is not included in the symbolic representation of this expression.

Parameters:
sequence - The sequence to manipulate by this expression; cannot be null.
Throws:
NullPointerException - If sequence is null.

CurrentExpression

public CurrentExpression(Sequence<? extends E> sequence,
                         boolean includeHashCode)
Constructor.

The identity hash code of sequence is included in the symbolic representation of this expression if includeHashCode is true.

Parameters:
sequence - The sequence to manipulate by this expression; cannot be null.
includeHashCode - True to include the identity hash code of sequence in the symbolic representation, false not to.
Throws:
NullPointerException - If sequence is null.
Method Detail

copy

public CurrentExpression<E> copy()
Description copied from interface: Copyable
Returns a deep copy of this object.

Returns:
The copy; never null.

evaluate

public E evaluate(Context context)
           throws ExpressionException
Description copied from interface: Expression
Evaluates this expression and returns the result.

There is no guarantee that the evaluation of this expression will terminate!

Parameters:
context - The context to use; cannot be null.
Returns:
The result of the evaluation; never null.
Throws:
ExpressionException - If the evaluation fails.
See Also:
Sequence.current()

name

public final String name()
Description copied from interface: Expression
The stand-alone symbol name for this expression.

Returns:
current

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.