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

dk.rode.thesis.builder
Class StandardExpressionBuilder<E>

java.lang.Object
  extended by dk.rode.thesis.builder.AbstractExpressionBuilder<E>
      extended by dk.rode.thesis.builder.StandardExpressionBuilder<E>
Type Parameters:
E - The type of value the evaluation of constructed expressions produces.
All Implemented Interfaces:
ExpressionBuilder<E>, Copyable<ExpressionBuilder<E>>, StrictCopyable<ExpressionBuilder<E>>
Direct Known Subclasses:
CountingExpressionBuilder, StandardComparableExpressionBuilder

@Participant(value="ConcreteBuilder")
public class StandardExpressionBuilder<E>
extends AbstractExpressionBuilder<E>
implements ExpressionBuilder<E>

A standard expression builder construct various Expression types having no bounds on the values produced by constructed expressions.

The constructed terminal expressions will all manipulate the same sequence instance.

A standard expression builder uses a context to register all unique instances of constructed variables and store all created constants.

Implementation notes:
This builder does not use covariant return types to comply with the canonical "Gang of Four" examples, but the TypedExpressionBuilder class does use covariant return types.

Author:
Gunni Rode / rode.dk
See Also:
ComparableExpressionBuilder

Field Summary
 
Fields inherited from class dk.rode.thesis.builder.AbstractExpressionBuilder
context, root, sequence
 
Constructor Summary
StandardExpressionBuilder(Context context, Sequence<? extends E> sequence)
          Constructor.
StandardExpressionBuilder(Sequence<? extends E> sequence)
          Constructor.
StandardExpressionBuilder(StandardExpressionBuilder<E> builder)
          Copy constructor.
 
Method Summary
 Expression<Boolean> buildAndExpression(Expression<Boolean> first, Expression<Boolean> second)
          Builds a new short-circuit AND expression.
 Expression<E> buildAssignmentExpression(VariableExpression<E> variable, Expression<? extends E> expression)
          Builds a new ASSIGNMENT expression.
 Expression<E> buildBreakExpression(TypedExpression<E> expression)
          Builds a new BREAK expression.
 Expression<E> buildConditionalExpression(Expression<Boolean> condition, Expression<? extends E> first, Expression<? extends E> second)
          Builds a new CONDITIONAL expression.
 Expression<E> buildCurrentExpression()
          Builds a new CURRENT expression.
 Expression<Boolean> buildEqualExpression(Expression<?> first, Expression<?> second)
          Builds a new EQUAL expression.
 FlowExpression<E> buildFlowExpression()
          Builds a new uninitialised FLOW expression.
 Expression<E> buildInitialisedFlowExpression(Expression<? extends E>... expressions)
          Builds a new initialised FLOW expression.
 Expression<E> buildNextExpression(Expression<? extends Number> count)
          Builds a new NEXT expression.
 Expression<Boolean> buildNonShortCircuitAndExpression(Expression<Boolean> first, Expression<Boolean> second)
          Builds a new non short-circuit AND expression.
 Expression<Boolean> buildNonShortCircuitOrExpression(Expression<Boolean> first, Expression<Boolean> second)
          Builds a new non short-circuit OR expression.
 Expression<Boolean> buildNotExpression(Expression<Boolean> expression)
          Builds a new NOT expression.
 Expression<Boolean> buildOrExpression(Expression<Boolean> first, Expression<Boolean> second)
          Builds a new short-circuit OR expression.
 Expression<E> buildResetExpression()
          Builds a new RESET expression.
 Expression<Boolean> buildReverseExpression(Expression<Boolean> reverse)
          Builds a new REVERSE expression.
 StandardExpressionBuilder<E> copy()
          Returns a deep copy of this object.
 
Methods inherited from class dk.rode.thesis.builder.AbstractExpressionBuilder
buildConstantExpression, buildExpression, buildVariableExpression, equals, getContext, getRootExpression, getSequence, hashCode, initialiseExpressions, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface dk.rode.thesis.builder.ExpressionBuilder
buildConstantExpression, buildExpression, buildVariableExpression, getRootExpression, getSequence
 

Constructor Detail

StandardExpressionBuilder

public StandardExpressionBuilder(Context context,
                                 Sequence<? extends E> sequence)
Constructor.

The context supplied as context is used to register created variables and store constants.

Parameters:
context - The context to use; cannot be null.
sequence - The sequence to be manipulated by constructed terminal expressions; cannot be null.
Throws:
NullPointerException - If either argument is null.
See Also:
AbstractExpressionBuilder.getContext()

StandardExpressionBuilder

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

A local context is used to register created variables and store constants.

Parameters:
sequence - The sequence to be manipulated by constructed terminal expressions; cannot be null.
Throws:
NullPointerException - If sequence is null.
See Also:
AbstractExpressionBuilder.getContext()

StandardExpressionBuilder

public StandardExpressionBuilder(StandardExpressionBuilder<E> builder)
Copy constructor.

The same context and sequence as used by builder will be used by this builder.

The root expression from builder is not copied. Hence, this builder is ready to construct new expressions, and return a unique root expression from AbstractExpressionBuilder.getRootExpression().

Parameters:
builder - The builder to copy; cannot be null.
Throws:
NullPointerException - If builder is null.
Method Detail

buildAndExpression

public Expression<Boolean> buildAndExpression(Expression<Boolean> first,
                                              Expression<Boolean> second)
Description copied from interface: ExpressionBuilder
Builds a new short-circuit AND expression.

Specified by:
buildAndExpression in interface ExpressionBuilder<E>
Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.

buildAssignmentExpression

public Expression<E> buildAssignmentExpression(VariableExpression<E> variable,
                                               Expression<? extends E> expression)
Description copied from interface: ExpressionBuilder
Builds a new ASSIGNMENT expression.

Specified by:
buildAssignmentExpression in interface ExpressionBuilder<E>
Parameters:
variable - The variable to be assigned the result of the evaluation of expression; cannot be null, or be a constant.
expression - The expression to deliver the variable value when evaluated; cannot be null.
Returns:
The constructed expression; never null.

buildBreakExpression

public Expression<E> buildBreakExpression(TypedExpression<E> expression)
Description copied from interface: ExpressionBuilder
Builds a new BREAK expression.

Specified by:
buildBreakExpression in interface ExpressionBuilder<E>
Parameters:
expression - The target expression, if any; can be null.
Returns:
The constructed expression; never null.

buildConditionalExpression

public Expression<E> buildConditionalExpression(Expression<Boolean> condition,
                                                Expression<? extends E> first,
                                                Expression<? extends E> second)
Description copied from interface: ExpressionBuilder
Builds a new CONDITIONAL expression.

Specified by:
buildConditionalExpression in interface ExpressionBuilder<E>
Parameters:
condition - The condition expression; cannot be null.
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.

buildCurrentExpression

public Expression<E> buildCurrentExpression()
Description copied from interface: ExpressionBuilder
Builds a new CURRENT expression.

Specified by:
buildCurrentExpression in interface ExpressionBuilder<E>
Returns:
The constructed expression; never null.

buildEqualExpression

public Expression<Boolean> buildEqualExpression(Expression<?> first,
                                                Expression<?> second)
Description copied from interface: ExpressionBuilder
Builds a new EQUAL expression.

Specified by:
buildEqualExpression in interface ExpressionBuilder<E>
Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.

buildFlowExpression

public FlowExpression<E> buildFlowExpression()
Description copied from interface: ExpressionBuilder
Builds a new uninitialised FLOW expression.

Specified by:
buildFlowExpression in interface ExpressionBuilder<E>
Returns:
The constructed expression; never null.

buildInitialisedFlowExpression

public Expression<E> buildInitialisedFlowExpression(Expression<? extends E>... expressions)
                                             throws ExpressionException
Description copied from interface: ExpressionBuilder
Builds a new initialised FLOW expression.

Specified by:
buildInitialisedFlowExpression in interface ExpressionBuilder<E>
Parameters:
expressions - The expressions, in order, to be associated with the returned expression; cannot be null.
Returns:
The constructed expression; never null.
Throws:
ExpressionException - If the building fails.

buildNextExpression

public Expression<E> buildNextExpression(Expression<? extends Number> count)
Description copied from interface: ExpressionBuilder
Builds a new NEXT expression.

Specified by:
buildNextExpression in interface ExpressionBuilder<E>
Parameters:
count - The expression that will determine the number of times next() will be invoked on the sequence when the constructed expression is evaluated.
Returns:
The constructed expression; never null.

buildNonShortCircuitAndExpression

public Expression<Boolean> buildNonShortCircuitAndExpression(Expression<Boolean> first,
                                                             Expression<Boolean> second)
Description copied from interface: ExpressionBuilder
Builds a new non short-circuit AND expression.

Specified by:
buildNonShortCircuitAndExpression in interface ExpressionBuilder<E>
Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.

buildNonShortCircuitOrExpression

public Expression<Boolean> buildNonShortCircuitOrExpression(Expression<Boolean> first,
                                                            Expression<Boolean> second)
Description copied from interface: ExpressionBuilder
Builds a new non short-circuit OR expression.

Specified by:
buildNonShortCircuitOrExpression in interface ExpressionBuilder<E>
Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.

buildNotExpression

public Expression<Boolean> buildNotExpression(Expression<Boolean> expression)
Description copied from interface: ExpressionBuilder
Builds a new NOT expression.

Specified by:
buildNotExpression in interface ExpressionBuilder<E>
Parameters:
expression - The expression operand; cannot be null.
Returns:
The constructed expression; never null.

buildOrExpression

public Expression<Boolean> buildOrExpression(Expression<Boolean> first,
                                             Expression<Boolean> second)
Description copied from interface: ExpressionBuilder
Builds a new short-circuit OR expression.

Specified by:
buildOrExpression in interface ExpressionBuilder<E>
Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.

buildResetExpression

public Expression<E> buildResetExpression()
Description copied from interface: ExpressionBuilder
Builds a new RESET expression.

Specified by:
buildResetExpression in interface ExpressionBuilder<E>
Returns:
The constructed expression; never null.

buildReverseExpression

public Expression<Boolean> buildReverseExpression(Expression<Boolean> reverse)
Description copied from interface: ExpressionBuilder
Builds a new REVERSE expression.

Specified by:
buildReverseExpression in interface ExpressionBuilder<E>
Parameters:
reverse - The expression that will determine if the sequence is tried reversed when the constructed expression is evaluated.
Returns:
The constructed expression; never null.

copy

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

Specified by:
copy in interface Copyable<ExpressionBuilder<E>>
Returns:
The copy; 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.