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

dk.rode.thesis.state
Enum ReversiblePrimeSequence.PrimeState

java.lang.Object
  extended by java.lang.Enum<ReversiblePrimeSequence.PrimeState>
      extended by dk.rode.thesis.state.ReversiblePrimeSequence.PrimeState
All Implemented Interfaces:
FunctionalState<Integer>, Serializable, Comparable<ReversiblePrimeSequence.PrimeState>
Enclosing class:
ReversiblePrimeSequence

private static enum ReversiblePrimeSequence.PrimeState
extends Enum<ReversiblePrimeSequence.PrimeState>
implements FunctionalState<Integer>

A prime state represents a stateless functional state for all reversible prime sequences, while the actual internal state and attributes are stored in a given reversible prime sequence instance.

State transitions are handled both by prime states, but also by reversible prime sequences requesting a given action, i.e. in ReversiblePrimeSequence.reverse().

Implementation notes:
Each state may be considered implemented according to the Flyweight pattern in that they are singletons that only operate on extrinsic state.

Author:
Gunni Rode / rode.dk

Enum Constant Summary
Calculate
          Functional state calculating prime numbers for a reversible prime sequence, and delivering the next prime number (just calculated).
Next
          Functional state delivering the next prime number for a reversible prime sequence ("forward"), where all prime numbers have been calculated.
Previous
          Functional state delivering the previous prime number for a reversible prime sequence ("reverse"), where all prime numbers have been calculated.
ResetHigh
          Functional state resetting a reversible prime sequence if prime numbers are delivered in descending order ("reverse").
ResetLow
          Functional state resetting a reversible prime sequence to start over either because of initialisation, or in case of restart or reset explicitly if prime numbers are delivered in ascending order ("forward").
Start
          Functional state initialising a reversible prime sequence.
 
Method Summary
protected abstract  void action(Sequence.State internalState, ReversiblePrimeSequence sequence)
          Handles the internal state request supplied as internalState for the reversible prime sequence supplied as sequence.
 Integer action(Sequence.State internalState, StateableSequence<Integer> sequence)
          Depending on the value of the internal state supplied as internalState, the following forms of actions are inferred: Sequence.State.START: initialisation requested.
static ReversiblePrimeSequence.PrimeState valueOf(String name)
          Returns the enum constant of this type with the specified name.
static ReversiblePrimeSequence.PrimeState[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

Calculate

@Participant(value="ConcreteState")
public static final ReversiblePrimeSequence.PrimeState Calculate
Functional state calculating prime numbers for a reversible prime sequence, and delivering the next prime number (just calculated).

State transitions:

See Also:
action(Sequence.State, ReversiblePrimeSequence)

Next

@Participant(value="ConcreteState")
public static final ReversiblePrimeSequence.PrimeState Next
Functional state delivering the next prime number for a reversible prime sequence ("forward"), where all prime numbers have been calculated.

State transitions:

Can also be set by ReversiblePrimeSequence.reverse().

See Also:
Previous, action(Sequence.State, ReversiblePrimeSequence)

Previous

@Participant(value="ConcreteState")
public static final ReversiblePrimeSequence.PrimeState Previous
Functional state delivering the previous prime number for a reversible prime sequence ("reverse"), where all prime numbers have been calculated.

State transitions:

Can also be set by ReversiblePrimeSequence.reverse().

See Also:
Next, action(Sequence.State, ReversiblePrimeSequence)

ResetHigh

@Participant(value="ConcreteState")
public static final ReversiblePrimeSequence.PrimeState ResetHigh
Functional state resetting a reversible prime sequence if prime numbers are delivered in descending order ("reverse"). If so, all prime numbers have been calculated.

State transitions:

Can also be set by ReversiblePrimeSequence.reverse().

See Also:
ResetLow, action(Sequence.State, ReversiblePrimeSequence)

ResetLow

@Participant(value="ConcreteState")
public static final ReversiblePrimeSequence.PrimeState ResetLow
Functional state resetting a reversible prime sequence to start over either because of initialisation, or in case of restart or reset explicitly if prime numbers are delivered in ascending order ("forward").

State transitions:

Can also be set by ReversiblePrimeSequence.reverse().

See Also:
ResetHigh, action(Sequence.State, ReversiblePrimeSequence)

Start

@Participant(value="ConcreteState")
public static final ReversiblePrimeSequence.PrimeState Start
Functional state initialising a reversible prime sequence. It is the first state set for any reversible prime sequence.

State transitions:

See Also:
action(Sequence.State, ReversiblePrimeSequence)
Method Detail

action

protected abstract void action(Sequence.State internalState,
                               ReversiblePrimeSequence sequence)
Handles the internal state request supplied as internalState for the reversible prime sequence supplied as sequence.

Parameters:
internalState - The internal state; never null, i.e. current state already handled at this point.
sequence - The reversible prime sequence in question; cannot be null.
Throws:
NullPointerException - If sequence is null.

action

public final Integer action(Sequence.State internalState,
                            StateableSequence<Integer> sequence)
Description copied from interface: FunctionalState
Depending on the value of the internal state supplied as internalState, the following forms of actions are inferred:

Specified by:
action in interface FunctionalState<Integer>
Parameters:
internalState - The internal state representing the requested action; can be null (current).
sequence - The stateable sequence in question; cannot be null.
Returns:
The sequence result from the action taken; can be null.

valueOf

public static ReversiblePrimeSequence.PrimeState valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

values

public static ReversiblePrimeSequence.PrimeState[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (ReversiblePrimeSequence.PrimeState c : ReversiblePrimeSequence.PrimeState.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

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.