|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD | ||||||||
java.lang.Objectjava.lang.Enum<ReversiblePrimeSequence.PrimeState>
dk.rode.thesis.state.ReversiblePrimeSequence.PrimeState
private static enum ReversiblePrimeSequence.PrimeState
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.
| 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 |
|---|
@Participant(value="ConcreteState") public static final ReversiblePrimeSequence.PrimeState Calculate
State transitions:
Sequence.State.START:
illegal state exception.
Sequence.State.NORMAL:
Next if all primes have been calculated.
Sequence.State.RESET:
ResetLow.
Sequence.State.RESTART:
illegal state exception.
action(Sequence.State, ReversiblePrimeSequence)@Participant(value="ConcreteState") public static final ReversiblePrimeSequence.PrimeState Next
State transitions:
Sequence.State.START:
illegal state exception.
Sequence.State.NORMAL:
ResetLow if restarting.
Sequence.State.RESET:
ResetLow.
Sequence.State.RESTART:
ResetLow.
ReversiblePrimeSequence.reverse().
Previous,
action(Sequence.State, ReversiblePrimeSequence)@Participant(value="ConcreteState") public static final ReversiblePrimeSequence.PrimeState Previous
State transitions:
Sequence.State.START:
illegal state exception.
Sequence.State.NORMAL:
ResetHigh if restarting.
Sequence.State.RESET:
ResetHigh.
Sequence.State.RESTART:
ResetHigh.
ReversiblePrimeSequence.reverse().
Next,
action(Sequence.State, ReversiblePrimeSequence)@Participant(value="ConcreteState") public static final ReversiblePrimeSequence.PrimeState ResetHigh
State transitions:
Sequence.State.START:
illegal state exception.
Sequence.State.NORMAL:
Previous.
Sequence.State.RESET:
None, but resets the sequence (high).
Sequence.State.RESTART:
None, but resets the sequence (high).
ReversiblePrimeSequence.reverse().
ResetLow,
action(Sequence.State, ReversiblePrimeSequence)@Participant(value="ConcreteState") public static final ReversiblePrimeSequence.PrimeState ResetLow
reset explicitly if
prime numbers are delivered in ascending order ("forward"). State transitions:
Sequence.State.START:
initialises the reversible prime sequence the very first
time (called from Start). Henceforth an illegal
state exception is thrown if used again.
Sequence.State.NORMAL:
Calculate if all primes have not been calculated,
otherwise Next.
Sequence.State.RESET:
None, but resets the sequence (low).
Sequence.State.RESTART:
None, but resets the sequence (low).
ReversiblePrimeSequence.reverse().
ResetHigh,
action(Sequence.State, ReversiblePrimeSequence)@Participant(value="ConcreteState") public static final ReversiblePrimeSequence.PrimeState Start
State transitions:
Sequence.State.START:
none, but initialises the sieve and validates the maximum number
of primes to investigate. Once this state is discarded, it will
never be used again for the same sequence.
Sequence.State.NORMAL:
Calculate if all primes have not been calculated,
otherwise Next.
Sequence.State.RESET:
ResetLow.
Sequence.State.RESTART:
illegal state exception.
action(Sequence.State, ReversiblePrimeSequence)| Method Detail |
|---|
protected abstract void action(Sequence.State internalState,
ReversiblePrimeSequence sequence)
internalState
for the reversible prime sequence supplied as sequence.
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.
NullPointerException - If sequence is null.
public final Integer action(Sequence.State internalState,
StateableSequence<Integer> sequence)
FunctionalStateinternalState, the following forms of actions are
inferred:
Sequence.State.START: initialisation requested.
Sequence.State.RESET: reset requested.
Sequence.State.RESTART: restart requested.
Sequence.State.NORMAL: next value requested.
null: current value requested.
action in interface FunctionalState<Integer>internalState - The internal state representing the requested action;
can be null (current).sequence - The stateable sequence in question; cannot be null.
public static ReversiblePrimeSequence.PrimeState valueOf(String name)
name - the name of the enum constant to be returned.
IllegalArgumentException - if this enum type has no constant
with the specified name
NullPointerException - if the argument is nullpublic static ReversiblePrimeSequence.PrimeState[] values()
for (ReversiblePrimeSequence.PrimeState c : ReversiblePrimeSequence.PrimeState.values()) System.out.println(c);
|
Gunni Rode / rode.dk | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD | ||||||||