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

dk.rode.thesis.interpreter
Class SequenceExpression<T,E>

java.lang.Object
  extended by dk.rode.thesis.interpreter.AbstractExpression<E>
      extended by dk.rode.thesis.interpreter.SequenceExpression<T,E>
Type Parameters:
T - The type of sequence values delivered by the manipulated sequence. Normally, but not required to be, identical with or a sub-type of E.
E - The type of value the evaluation of this expression produces.
All Implemented Interfaces:
Expression<E>, TerminalExpression<E>, Copyable<Expression<E>>, StrictCopyable<Expression<E>>
Direct Known Subclasses:
CurrentExpression, NextExpression, ResetExpression, ReverseExpression, SetExpression

public abstract class SequenceExpression<T,E>
extends AbstractExpression<E>
implements TerminalExpression<E>

A sequence expression represents a terminal expression used to manipulate a given sequence.

When a sequence expression is copied, the manipulated sequence is not copied, but used as is.

Author:
Gunni Rode / rode.dk

Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.rode.thesis.interpreter.Expression
Expression.SymbolIdiom
 
Field Summary
protected  boolean includeHashCode
          True to include the identity hash code of sequence in the symbolic representation, false if not.
protected  Sequence<? extends T> sequence
          The sequence manipulated by this expression.
 
Constructor Summary
protected SequenceExpression(Sequence<? extends T> sequence, boolean includeHashCode)
          Constructor.
protected SequenceExpression(SequenceExpression<? extends T,E> expression)
          Copy constructor.
 
Method Summary
 String asSymbol(Context context)
          Returns name, where name is the actual name of this expression, or name#123, where 123 is the identity hash code of the manipulated sequence.
 boolean equals(Object object)
          Returns true if object is a sequence expression of the same type as this expression manipulating the same sequence using the same operands, false if not.
 int hashCode()
          Returns the hash code of 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
 
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, copy, evaluate, name
 

Field Detail

includeHashCode

protected final boolean includeHashCode
True to include the identity hash code of sequence in the symbolic representation, false if not.

Default false.


sequence

protected final Sequence<? extends T> sequence
The sequence manipulated by this expression.

Never null.

Constructor Detail

SequenceExpression

protected SequenceExpression(Sequence<? extends T> 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.

SequenceExpression

protected SequenceExpression(SequenceExpression<? extends T,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.
Method Detail

asSymbol

public String asSymbol(Context context)
                throws ExpressionException
Returns name, where name is the actual name of this expression, or name#123, where 123 is the identity hash code of the manipulated sequence.

Specified by:
asSymbol in interface Expression<E>
Parameters:
context - The context to use; never null.
Returns:
The symbolic representation; never null.
Throws:
ExpressionException - If the symbol cannot be generated.
See Also:
Expression.contains(Expression)

equals

public boolean equals(Object object)
Returns true if object is a sequence expression of the same type as this expression manipulating the same sequence using the same operands, false if not.

Overrides:
equals in class AbstractExpression<E>
Parameters:
object - The object to test; can be null.
Returns:
True if equal, false if not.

hashCode

public int hashCode()
Returns the hash code of this expression.

Overrides:
hashCode in class AbstractExpression<E>
Returns:
The hash code.

operands

public List<Expression<?>> operands()
Description copied from interface: Expression
Returns the expression operands used by this expression, in order.

Modifying the returned list will not affect this expression.

Specified by:
operands in interface Expression<E>
Returns:
The operands; never null, but can be empty.

toString

public String toString()
Description copied from class: AbstractExpression
Returns the string representation of this expression.

Specified by:
toString in interface Expression<E>
Overrides:
toString in class AbstractExpression<E>
Returns:
The string representation; never null.

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.