|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectdk.rode.thesis.builder.AbstractExpressionBuilder<E>
dk.rode.thesis.builder.StandardExpressionBuilder<E>
dk.rode.thesis.builder.CountingExpressionBuilder<E>
E - The type of value the evaluation of constructed
expressions produces.@Participant(value="ConcreteBuilder") public class CountingExpressionBuilder<E>
A counting 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 getExpressionCount()
method.
Implementation notes:
Due to inheritance of the StandardExpressionBuilder, covariant
return types of the precise types of created expressions cannot
be made without casting to explicit types, for example to
NextExpression. This is not always possible if the
implementing types are hidden.
The counts per expression type could easily have been stored in a map instead, but by using the context, we at the same time utilise the functionality exposed by it.
Counting functionality inspired by the Gamma et al. example in [Gamma95, p.104].
CountingComparableExpressionBuilder| Field Summary | |
|---|---|
static String |
PREFIX
The prefix used for all variables storing a count for a given expression type. |
| Fields inherited from class dk.rode.thesis.builder.AbstractExpressionBuilder |
|---|
context, root, sequence |
| Constructor Summary | |
|---|---|
CountingExpressionBuilder(Context context,
Sequence<? extends E> sequence)
Constructor. |
|
CountingExpressionBuilder(CountingExpressionBuilder<E> builder)
Copy constructor. |
|
CountingExpressionBuilder(Sequence<? extends E> sequence)
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. |
|
|
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. |
|
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. |
|
|
buildVariableExpression(Class<V> type,
String name)
Builds a new VARIABLE expression. |
|
CountingExpressionBuilder<E> |
copy()
Returns a deep copy of this object. |
|
protected
|
count(W expression)
Updates the number of times this builder has seen an expression with the same name as expression. |
|
Map<String,Integer> |
getExpressionCount()
Returns a map containing as values the number of times a given expression type has been created, excluding the count for the root
expression. |
|
| 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 |
|---|
buildExpression, getRootExpression, getSequence |
| Field Detail |
|---|
public static final String PREFIX
The value is count., including the dot (.).
| Constructor Detail |
|---|
public CountingExpressionBuilder(Context context,
Sequence<? extends E> sequence)
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 PREFIX, this may affect
the counting performed by this builder (see the class documentation)!
context - The context to use; cannot be null.sequence - The sequence to be manipulated by constructed
terminal expressions; cannot be null.
NullPointerException - If either argument is null.AbstractExpressionBuilder.getContext()public CountingExpressionBuilder(CountingExpressionBuilder<E> builder)
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().
builder - The builder to copy; cannot be null.
NullPointerException - If builder is null.public CountingExpressionBuilder(Sequence<? extends E> sequence)
A local context is used to register created
variables and store
constants.
sequence - The sequence to be manipulated by constructed
terminal expressions; cannot be null.
NullPointerException - If sequence is null.AbstractExpressionBuilder.getContext()| Method Detail |
|---|
public Expression<Boolean> buildAndExpression(Expression<Boolean> first,
Expression<Boolean> second)
ExpressionBuilder
buildAndExpression in interface ExpressionBuilder<E>buildAndExpression in class StandardExpressionBuilder<E>first - The first expression operand; cannot be null.second - The second expression operand; cannot be null.
public Expression<E> buildAssignmentExpression(VariableExpression<E> variable,
Expression<? extends E> expression)
ExpressionBuilder
buildAssignmentExpression in interface ExpressionBuilder<E>buildAssignmentExpression in class StandardExpressionBuilder<E>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.
public Expression<E> buildBreakExpression(TypedExpression<E> expression)
ExpressionBuilder
buildBreakExpression in interface ExpressionBuilder<E>buildBreakExpression in class StandardExpressionBuilder<E>expression - The target expression, if any; can be null.
public Expression<E> buildConditionalExpression(Expression<Boolean> condition,
Expression<? extends E> first,
Expression<? extends E> second)
ExpressionBuilder
buildConditionalExpression in interface ExpressionBuilder<E>buildConditionalExpression in class StandardExpressionBuilder<E>condition - The condition expression; cannot be null.first - The first expression operand; cannot be null.second - The second expression operand; cannot be null.
public <V> Expression<V> buildConstantExpression(Class<V> type,
V value)
throws ExpressionException
ExpressionBuilder
buildConstantExpression in interface ExpressionBuilder<E>buildConstantExpression in class AbstractExpressionBuilder<E>V - The type of value the constructed expression
produces.type - The type of the constant represented by the
constructed expression; cannot be null.value - The value of the constant; cannot be null.
ExpressionException - If the building fails.public Expression<E> buildCurrentExpression()
ExpressionBuilder
buildCurrentExpression in interface ExpressionBuilder<E>buildCurrentExpression in class StandardExpressionBuilder<E>
public Expression<Boolean> buildEqualExpression(Expression<?> first,
Expression<?> second)
ExpressionBuilder
buildEqualExpression in interface ExpressionBuilder<E>buildEqualExpression in class StandardExpressionBuilder<E>first - The first expression operand; cannot be null.second - The second expression operand; cannot be null.
public FlowExpression<E> buildFlowExpression()
ExpressionBuilderuninitialised
FLOW expression.
buildFlowExpression in interface ExpressionBuilder<E>buildFlowExpression in class StandardExpressionBuilder<E>
public Expression<E> buildInitialisedFlowExpression(Expression<? extends E>... expressions)
throws ExpressionException
ExpressionBuilderinitialised
FLOW expression.
buildInitialisedFlowExpression in interface ExpressionBuilder<E>buildInitialisedFlowExpression in class StandardExpressionBuilder<E>expressions - The expressions, in order, to be
associated with the returned expression;
cannot be null.
ExpressionException - If the building fails.public Expression<E> buildNextExpression(Expression<? extends Number> count)
ExpressionBuilder
buildNextExpression in interface ExpressionBuilder<E>buildNextExpression in class StandardExpressionBuilder<E>count - The expression that will determine the number
of times next() will be invoked on
the sequence when the
constructed expression is evaluated.
public Expression<Boolean> buildNonShortCircuitAndExpression(Expression<Boolean> first,
Expression<Boolean> second)
ExpressionBuilder
buildNonShortCircuitAndExpression in interface ExpressionBuilder<E>buildNonShortCircuitAndExpression in class StandardExpressionBuilder<E>first - The first expression operand; cannot be null.second - The second expression operand; cannot be null.
public Expression<Boolean> buildNonShortCircuitOrExpression(Expression<Boolean> first,
Expression<Boolean> second)
ExpressionBuilder
buildNonShortCircuitOrExpression in interface ExpressionBuilder<E>buildNonShortCircuitOrExpression in class StandardExpressionBuilder<E>first - The first expression operand; cannot be null.second - The second expression operand; cannot be null.
public Expression<Boolean> buildNotExpression(Expression<Boolean> expression)
ExpressionBuilder
buildNotExpression in interface ExpressionBuilder<E>buildNotExpression in class StandardExpressionBuilder<E>expression - The expression operand; cannot be null.
public Expression<Boolean> buildOrExpression(Expression<Boolean> first,
Expression<Boolean> second)
ExpressionBuilder
buildOrExpression in interface ExpressionBuilder<E>buildOrExpression in class StandardExpressionBuilder<E>first - The first expression operand; cannot be null.second - The second expression operand; cannot be null.
public Expression<E> buildResetExpression()
ExpressionBuilder
buildResetExpression in interface ExpressionBuilder<E>buildResetExpression in class StandardExpressionBuilder<E>public Expression<Boolean> buildReverseExpression(Expression<Boolean> reverse)
ExpressionBuilder
buildReverseExpression in interface ExpressionBuilder<E>buildReverseExpression in class StandardExpressionBuilder<E>reverse - The expression that will determine if the
sequence is tried
reversed when the constructed expression is
evaluated.
public <V> VariableExpression<V> buildVariableExpression(Class<V> type,
String name)
throws ExpressionException
ExpressionBuilder
buildVariableExpression in interface ExpressionBuilder<E>buildVariableExpression in class AbstractExpressionBuilder<E>V - The type of value the constructed expression
produces.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.
ExpressionException - If the building fails.public CountingExpressionBuilder<E> copy()
Copyable
copy in interface Copyable<ExpressionBuilder<E>>copy in class StandardExpressionBuilder<E>protected <V,W extends Expression<V>> W count(W expression)
name as expression.
The count per expression name is stored in the context used, prefixed with count..
V - The type of value the evaluation of expression produces.W - The actual type of expression.expression - The expression to increase the count for; cannot be null.
expression; never null.
NullPointerException - If expression is null.
public Map<String,Integer> getExpressionCount()
throws ExpressionException
root
expression.
The keys correspond to an expression name.
ExpressionException - If the generation of the map fails.
|
Gunni Rode / rode.dk | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||