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

dk.rode.thesis.meta.model
Class LongSequence

java.lang.Object
  extended by dk.rode.thesis.meta.model.AbstractSequence<Long>
      extended by dk.rode.thesis.meta.model.LongSequence
All Implemented Interfaces:
Sequence<Long>, Copyable<Sequence<Long>>, StrictCopyable<Sequence<Long>>, Stringable<Sequence<Long>>
Direct Known Subclasses:
VisitableLongSequence

public class LongSequence
extends AbstractSequence<Long>
implements Sequence<Long>

A long sequence represents an unbounded long value that is increased with each call to next().

A long sequence is unbounded, but unique and consistent.

Author:
Gunni Rode / rode.dk

Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence
Sequence.State
 
Field Summary
private  long sequence
          The current sequence number.
private  long start
          Start number of this sequence.
 
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence
state
 
Constructor Summary
LongSequence()
          No-arg constructor.
LongSequence(long start)
          Constructor.
LongSequence(LongSequence sequence)
          Copy constructor.
 
Method Summary
 boolean bounded()
          Returns false.
 boolean consistent()
          Returns true.
 LongSequence copy()
          Returns a copy of this sequence that will start at the same sequence index as this sequence.
 Long current()
          Returns the current element from this sequence.
 Long next()
          Returns the next element from this sequence.
 void reset()
          Resets this sequence to start over if it is consistent.
 boolean unique()
          Returns true.
 
Methods inherited from class dk.rode.thesis.meta.model.AbstractSequence
getStringablePolicy, state, toString, 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
state
 
Methods inherited from interface dk.rode.thesis.strategy.Stringable
getStringablePolicy, toString
 

Field Detail

sequence

private long sequence
The current sequence number.


start

private final long start
Start number of this sequence.

Constructor Detail

LongSequence

public LongSequence()
No-arg constructor.


LongSequence

public LongSequence(long start)
Constructor.

Parameters:
start - The start value of this sequence.

LongSequence

public LongSequence(LongSequence sequence)
Copy constructor.

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

bounded

public boolean bounded()
Returns false.

Specified by:
bounded in interface Sequence<Long>
Returns:
False.
See Also:
Sequence.unique()

consistent

public boolean consistent()
Returns true.

Specified by:
consistent in interface Sequence<Long>
Returns:
True.

copy

public LongSequence 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<Long>
Specified by:
copy in interface Copyable<Sequence<Long>>
Returns:
A copy of this sequence; never null.

current

public Long current()
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<Long>
Returns:
The current element; never null.

next

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

Specified by:
next in interface Sequence<Long>
Returns:
The next element; never null.
See Also:
Sequence.current(), Sequence.state()

reset

public void reset()
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<Long>
Overrides:
reset in class AbstractSequence<Long>

unique

public boolean unique()
Returns true.

Specified by:
unique in interface Sequence<Long>
Returns:
True.
See Also:
Sequence.consistent()

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.