|
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.iterator.SequenceIterator<E>
E - The type of values delivered by this iterator.@ParticipantUsage(value="Iterator",
type=java.util.Iterator.class)
@Participant(value="ConcreteIterator")
public class SequenceIterator<E>
A sequence iterator is an external iterator
that can iterate over bounded sequences.
The next() method returns the result of
Sequence.next() for the sequence represented by
the iterator. The hasNext() method will
return false as long as the bound has not been reached.
The functionality offered by a sequence iterator to
traverse the sequence values is roughly equivalent to
the following idiom:
The state of the sequence represented by the iterator may or may be affected if the sequence is accessed concurrently, depending on the means of creation.Sequencesequence = ..; while (sequence.state()!=Sequence.State.RESTART) { // do something meaningful with returned value... sequence.next(); }
A sequence iterator is not thread-safe.
SequenceIterator(Sequence),
SequenceIterator(SequenceIterator),
iterator(Sequence),
IterableSequence,
ProcessableSequence| Field Summary | |
|---|---|
(package private) Sequence<E> |
sequence
The sequence to iterate over. |
| Constructor Summary | |
|---|---|
SequenceIterator(Sequence<E> sequence)
Constructor. |
|
SequenceIterator(SequenceIterator<E> iterator)
Copy constructor. |
|
| Method Summary | ||
|---|---|---|
StringablePolicy<? super Sequence<E>> |
getStringablePolicy(StringablePolicy<? super Sequence<E>> policy)
Always return a non-null policy: policy is not null: policy is returned. |
|
boolean |
hasNext()
|
|
static
|
iterator(Sequence<V> sequence)
Creates a new iterator based on sequence. |
|
E |
next()
|
|
void |
remove()
|
|
String |
toString()
|
|
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 java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
final Sequence<E> sequence
Never null.
| Constructor Detail |
|---|
public SequenceIterator(Sequence<E> sequence)
Modifications to sequence will affect this
iterator!
sequence - The sequence to iterate over; cannot be null.
NullPointerException - If sequence is null.public SequenceIterator(SequenceIterator<E> iterator)
Modifications to iterator will not affect this
iterator!
iterator - The iterator to copy; cannot be null.
NullPointerException - If iterator is null.| Method Detail |
|---|
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>>policy - The supplied policy; can be null.
Stringable.toString(StringablePolicy)public boolean hasNext()
hasNext in interface Iterator<E>public static final <V> Iterator<V> iterator(Sequence<V> sequence)
sequence.
Modification to sequence will not affect the
returned iterator as sequence is copied before use.
V - The type of values delivered by sequence.sequence - The sequence; cannot be null.
NullPointerException - If sequence is null.public E next()
next in interface Iterator<E>public void remove()
remove in interface Iterator<E>UnsupportedOperationException - Always thrown.public String toString()
toString in class Objectpublic CharSequence toString(StringablePolicy<? super Sequence<E>> policy)
Stringablepolicy 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.getStringablePolicy(policy).toString(this);
}
There are two approaches to formatting this stringable object
into a char sequence representation:
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>>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 | ||||||||