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

dk.rode.thesis.bridge
Class MemorizableSequenceAbstraction<E>

java.lang.Object
  extended by dk.rode.thesis.meta.model.AbstractSequence<E>
      extended by dk.rode.thesis.bridge.SequenceAbstraction<E>
          extended by dk.rode.thesis.bridge.MemorizableSequenceAbstraction<E>
Type Parameters:
E - The type of values delivered by this sequence.
All Implemented Interfaces:
MemorizableSequence<E>, Sequence<E>, Copyable<Sequence<E>>, StrictCopyable<Sequence<E>>, Stringable<Sequence<E>>

@Participant(value="RefinedAbstraction")
public class MemorizableSequenceAbstraction<E>
extends SequenceAbstraction<E>
implements MemorizableSequence<E>, Sequence<E>

A memorizable sequence abstraction refines a sequence abstraction so it can save and restore its internal implementation in form of mementos.

Mementos cannot be created or set until a generator has been set, either at construction time, any time before sequence use via the SequenceAbstraction.setGenerator(SequenceValueGenerator) method.

Author:
Gunni Rode / rode.dk

Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence
Sequence.State
 
Field Summary
 
Fields inherited from class dk.rode.thesis.bridge.SequenceAbstraction
current, generator
 
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence
state
 
Constructor Summary
MemorizableSequenceAbstraction()
          Constructor.
MemorizableSequenceAbstraction(SequenceAbstraction<E> sequence)
          Copy constructor.
MemorizableSequenceAbstraction(SequenceValueGenerator<E> generator)
          Constructor, which creates this memorizable sequence abstraction to use the value generator supplied as generator.
 
Method Summary
 MemorizableSequenceAbstraction<E> copy()
          Returns a copy of this sequence that will start at the same sequence index as this sequence.
 SequenceMemento<E> getMemorizableState()
          Returns a sequence memento representing the current state of this sequence.
 void setMemorizableState(SequenceMemento<E> memento)
          Updates this sequence to the state supplied as memento.
 
Methods inherited from class dk.rode.thesis.bridge.SequenceAbstraction
bounded, consistent, current, isInitialised, next, reset, setGenerator, state, toString, unique
 
Methods inherited from class dk.rode.thesis.meta.model.AbstractSequence
getStringablePolicy, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, 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

MemorizableSequenceAbstraction

public MemorizableSequenceAbstraction()
Constructor.

A value generator must explicitly be set using the SequenceAbstraction.setGenerator(SequenceValueGenerator) method before this sequence is valid!


MemorizableSequenceAbstraction

public MemorizableSequenceAbstraction(SequenceAbstraction<E> sequence)
Copy constructor.

If sequence does not have a value generator set, a generator must explicitly be set for this sequence using the SequenceAbstraction.setGenerator(SequenceValueGenerator) method before this sequence is valid!

Parameters:
sequence - The (memorizable) sequence abstraction to copy; cannot be null.
Throws:
NullPointerException - If sequence is null.

MemorizableSequenceAbstraction

public MemorizableSequenceAbstraction(@Participant(value="Implementation")
                                      SequenceValueGenerator<E> generator)
Constructor, which creates this memorizable sequence abstraction to use the value generator supplied as generator.

The SequenceAbstraction.setGenerator(SequenceValueGenerator) must not be invoked for this sequence.

Parameters:
generator - The generator to use; cannot be null.
Throws:
NullPointerException - If generator is null.
Method Detail

copy

public MemorizableSequenceAbstraction<E> copy()
Description copied from interface: Sequence
Returns a copy of this sequence that will start at the same sequence index as this sequence.

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

getMemorizableState

public SequenceMemento<E> getMemorizableState()
                                       throws IllegalStateException
Description copied from interface: MemorizableSequence
Returns a sequence memento representing the current state of this sequence.

Specified by:
getMemorizableState in interface MemorizableSequence<E>
Returns:
The memento; never null.
Throws:
IllegalStateException - If a generator has not been set.

setMemorizableState

public void setMemorizableState(SequenceMemento<E> memento)
                         throws IllegalStateException,
                                MemorizableException
Description copied from interface: MemorizableSequence
Updates this sequence to the state supplied as memento.

Specified by:
setMemorizableState in interface MemorizableSequence<E>
Parameters:
memento - The memento supplying the state; cannot be null.
Throws:
IllegalStateException - If a generator has not been set.
MemorizableException - If the update fails, e.g. illegal memento state for this sequence, or illegal memento type.

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.