|
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.meta.model.AbstractSequence<E>
dk.rode.thesis.observer.SequenceObserversSequence<E,A>
dk.rode.thesis.observer.SequenceObserversSequenceDecorator<E,A>
E
- The type of values delivered by this sequence.A
- The type of aspect used by this sequence.@Participant(value={"ConcreteSubject","ConcreteObserver"}) public abstract class SequenceObserversSequenceDecorator<E,A>
A sequence observers sequence decorator decorates any
sequence
to become an observable
sequence that uses a sequence
observer
as the notification mechanism.
Implementation notes:
Because Java does not support functional multiple inheritance,
this decorator cannot inherit both SequenceDecorator
and SequenceObserversSequence
. Hence, all Sequence
methods have to be implemented explicitly in this class,
while the observable functionality is inherited from
SequenceObserversSequence
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
Sequence.State |
Field Summary | |
---|---|
private Sequence<E> |
sequence
The decorated sequence. |
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
state |
Constructor Summary | |
---|---|
SequenceObserversSequenceDecorator(Sequence<E> sequence)
Constructor. |
|
SequenceObserversSequenceDecorator(SequenceObserversSequenceDecorator<E,A> sequence)
Copy constructor. |
Method Summary | |
---|---|
boolean |
bounded()
Returns true if this sequence is bounded, i.e. |
boolean |
consistent()
Returns true if this sequence is consistent, i.e. deliver the same values, in order, after restart or reset . |
E |
current()
Returns the current element from this sequence. |
protected E |
doNext()
Hook for sub-classes to perform the actual next()
operation without notifying observers. |
boolean |
equals(Object object)
|
StringablePolicy<? super Sequence<E>> |
getStringablePolicy(StringablePolicy<? super Sequence<E>> policy)
Always return a non-null policy: policy is not null: policy is returned. |
int |
hashCode()
|
void |
reset()
Resets this sequence to start over if it is consistent. |
Sequence.State |
state()
Returns the internal state of this sequence. |
String |
toString()
Returns the default string representation specified by the AbstractSequence.toString(StringablePolicy) method. |
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. |
boolean |
unique()
Returns true if this sequence deliver a given sequence value at most one time until reset or restarted. |
Methods inherited from class dk.rode.thesis.observer.SequenceObserversSequence |
---|
addObserver, addObserver, getAspect, getAspects, getObservers, getObservers, next, removeObserver, removeObserver, sequenceEvent |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
copy |
Field Detail |
---|
private final Sequence<E> sequence
Never null.
Constructor Detail |
---|
public SequenceObserversSequenceDecorator(Sequence<E> sequence)
sequence
- The sequence to decorate; cannot be null.
NullPointerException
- If sequence
is null.public SequenceObserversSequenceDecorator(SequenceObserversSequenceDecorator<E,A> sequence)
sequence
- The observable sequence to copy; cannot be null.
NullPointerException
- If sequence
is null.Method Detail |
---|
public boolean bounded()
Sequence
The same type of sequence may represent both bounded and
unbounded sequences and the behaviour is determined and fixed
at construction time.
Bounded sequences will restart if they deliver
consistent
values.
Sequence.unique()
public boolean consistent()
Sequence
reset
.
Only bounded
consistent sequences will restart.
Consistent sequences need not deliver unique
sequence values.
Instances of the same type of sequences are always consistent or inconsistent; it is determined at design time, not construction time.
public 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.
protected E doNext()
SequenceObserversSequence
next()
operation without notifying observers.
doNext
in class SequenceObserversSequence<E,A>
public boolean equals(Object object)
equals
in class Object
public StringablePolicy<? super Sequence<E>> getStringablePolicy(StringablePolicy<? super Sequence<E>> policy)
Stringable
policy
is not null: policy
is returned.
policy
is null: a default, non-null policy is returned.
getStringablePolicy
in interface Stringable<Sequence<E>>
getStringablePolicy
in class AbstractSequence<E>
policy
- The supplied policy; can be null.
Stringable.toString(StringablePolicy)
public int hashCode()
hashCode
in class Object
public void reset()
Sequence
If this sequence is consistent
, the
sequence will restart.
reset
in interface Sequence<E>
reset
in class AbstractSequence<E>
public Sequence.State state()
Sequence
state
in interface Sequence<E>
state
in class AbstractSequence<E>
public String toString()
AbstractSequence
AbstractSequence.toString(StringablePolicy)
method.
toString
in class AbstractSequence<E>
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
public boolean unique()
Sequence
reset
or restarted.
Unbounded
sequences that are unique will never
deliver the same sequence value more than once.
The same type of sequence may represent both unique and not unique sequences and the behaviour is determined and fixed at construction time.
Sequence.consistent()
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |