|
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.decorator.SequenceDecorator<E> dk.rode.thesis.iterator.ProcessableSequence<E>
E
- The type of values processed by this processable sequence.public class ProcessableSequence<E>
A processable sequence represents an internal
iterator that can iterate over bounded
sequences
using a value processor
to perform the actual processing of delivered
sequence values. The processing will advance the sequence.
The iteration is performed using the process(ValueProcessor)
method. The processing will stop when the processable sequence has
no more values, or in case the processor returns false.
The processing performed by a processable sequence is not thread-safe.
Implementation notes:
This implementation uses the Decorator and Strategy
patterns as opposed to inheritance: the processing is delegated to a
ValueProcessor
supplied at iteration time, and hence this
iterator need not be sub-classed. The internal iterator example
provided by Gamma et al. uses inheritance, but Gamma et al. note
that it might be feasible to parameterise the iterator with the
processing operation in languages with different features than
those offered by C++ [Gamma95, p.267-269].
This is a specialised case of using composition instead of inheritance. More specifically, the internal iterators presented by Gamma et al. can be viewed as variants of the Template Method pattern, and the use of the Template Method pattern can thus be replaced by composition, providing all required information is supplied as arguments.
The is no interface in Java to support internal iterators.
IterableSequence
,
SequenceIterator
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
Sequence.State |
Constructor Summary | |
---|---|
ProcessableSequence(Sequence<E> sequence)
Constructor, which creates this processable sequence to process through the sequence values from sequence . |
Method Summary | |
---|---|
ProcessableSequence<E> |
copy()
Returns a copy of this sequence that will start at the same sequence index as this sequence. |
boolean |
process(ValueProcessor<? super E> processor)
Process values in this sequence using the processor supplied as processor until all values have been
exhausted, or processor returns false. |
Methods inherited from class dk.rode.thesis.decorator.SequenceDecorator |
---|
bounded, consistent, current, equals, getSequence, getStringablePolicy, hashCode, next, reset, state, toString, toString, unique |
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 |
---|
bounded, consistent, current, next, reset, state, unique |
Methods inherited from interface dk.rode.thesis.strategy.Stringable |
---|
getStringablePolicy, toString |
Constructor Detail |
---|
public ProcessableSequence(Sequence<E> sequence)
sequence
. Before each time this sequence is processed, it will be reset.
Modifying sequence
externally will affect this iterator.
sequence
- The sequence to make iterable; cannot be null.
NullPointerException
- If sequence
is null.
IllegalArgumentException
- If sequence
is unbounded.Method Detail |
---|
public ProcessableSequence<E> copy()
Sequence
copy
in interface Sequence<E>
copy
in interface Copyable<Sequence<E>>
public boolean process(ValueProcessor<? super E> processor)
processor
supplied as processor
until all values have been
exhausted, or processor
returns false.
This sequence will be reset
before
the processing is performed, and the processor
initialised
.
The processing will advance this sequence.
processor
- The value processor to use; cannot be null.
processor
terminated the iteration by
returning false.
NullPointerException
- If processor
is null.
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |