|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.rode.thesis.meta.model.AbstractSequence<E> dk.rode.thesis.templatemethod.SequenceTemplate<Integer,Integer> dk.rode.thesis.templatemethod.NegativeSequence
@Participant(value="ConcreteClass") public class NegativeSequence
A negative sequence represents a perhaps
bounded
integer value that is decreased
with each call to next()
, starting at minus one.
A negative sequence is unbounded
unless a specific
minimum number is supplied at construction time, but is unique
and consistent
.
Implementation notes:
A negative sequence quite possibly represents the simplest implementation
of a sequence template
, and it could easily
have been implemented in a fashion like the LongSequence
class.
Note that no explicit class attribute is required to store the sequence
value! The use of the sequence template here is only to illustrate its use.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
Sequence.State |
Field Summary | |
---|---|
private int |
minimum
The minimum value of this sequence. |
Fields inherited from class dk.rode.thesis.templatemethod.SequenceTemplate |
---|
POLICY |
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
state |
Constructor Summary | |
---|---|
NegativeSequence()
Constructor, which creates this negative sequence as unbounded. |
|
NegativeSequence(int minimum)
Constructor, which creates this negative sequence as bounded. |
|
NegativeSequence(NegativeSequence sequence)
Copy constructor. |
Method Summary | |
---|---|
boolean |
bounded()
Returns true if a minimum sequence value were supplied at construction time, false if not. |
NegativeSequence |
copy()
Returns a copy of this sequence that will start at the same sequence index as this sequence. |
protected Integer |
nextValue(Integer key,
Integer current)
This abstract operation creates the next sequence
value to be delivered. |
protected Integer |
nextValueOpen(Integer current)
Prepares this sequence for the next sequence value to
be delivered based on the current value supplied
as current . |
protected boolean |
sequenceOpen(Object... arguments)
Performs sub-class specific initialisation of this sequence before sequence values will be delivered, and returns true upon success. |
Methods inherited from class dk.rode.thesis.templatemethod.SequenceTemplate |
---|
close, consistent, current, ensureOpen, finalize, index, isClosed, next, nextValueClose, reset, sequenceClose, sequenceReset, size, unique |
Methods inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
getStringablePolicy, state, toString, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private int minimum
A value of zero means no minimum, i.e. unbounded.
Constructor Detail |
---|
public NegativeSequence()
public NegativeSequence(int minimum)
minimum
- The minimum value of this sequence; cannot be positive.
IllegalArgumentException
- If minimum
is positive.public NegativeSequence(NegativeSequence sequence)
sequence
- The sequence to copy; cannot be null.
NullPointerException
- If sequence
is null.Method Detail |
---|
public boolean bounded()
bounded
in interface Sequence<Integer>
bounded
in class SequenceTemplate<Integer,Integer>
Sequence.unique()
public NegativeSequence copy()
Sequence
protected Integer nextValue(Integer key, Integer current)
SequenceTemplate
next
sequence
value to be delivered. This is step 2/3 in value creation, where
the previous step was nextValueOpen(E)
and the last is nextValueClose(K, E)
.
nextValue
in class SequenceTemplate<Integer,Integer>
key
- The correlation key just created by
nextValueOpen(E)
; can be null.current
- The current (soon to be previous) sequence value; never null
unless initialising this sequence (once).
SequenceTemplate.next()
returns; null means sequence restart,
which is only allowed if this sequence is bounded
.protected Integer nextValueOpen(Integer current)
SequenceTemplate
next
sequence value to
be delivered based on the current
value supplied
as current
. This is step 1/3 in value creation, where
the next steps are nextValue(K, E)
and
nextValueClose(K, E)
.
The returned correlation key will be used to identify the
same creation process in subsequent calls to nextValue
and nextValueClose
.
nextValueOpen
in class SequenceTemplate<Integer,Integer>
current
- The current (soon to be previous) sequence value; never null
unless initialising this sequence (once).
protected boolean sequenceOpen(Object... arguments) throws Exception
SequenceTemplate
closed
.
Initialisation is performed upon construction
of new sequences and when
copying
existing
sequences, if needed. The arguments supplied to this (abstract) operation
is the varargs arguments supplied at construction time (e.g. via sub-class
implementations).
sequenceOpen
in class SequenceTemplate<Integer,Integer>
arguments
- Arguments required by the initialisation, if any;
never null, but can be empty.
IllegalArgumentException
- If the minimum sequence value is
positive.
Exception
- If the super sequence open method throws an
exception.SequenceTemplate.sequenceReset()
,
SequenceTemplate.sequenceClose()
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |