|
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.Object dk.rode.thesis.builder.AbstractExpressionBuilder<E>
E
- The type of value the evaluation of constructed
expressions produces.@Participant(value="Builder") public abstract class AbstractExpressionBuilder<E>
An abstract expression builder implements the basic
traits of the ExpressionBuilder
interface, while
ensuring that the constructed terminal
expressions will all manipulate the same sequence
instance.
Any builder inheriting this class furthermore uses a context
to register all unique instances of constructed variables
and store all created constants
.
Implementation notes:
The initialiseExpressions(Expression)
method is a
visitation method used to visit all expressions in the
expression syntax-tree. See also the
Visitor
pattern.
Field Summary | |
---|---|
protected Context |
context
The context used to register created variables and
store created constants . |
protected FlowExpression<E> |
root
The root expression returned by getRootExpression() . |
protected Sequence<? extends E> |
sequence
The sequence manipulated by terminal
expressions. |
Constructor Summary | |
---|---|
AbstractExpressionBuilder(AbstractExpressionBuilder<E> builder)
Copy constructor. |
|
AbstractExpressionBuilder(Context context,
Sequence<? extends E> sequence)
Constructor. |
|
AbstractExpressionBuilder(Sequence<? extends E> sequence)
Constructor. |
Method Summary | ||
---|---|---|
|
buildConstantExpression(Class<V> type,
V value)
Builds a new CONSTANT expression. |
|
void |
buildExpression(Expression<? extends E> expression)
Adds the constructed expression supplied
as expression to the root
expression constructed by this builder. |
|
|
buildVariableExpression(Class<V> type,
String name)
Builds a new VARIABLE expression. |
|
boolean |
equals(Object object)
Returns true if object is an instance of this
class and uses the same sequence as
this builder, false if not. |
|
Context |
getContext()
Return the context used by this
builder. |
|
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. |
|
int |
hashCode()
Returns the hash code of this builder. |
|
protected static
|
initialiseExpressions(Expression<V> expression)
Initialises all initialisable expressions
reachable from the expression supplied as expression that has
not already been initialised. |
|
String |
toString()
Returns the string representation of this builder. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface dk.rode.thesis.prototype.Copyable |
---|
copy |
Field Detail |
---|
protected final Context context
variables
and
store created constants
. Never null.
protected final FlowExpression<E> root
getRootExpression()
. Never null.
protected final Sequence<? extends E> sequence
sequence
manipulated by terminal
expressions. Never null.
Constructor Detail |
---|
public AbstractExpressionBuilder(AbstractExpressionBuilder<E> builder)
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 getRootExpression()
.
builder
- The builder to copy; cannot be null.
NullPointerException
- If builder
is null.public AbstractExpressionBuilder(Context context, Sequence<? extends E> sequence)
The context
supplied as context
is
used to register created variables
and store constants
.
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.getContext()
public AbstractExpressionBuilder(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.getContext()
Method Detail |
---|
public <V> Expression<V> buildConstantExpression(Class<V> type, V value) throws ExpressionException
ExpressionBuilder
buildConstantExpression
in interface ExpressionBuilder<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 void buildExpression(Expression<? extends E> expression) throws ExpressionException
ExpressionBuilder
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.
buildExpression
in interface ExpressionBuilder<E>
expression
- The expression to add; cannot be null.
ExpressionException
- If the adding fails in case the
root expression has already been fetched.public <V> VariableExpression<V> buildVariableExpression(Class<V> type, String name) throws ExpressionException
ExpressionBuilder
buildVariableExpression
in interface ExpressionBuilder<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 boolean equals(Object object)
object
is an instance of this
class and uses the same sequence
as
this builder, false if not.
equals
in class Object
object
- The object to test; can be null.
public Context getContext()
context
used by this
builder.
public Expression<E> getRootExpression() throws ExpressionException
ExpressionBuilder
Expressions are added to the root expression using the
ExpressionBuilder.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.
getRootExpression
in interface ExpressionBuilder<E>
ExpressionException
- If the initialisation fails.public Sequence<? extends E> getSequence()
ExpressionBuilder
sequence
manipulated by the
terminal expressions constructed by this builder.
getSequence
in interface ExpressionBuilder<E>
public int hashCode()
hashCode
in class Object
protected static <V> Expression<V> initialiseExpressions(Expression<V> expression) throws ExpressionException
initialisable
expressions
reachable from the expression supplied as expression
that has
not already been initialised.
V
- The type of value the evaluation of expression
produces.expression
- The expression (root); cannot be null.
expression
; never null.
NullPointerException
- If expression
is null.
ExpressionException
- If the initialisation fails.public String toString()
toString
in class Object
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |