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

dk.rode.thesis.facade
Class UnboundedRandomSequence

java.lang.Object
  extended by dk.rode.thesis.meta.model.AbstractSequence<Integer>
      extended by dk.rode.thesis.facade.RandomSequence
          extended by dk.rode.thesis.facade.UnboundedRandomSequence
All Implemented Interfaces:
Sequence<Integer>, Copyable<Sequence<Integer>>, StrictCopyable<Sequence<Integer>>, Stringable<Sequence<Integer>>

@Participant(value="SubsystemClass")
 class UnboundedRandomSequence
extends RandomSequence
implements Sequence<Integer>

An unbounded random sequence returns a pseudo integer random number with each call to next() with no upper bound.

It uses an internal sequence to deliver an an integer value that will be multiplied with a random value to generate a sequence value.

An unbounded random sequence is unbounded, inconsistent, and not unique.

Author:
Gunni Rode / rode.dk
See Also:
RandomSequence

Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence
Sequence.State
 
Field Summary
private  Sequence<? extends Number> sequence
          A sequence to deliver unbounded long values.
 
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence
state
 
Constructor Summary
UnboundedRandomSequence()
          No-arg constructor.
UnboundedRandomSequence(Sequence<? extends Number> sequence)
          Constructor.
UnboundedRandomSequence(UnboundedRandomSequence sequence)
          Copy constructor.
 
Method Summary
 boolean bounded()
          Returns false.
 UnboundedRandomSequence copy()
          Returns a copy of this sequence that will start at the same sequence index as this sequence.
 Integer current()
          Returns the current element from this sequence.
 Integer next()
          Returns the next element from this sequence.
 void reset()
          Resets this sequence to start over if it is consistent.
private static int value(int random, Number number)
          Calculates the current value of this sequence.
 
Methods inherited from class dk.rode.thesis.facade.RandomSequence
consistent, unique
 
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
consistent, state, unique
 
Methods inherited from interface dk.rode.thesis.strategy.Stringable
getStringablePolicy, toString
 

Field Detail

sequence

private final Sequence<? extends Number> sequence
A sequence to deliver unbounded long values.

Never null.

Constructor Detail

UnboundedRandomSequence

public UnboundedRandomSequence()
No-arg constructor.

A LongSequence is used to deliver the unbounded long values used internally.


UnboundedRandomSequence

public UnboundedRandomSequence(Sequence<? extends Number> sequence)
Constructor.

Parameters:
sequence - The sequence to deliver a long value that will be multiplied with a random value; cannot be null.
Throws:
NullPointerException - If sequence is null.

UnboundedRandomSequence

public UnboundedRandomSequence(UnboundedRandomSequence 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<Integer>
Overrides:
bounded in class RandomSequence
Returns:
False.
See Also:
Sequence.unique()

copy

public UnboundedRandomSequence 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<Integer>
Specified by:
copy in interface Copyable<Sequence<Integer>>
Overrides:
copy in class RandomSequence
Returns:
A copy of this sequence; never null.

current

public Integer 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<Integer>
Overrides:
current in class RandomSequence
Returns:
The current element; never null.

next

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

Specified by:
next in interface Sequence<Integer>
Overrides:
next in class RandomSequence
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<Integer>
Overrides:
reset in class RandomSequence

value

private static final int value(int random,
                               Number number)
Calculates the current value of this sequence.

Parameters:
random - The random number.
number - The unbounded number.
Returns:
The sequence value.

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.