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

dk.rode.thesis.builder
Interface ExpressionBuilder<E>

Type Parameters:
E - The main type of values the constructed expressions operate on and/or produces.
All Superinterfaces:
Copyable<ExpressionBuilder<E>>, StrictCopyable<ExpressionBuilder<E>>
All Known Subinterfaces:
ComparableExpressionBuilder<E>
All Known Implementing Classes:
AbstractExpressionBuilder, CountingComparableExpressionBuilder, CountingExpressionBuilder, StandardComparableExpressionBuilder, StandardExpressionBuilder, TypedComparableExpressionBuilder, TypedExpressionBuilder

@ParticipantUsage(value="Product",
                  type=Expression.class)
@Participant(value="Builder")
public interface ExpressionBuilder<E>
extends StrictCopyable<ExpressionBuilder<E>>

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

The constructed root expression can be fetched using the getRootExpression() method, and expressions can be added to it using the buildExpression(Expression) method.

Author:
Gunni Rode / rode.dk

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.
<V> Expression<V>
buildConstantExpression(Class<V> type, V value)
          Builds a new CONSTANT expression.
 Expression<E> buildCurrentExpression()
          Builds a new CURRENT expression.
 Expression<Boolean> buildEqualExpression(Expression<?> first, Expression<?> second)
          Builds a new EQUAL expression.
 void buildExpression(Expression<? extends E> expression)
          Adds the constructed expression supplied as expression to the root expression constructed by this builder.
 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.
<V> VariableExpression<V>
buildVariableExpression(Class<V> type, String name)
          Builds a new VARIABLE expression.
 Expression<E> getRootExpression()
          Returns the root expression constructed by this builder.
 Sequence<? extends E> getSequence()
          Returns the sequence manipulated by the terminal expressions constructed by this builder.
 
Methods inherited from interface dk.rode.thesis.prototype.Copyable
copy
 

Method Detail

buildAndExpression

Expression<Boolean> buildAndExpression(Expression<Boolean> first,
                                       Expression<Boolean> second)
Builds a new short-circuit AND expression.

Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.
Throws:
NullPointerException - If either expression is null.

buildAssignmentExpression

Expression<E> buildAssignmentExpression(VariableExpression<E> variable,
                                        Expression<? extends E> expression)
Builds a new ASSIGNMENT expression.

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.
Throws:
NullPointerException - If either argument is null.
IllegalArgumentException - If variable is a constant.

buildBreakExpression

Expression<E> buildBreakExpression(TypedExpression<E> expression)
Builds a new BREAK expression.

Parameters:
expression - The target expression, if any; can be null.
Returns:
The constructed expression; never null.

buildConditionalExpression

Expression<E> buildConditionalExpression(Expression<Boolean> condition,
                                         Expression<? extends E> first,
                                         Expression<? extends E> second)
Builds a new CONDITIONAL expression.

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.
Throws:
NullPointerException - If either expression is null.

buildConstantExpression

<V> Expression<V> buildConstantExpression(Class<V> type,
                                          V value)
                                      throws ExpressionException
Builds a new CONSTANT expression.

Type Parameters:
V - The type of value the constructed expression produces.
Parameters:
type - The type of the constant represented by the constructed expression; cannot be null.
value - The value of the constant; cannot be null.
Returns:
The constructed expression; never null.
Throws:
NullPointerException - If either expression is null.
ExpressionException - If the building fails.

buildCurrentExpression

Expression<E> buildCurrentExpression()
Builds a new CURRENT expression.

Returns:
The constructed expression; never null.

buildEqualExpression

Expression<Boolean> buildEqualExpression(Expression<?> first,
                                         Expression<?> second)
Builds a new EQUAL expression.

Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.
Throws:
NullPointerException - If either expression is null.

buildExpression

void buildExpression(Expression<? extends E> expression)
                     throws ExpressionException
Adds the constructed expression supplied as expression to the root expression constructed by this builder.

If expression is initialisable but not initialised, it will be initialised when the root expression is returned.

Parameters:
expression - The expression to add; cannot be null.
Throws:
NullPointerException - If expression is null.
ExpressionException - If the adding fails in case the root expression has already been fetched.

buildFlowExpression

FlowExpression<E> buildFlowExpression()
Builds a new uninitialised FLOW expression.

Returns:
The constructed expression; never null.

buildInitialisedFlowExpression

Expression<E> buildInitialisedFlowExpression(Expression<? extends E>... expressions)
                                             throws ExpressionException
Builds a new initialised FLOW expression.

Parameters:
expressions - The expressions, in order, to be associated with the returned expression; cannot be null.
Returns:
The constructed expression; never null.
Throws:
NullPointerException - If expressions is null, or contain a null entry.
ExpressionException - If the building fails.

buildNextExpression

Expression<E> buildNextExpression(Expression<? extends Number> count)
Builds a new NEXT expression.

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.
Throws:
NullPointerException - If count is null.

buildNonShortCircuitAndExpression

Expression<Boolean> buildNonShortCircuitAndExpression(Expression<Boolean> first,
                                                      Expression<Boolean> second)
Builds a new non short-circuit AND expression.

Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.
Throws:
NullPointerException - If either expression is null.

buildNonShortCircuitOrExpression

Expression<Boolean> buildNonShortCircuitOrExpression(Expression<Boolean> first,
                                                     Expression<Boolean> second)
Builds a new non short-circuit OR expression.

Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.
Throws:
NullPointerException - If either expression is null.

buildNotExpression

Expression<Boolean> buildNotExpression(Expression<Boolean> expression)
Builds a new NOT expression.

Parameters:
expression - The expression operand; cannot be null.
Returns:
The constructed expression; never null.
Throws:
NullPointerException - If expression is null.

buildOrExpression

Expression<Boolean> buildOrExpression(Expression<Boolean> first,
                                      Expression<Boolean> second)
Builds a new short-circuit OR expression.

Parameters:
first - The first expression operand; cannot be null.
second - The second expression operand; cannot be null.
Returns:
The constructed expression; never null.
Throws:
NullPointerException - If either expression is null.

buildResetExpression

Expression<E> buildResetExpression()
Builds a new RESET expression.

Returns:
The constructed expression; never null.

buildReverseExpression

Expression<Boolean> buildReverseExpression(Expression<Boolean> reverse)
Builds a new REVERSE expression.

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.
Throws:
NullPointerException - If reverse is null.

buildVariableExpression

<V> VariableExpression<V> buildVariableExpression(Class<V> type,
                                                  String name)
                                              throws ExpressionException
Builds a new VARIABLE expression.

Type Parameters:
V - The type of value the constructed expression produces.
Parameters:
type - The type of the value represented by the constructed expression; cannot be null.
name - The name of the constructed expression; cannot be null or empty.
Returns:
The constructed expression; never null.
Throws:
NullPointerException - If either argument is null.
IllegalArgumentException - If name is illegal.
ExpressionException - If the building fails.

getRootExpression

Expression<E> getRootExpression()
                                throws ExpressionException
Returns the root expression constructed by this builder.

Expressions are added to the root expression using the buildExpression(Expression) method. Once the root expression has been returned once, additional expressions cannot be added to it!

All initialisable expressions contained in the root expression will have been initialised, if not already.

Returns:
The root expression, completely initialised; never null.
Throws:
ExpressionException - If the initialisation fails.

getSequence

Sequence<? extends E> getSequence()
Returns the sequence manipulated by the terminal expressions constructed by this builder.

Returns:
The sequence; 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.