|
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>
dk.rode.thesis.builder.CountingComparableExpressionBuilder<E>
E
- The Comparable
type of values the constructed expressions
operate on and/or produces.@Participant(value="ConcreteBuilder") public class CountingComparableExpressionBuilder<E extends Comparable<? super 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.
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.AbstractExpressionBuilder |
---|
buildExpression, equals, getContext, getRootExpression, getSequence, hashCode, initialiseExpressions, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public CountingComparableExpressionBuilder(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 CountingExpressionBuilder.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 CountingComparableExpressionBuilder(CountingComparableExpressionBuilder<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 CountingComparableExpressionBuilder(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> buildGreaterThanExpression(Expression<E> first, Expression<E> second)
ComparableExpressionBuilder
buildGreaterThanExpression
in interface ComparableExpressionBuilder<E extends Comparable<? super E>>
first
- The first expression operand; cannot be null.second
- The second expression operand; cannot be null.
public Expression<E> buildSetExpression(Expression<E> value)
ComparableExpressionBuilder
buildSetExpression
in interface ComparableExpressionBuilder<E extends Comparable<? super E>>
value
- The expression that will determine the sequence
value to fast-forward to for the sequence
when the constructed expression is
evaluated.
public Expression<Boolean> buildSmallerThanExpression(Expression<E> first, Expression<E> second)
ComparableExpressionBuilder
buildSmallerThanExpression
in interface ComparableExpressionBuilder<E extends Comparable<? super E>>
first
- The first expression operand; cannot be null.second
- The second expression operand; cannot be null.
public CountingComparableExpressionBuilder<E> copy()
Copyable
copy
in interface Copyable<ExpressionBuilder<E extends Comparable<? super E>>>
copy
in class CountingExpressionBuilder<E extends Comparable<? super E>>
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |