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

dk.rode.thesis.bridge
Class SynchronisedSequenceAbstraction<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.SynchronisedSequenceAbstraction<E>
Type Parameters:
E - The type of values delivered by this sequence.
All Implemented Interfaces:
Sequence<E>, Copyable<Sequence<E>>, StrictCopyable<Sequence<E>>, Stringable<Sequence<E>>

@Participant(value="RefinedAbstraction")
public class SynchronisedSequenceAbstraction<E>
extends SequenceAbstraction<E>

A synchronised sequence abstraction refines a sequence abstraction by making it thread-safe.

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
SynchronisedSequenceAbstraction()
          Constructor.
SynchronisedSequenceAbstraction(SequenceAbstraction<E> sequence)
          Copy constructor.
SynchronisedSequenceAbstraction(SequenceValueGenerator<? extends E> generator)
          Constructor, which creates this synchronised sequence abstraction to use the value generator supplied as generator.
 
Method Summary
 SynchronisedSequenceAbstraction<E> copy()
          Returns a copy of this sequence that will start at the same sequence index as this sequence.
 E current()
          Returns the current element from this sequence.
 E next()
          Returns the next element from this sequence.
 void reset()
          Resets this sequence to start over if it is consistent.
 SequenceAbstraction<E> setGenerator(SequenceValueGenerator<? extends E> generator)
          Sets the generator to use for this sequence to generator.
 
Methods inherited from class dk.rode.thesis.bridge.SequenceAbstraction
bounded, consistent, isInitialised, 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.strategy.Stringable
getStringablePolicy
 

Constructor Detail

SynchronisedSequenceAbstraction

public SynchronisedSequenceAbstraction()
Constructor.

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


SynchronisedSequenceAbstraction

public SynchronisedSequenceAbstraction(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 setGenerator(SequenceValueGenerator) method before this sequence is valid!

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

SynchronisedSequenceAbstraction

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

The 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 SynchronisedSequenceAbstraction<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.

current

public E current()
          throws IllegalStateException
Description copied from interface: Sequence
Returns the current element from this sequence.

This method can be invoked even if Sequence.next() has not been invoked yet, thus delivering the initial value of this sequence.

Specified by:
current in interface Sequence<E>
Overrides:
current in class SequenceAbstraction<E>
Returns:
The current element; never null.
Throws:
IllegalStateException - If a values has not been set.

next

public E next()
       throws IllegalStateException
Description copied from interface: Sequence
Returns the next element from this sequence.

Specified by:
next in interface Sequence<E>
Overrides:
next in class SequenceAbstraction<E>
Returns:
The next element; never null.
Throws:
IllegalStateException - If a values has not been set.
See Also:
Sequence.current(), Sequence.state()

reset

public void reset()
           throws IllegalStateException
Description copied from interface: Sequence
Resets this sequence to start over if it is consistent.

If this sequence is consistent, the sequence will restart.

Specified by:
reset in interface Sequence<E>
Overrides:
reset in class SequenceAbstraction<E>
Throws:
IllegalStateException - If a values has not been set.

setGenerator

public SequenceAbstraction<E> setGenerator(@Participant(value="Implementation")
                                           SequenceValueGenerator<? extends E> generator)
                                    throws IllegalStateException
Description copied from class: SequenceAbstraction
Sets the generator to use for this sequence to generator.

A generator can only be set once, and cannot be changed once set. This sequence is not valid until a generator has been set.

Overrides:
setGenerator in class SequenceAbstraction<E>
Parameters:
generator - The generator to use; cannot be null.
Returns:
This sequence abstraction; never null.
Throws:
IllegalStateException - If a generator has already been set.
See Also:
SequenceAbstraction.SequenceAbstraction(SequenceValueGenerator)

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.