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

dk.rode.thesis.meta.model
Interface ReversibleSequence<E>

Type Parameters:
E - The type of values delivered by this reversible sequence.
All Superinterfaces:
Copyable<Sequence<E>>, Sequence<E>, StrictCopyable<Sequence<E>>, Stringable<Sequence<E>>
All Known Implementing Classes:
RangeSequence, ReversiblePrimeSequence, VisitableReversiblePrimeSequence

public interface ReversibleSequence<E>
extends Sequence<E>

A reversible sequence allows retrieval of previous values if and only if such previous values are ready for delivery, i.e. have already been calculated.

By invoking reverse() on a reversible sequence, the order to advance is reversed, from "next" to "previous" value, and back to "next" from "previous" the next time reverse() is invoked, and so forth.

Reversible sequences are by nature always bounded and consistent.

Examples:

    Consistent, bounded, unique, reversible number sequence: [0, 1, 2, 3, 4, 5]
    
    current(): 0   
    next():    1               
    next():    2               
    next():    3               
    current(): 3               
    next():    4               
    next():    5  
    next():    1     
    next():    2               
    reverse(): 2
    next():    1               
    reset():   0    
    next():    5
    next():    4
    next():    3
    next():    2
    reverse(): 2
    next():    3
    reset():   0
    next():    1
    reset():   0
    reverse(): 0
    next():    5
    ..
 

Author:
Gunni Rode / rode.dk

Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence
Sequence.State
 
Method Summary
 ReversibleSequence<E> copy()
          Returns a copy of this reversible sequence that will start at the same sequence index as this sequence in the same direction.
 E reverse()
          Reverses this reversible sequence, if currently reversible.
 boolean reversible()
          Returns true if this reversible sequence can be reversed in its current state, false if not.
 
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
 

Method Detail

copy

ReversibleSequence<E> copy()
Returns a copy of this reversible sequence that will start at the same sequence index as this sequence in the same direction.

Specified by:
copy in interface Copyable<Sequence<E>>
Specified by:
copy in interface Sequence<E>
Returns:
A copy of this sequence; never null.

reverse

E reverse()
Reverses this reversible sequence, if currently reversible.

The current value is not affected by this method, and is returned by this method.

Returns:
The current sequence value; never null.
Throws:
IllegalStateException - If this sequence cannot be reversed at this point.

reversible

boolean reversible()
Returns true if this reversible sequence can be reversed in its current state, false if not.

If this method returns true, it is safe to invoke reverse(). If it returns false, an illegal state exception will be thrown by reverse().

Returns:
True if this reversible sequence can be reversed in its current state, false if not.

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.