Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.adapter
Class IteratorSequence<E>

java.lang.Object
  extended by dk.rode.thesis.adapter.IteratorSequence<E>
Type Parameters:
E - The type of values delivered by this iterator.
All Implemented Interfaces:
Iterator<E>

@ParticipantUsage(value="Target",
                  type=java.util.Iterator.class)
@Participant(value="Adapter")
public class IteratorSequence<E>
extends Object
implements Iterator<E>

An object adapter that adapts a Sequence type to conform to the Iterator type: when the iterator is advanced, so is the sequence - hence the adaptation.

Author:
Gunni Rode / rode.dk
See Also:
IterableSequence, SequenceIterator

Field Summary
private  SequenceIterator<E> iterator
          The adapted sequence in form of an SequenceIterator instance: the responsibility is designated to the sequence iterator because it already implements the desired functionality.
 
Constructor Summary
IteratorSequence(Sequence<E> sequence)
          Constructor, which creates this iterator sequence to iterate through the sequence value from sequence, starting from its current value.
 
Method Summary
 boolean hasNext()
           
 E next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iterator

private final SequenceIterator<E> iterator
The adapted sequence in form of an SequenceIterator instance: the responsibility is designated to the sequence iterator because it already implements the desired functionality. This makes the adaption easy, as we merely forward the method invocations.

Never null.

Constructor Detail

IteratorSequence

public IteratorSequence(@Participant(value="Adaptee")
                        Sequence<E> sequence)
Constructor, which creates this iterator sequence to iterate through the sequence value from sequence, starting from its current value.

sequence must be bounded.

Parameters:
sequence - The sequence to adapt as an iterator; cannot be null.
Throws:
NullPointerException - If sequence is null.
IllegalArgumentException - If sequence is not bounded.
Method Detail

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<E>

next

public E next()
Specified by:
next in interface Iterator<E>

remove

public void remove()
Specified by:
remove in interface Iterator<E>

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.