|
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.meta.model.AbstractSequence<E> dk.rode.thesis.state.AbstractStateableSequence<E>
E
- The type of values delivered by this stateable sequence.@Participant(value="Context") public abstract class AbstractStateableSequence<E>
An abstract stateable sequence implements the basic
traits of a stateable
sequence.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
Sequence.State |
Field Summary | |
---|---|
private FunctionalState<E> |
functionalState
The current functional sequence state encapsulating the current behaviour of this sequence. |
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
state |
Constructor Summary | |
---|---|
protected |
AbstractStateableSequence()
No-arg constructor. |
protected |
AbstractStateableSequence(FunctionalState<E> functionalState)
Constructor. |
protected |
AbstractStateableSequence(StateableSequence<E> sequence)
Copy constructor. |
Method Summary | |
---|---|
E |
current()
Returns the current element from this sequence. |
FunctionalState<E> |
getFunctionalState()
Returns the functional state currently
set for this stateable sequence if this sequence allows disclosure
of such states. |
E |
next()
Returns the next element from this sequence. |
void |
reset()
Resets this sequence to start over if it is consistent. |
FunctionalState<E> |
setFunctionalState(FunctionalState<E> functionalState,
Sequence.State internalState)
Updates the functional state for this
stateable sequence to functionalState , as well as the
internal state to state , if supplied. |
CharSequence |
toString(StringablePolicy<? super Sequence<E>> policy)
Returns a char sequence representation of this stringable object using the format determined by policy or the
default policy
in case policy is null. |
Methods inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
getStringablePolicy, state, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
bounded, consistent, copy, state, unique |
Methods inherited from interface dk.rode.thesis.strategy.Stringable |
---|
getStringablePolicy |
Field Detail |
---|
private FunctionalState<E> functionalState
Never null.
Constructor Detail |
---|
protected AbstractStateableSequence()
No initial functional state is set, and must be done in the sub-class constructor.
protected AbstractStateableSequence(FunctionalState<E> functionalState)
functionalState
- The initial functional state of this
sequence; cannot be null.
NullPointerException
- If functionalState
is null.protected AbstractStateableSequence(StateableSequence<E> sequence)
sequence
- The sequence to copy; cannot be null.
NullPointerException
- If sequence
is null.Method Detail |
---|
public final E current()
Sequence
This method can be invoked even if Sequence.next()
has not been invoked yet, thus delivering the initial
value of this sequence.
current
in interface Sequence<E>
public FunctionalState<E> getFunctionalState()
StateableSequence
state
currently
set for this stateable sequence if this sequence allows disclosure
of such states.
A functional state is not the same as an internal sequence
state
, but functional states will update the
internal state.
getFunctionalState
in interface StateableSequence<E>
StateableSequence.setFunctionalState(FunctionalState, Sequence.State)
public final E next()
Sequence
next
in interface Sequence<E>
Sequence.current()
,
Sequence.state()
public final void reset()
Sequence
If this sequence is consistent
, the
sequence will restart.
reset
in interface Sequence<E>
reset
in class AbstractSequence<E>
public FunctionalState<E> setFunctionalState(FunctionalState<E> functionalState, Sequence.State internalState)
StateableSequence
state
for this
stateable sequence to functionalState
, as well as the
internal state
to state
, if supplied.
A functional state is not the same as an internal sequence
state, but functional states will update the internal state. After
the functional sequence state has been set, its
FunctionalState.action(Sequence.State, StateableSequence)
method is invoked using the internal state supplied as argument.
setFunctionalState
in interface StateableSequence<E>
functionalState
- The functional state; cannot be null.internalState
- The internal state; can be null.
StateableSequence.getFunctionalState()
public CharSequence toString(StringablePolicy<? super Sequence<E>> policy)
Stringable
policy
or the
default
policy
in case policy
is null.
In Foo
, a typical implementation of this method
could be:
public CharSequence toString(StringablePolicy<? super Foo> policy) { return this.There are two approaches to formatting this stringable object into a char sequence representation:getStringablePolicy
(policy).toString
(this); }
policy
decide the entire format,
as in the Foo
example above; or
policy
to format part of the overall
representation, for example letting this method append
certain text regardless of the policy used.
StringablePolicy.toString(Object)
method, for
example in case multiple stringable objects should be formatted
into an overall representation.
In case an implementation uses the approach from bullet 2), care
must be take to respect the policy hints
so the overall format remains meaningful.
toString
in interface Stringable<Sequence<E>>
toString
in class AbstractSequence<E>
policy
- The policy to dictate the formatting; can be null, in
which case the result of toString
method
is returned.
StringablePolicy.Type
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |