|
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.IterableSequence<E>
E
- The type of values delivered by this iterable sequence.@ParticipantUsage(value="Aggregate", type=java.lang.Iterable.class) @Participant(value="ConcreteAggregate") public class IterableSequence<E>
An iterable sequence is a bounded
sequence
that can be accessed as any
other iterable object.
When iterating, the iterable sequence will be advanced!
To avoid modification of the sequence, simply
copy
it before use.
Example usage:
// Highest number to consider as a prime number... int n = 100; // Create a bounded sequence to deliver primes...An iterable sequence is not thread-safe.PrimeSequence
sequence = newPrimeSequence
(n); // Create iterable sequence based on "sequence"...IterableSequence
<Integer> is = newIterableSequence
<Integer>(sequence); // Print all primes between 2 and n (implicit usage ofiterator()
)... for (int prime : is) {LogFactory
.getLog
().println
("Prime: ", prime); }
SequenceIterator
,
ProcessableSequence
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
Sequence.State |
Constructor Summary | |
---|---|
IterableSequence(Sequence<E> sequence)
Constructor, which creates this iterable sequence to iterate through the sequence values from sequence , starting
from its current value. |
Method Summary | |
---|---|
IterableSequence<E> |
copy()
Returns a copy of this sequence that will start at the same sequence index as this sequence. |
Iterator<E> |
iterator()
Returns an iterator to iterate over this sequence. |
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 IterableSequence(Sequence<E> sequence)
sequence
, starting
from its current value.
sequence
must be bounded
and
is not altered by this constructor, but copied
before returned by the iterator()
method. If
not bounded, iterator()
will thrown an exception.
sequence
- The sequence to make iterable; cannot be null.
NullPointerException
- If sequence
is null.
IllegalArgumentException
- If sequence
is unbounded.Method Detail |
---|
public IterableSequence<E> copy()
Sequence
copy
in interface Sequence<E>
copy
in interface Copyable<Sequence<E>>
public Iterator<E> iterator()
The returned iterator will advance this sequence because this sequence is iterable!
iterator
in interface Iterable<E>
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |