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

dk.rode.thesis.builder
Class CountingComparableExpressionBuilder<E extends Comparable<? super E>>

java.lang.Object
  extended by dk.rode.thesis.builder.AbstractExpressionBuilder<E>
      extended by dk.rode.thesis.builder.StandardExpressionBuilder<E>
          extended by dk.rode.thesis.builder.CountingExpressionBuilder<E>
              extended by dk.rode.thesis.builder.CountingComparableExpressionBuilder<E>
Type Parameters:
E - The Comparable type of values the constructed expressions operate on and/or produces.
All Implemented Interfaces:
ComparableExpressionBuilder<E>, ExpressionBuilder<E>, Copyable<ExpressionBuilder<E>>, StrictCopyable<ExpressionBuilder<E>>

@Participant(value="ConcreteBuilder")
public class CountingComparableExpressionBuilder<E extends Comparable<? super E>>
extends CountingExpressionBuilder<E>
implements ComparableExpressionBuilder<E>

A counting comparable expression builder performs the same functionality as a standard expression builder, but also registers the number of times each expression type is created based on expression names.

The count per expression name is stored in the context used, prefixed with count., for example count.next for NextExpression. The counts can also be directly fetched using the CountingExpressionBuilder.getExpressionCount() method.

Implementation notes:
Since Java does not support multiple functional inheritance, this class cannot inherit both CountingExpressionBuilder and ComparableExpressionBuilder. As most of the functionality is implemented in CountingExpressionBuilder, this is the class chosen to inherit. The missing build-methods (only 3) thus has to create expressions themselves and not rely on the super class to perform the construction.

Author:
Gunni Rode / rode.dk

Field Summary
 
Fields inherited from class dk.rode.thesis.builder.CountingExpressionBuilder
PREFIX
 
Fields inherited from class dk.rode.thesis.builder.AbstractExpressionBuilder
context, root, sequence
 
Constructor Summary
CountingComparableExpressionBuilder(Context context, Sequence<? extends E> sequence)
          Constructor.
CountingComparableExpressionBuilder(CountingComparableExpressionBuilder<E> builder)
          Copy constructor.
CountingComparableExpressionBuilder(Sequence<? extends E> sequence)
          Constructor.
 
Method Summary
 Expression<Boolean> buildGreaterThanExpression(Expression<E> first, Expression<E> second)
          Builds a new GREATER THAN expression.
 Expression<E> buildSetExpression(Expression<E> value)
          Builds a new SET expression.
 Expression<Boolean> buildSmallerThanExpression(Expression<E> first, Expression<E> second)
          Builds a new SMALLER THAN expression.
 CountingComparableExpressionBuilder<E> copy()
          Returns a deep copy of this object.
 
Methods inherited from class dk.rode.thesis.builder.CountingExpressionBuilder
buildAndExpression, buildAssignmentExpression, buildBreakExpression, buildConditionalExpression, buildConstantExpression, buildCurrentExpression, buildEqualExpression, buildFlowExpression, buildInitialisedFlowExpression, buildNextExpression, buildNonShortCircuitAndExpression, buildNonShortCircuitOrExpression, buildNotExpression, buildOrExpression, buildResetExpression, buildReverseExpression, buildVariableExpression, count, getExpressionCount
 
Methods inherited from class dk.rode.thesis.builder.AbstractExpressionBuilder
buildExpression, 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
buildAndExpression, buildAssignmentExpression, buildBreakExpression, buildConditionalExpression, buildConstantExpression, buildCurrentExpression, buildEqualExpression, buildExpression, buildFlowExpression, buildInitialisedFlowExpression, buildNextExpression, buildNonShortCircuitAndExpression, buildNonShortCircuitOrExpression, buildNotExpression, buildOrExpression, buildResetExpression, buildReverseExpression, buildVariableExpression, getRootExpression, getSequence
 

Constructor Detail

CountingComparableExpressionBuilder

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

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

Note, that in case context has variables registered with names prefixed with CountingExpressionBuilder.PREFIX, this may affect the counting performed by this builder (see the class documentation)!

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()

CountingComparableExpressionBuilder

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

The same sequence as used by builder will be used by this builder, but a new context will be created and used. Hence, all counts are cleared.

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.

CountingComparableExpressionBuilder

public CountingComparableExpressionBuilder(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()
Method Detail

buildGreaterThanExpression

public Expression<Boolean> buildGreaterThanExpression(Expression<E> first,
                                                      Expression<E> second)
Description copied from interface: ComparableExpressionBuilder
Builds a new GREATER THAN expression.

Specified by:
buildGreaterThanExpression in interface ComparableExpressionBuilder<E extends Comparable<? super E>>
Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.

buildSetExpression

public Expression<E> buildSetExpression(Expression<E> value)
Description copied from interface: ComparableExpressionBuilder
Builds a new SET expression.

Specified by:
buildSetExpression in interface ComparableExpressionBuilder<E extends Comparable<? super E>>
Parameters:
value - The expression that will determine the sequence value to fast-forward to for the sequence when the constructed expression is evaluated.
Returns:
The constructed expression; never null.

buildSmallerThanExpression

public Expression<Boolean> buildSmallerThanExpression(Expression<E> first,
                                                      Expression<E> second)
Description copied from interface: ComparableExpressionBuilder
Builds a new SMALLER THAN expression.

Specified by:
buildSmallerThanExpression in interface ComparableExpressionBuilder<E extends Comparable<? super E>>
Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.

copy

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

Specified by:
copy in interface Copyable<ExpressionBuilder<E extends Comparable<? super E>>>
Overrides:
copy in class CountingExpressionBuilder<E extends Comparable<? super 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.