|
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<BigInteger> dk.rode.thesis.facade.FibonacciSequence
@Participant(value="SubsystemClass") public class FibonacciSequence
A Fibonacci sequence represents an integer sequence, where
each number delivered by next()
is the sum of the two
preceding numbers, except one which is the initial value:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, ..
A Fibonacci sequence is unbounded
unless
a maximum number to consider has been supplied at construction time, not
unique
(1), but consistent
.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
Sequence.State |
Field Summary | |
---|---|
private BigInteger |
current
The current Fibonacci number. |
private BigInteger |
maximum
Maximum number to consider. |
private BigInteger |
previous
The previous Fibonacci number. |
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
state |
Constructor Summary | |
---|---|
FibonacciSequence()
No-arg constructor. |
|
FibonacciSequence(BigInteger maximum)
Constructor. |
|
FibonacciSequence(FibonacciSequence sequence)
Copy constructor. |
Method Summary | |
---|---|
boolean |
bounded()
Returns true if this sequence is bounded, i.e. |
boolean |
consistent()
Returns true. |
FibonacciSequence |
copy()
Returns a copy of this sequence that will start at the same sequence index as this sequence. |
BigInteger |
current()
Returns the current element from this sequence. |
BigInteger |
next()
Returns the next element from this sequence. |
void |
reset()
Resets this sequence to start over if it is consistent. |
boolean |
unique()
Returns false. |
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 |
---|
private BigInteger current
The first number is one.
private BigInteger maximum
The number need not be a Fibonacci number.
A value of null means no maximum.
private BigInteger previous
Constructor Detail |
---|
public FibonacciSequence()
No maximum number is enforced.
public FibonacciSequence(BigInteger maximum)
maximum
, if not
null.
maximum
- The maximum bound; can be null.
IllegalArgumentException
- If maximum
is not null, but
not positive.public FibonacciSequence(FibonacciSequence sequence)
sequence
- The sequence to copy; cannot be null.
NullPointerException
- If sequence
is null.Method Detail |
---|
public boolean bounded()
Sequence
The same type of sequence may represent both bounded and
unbounded sequences and the behaviour is determined and fixed
at construction time.
Bounded sequences will restart if they deliver
consistent
values.
bounded
in interface Sequence<BigInteger>
Sequence.unique()
public boolean consistent()
consistent
in interface Sequence<BigInteger>
public FibonacciSequence copy()
Sequence
copy
in interface Sequence<BigInteger>
copy
in interface Copyable<Sequence<BigInteger>>
public BigInteger current()
Sequence
This method can be invoked even if Sequence.next()
has not been invoked yet, thus delivering the initial
value of this sequence.
current
in interface Sequence<BigInteger>
public BigInteger next()
Sequence
next
in interface Sequence<BigInteger>
Sequence.current()
,
Sequence.state()
public void reset()
Sequence
If this sequence is consistent
, the
sequence will restart.
reset
in interface Sequence<BigInteger>
reset
in class AbstractSequence<BigInteger>
public boolean unique()
unique
in interface Sequence<BigInteger>
Sequence.consistent()
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |