
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<Integer> dk.rode.thesis.facade.AckermannSequence
@Participant(value="SubsystemClass") class AckermannSequence
An Ackermann sequence calculates the next value of the Ackermann function,
v = A(m, n), each time next()
is invoked, using a fixed value for
m and thus increasing n, either indefinitely, or until a maximum
value has been reached.
The running time of next()
is not consistent each time
invoked!
An Ackermann sequence is bounded
if a maximum
value of n is supplied at construction
time, otherwise unbounded, but always unique
and
consistent
.
Implementation note:
This implementation is naive. The stack depth very quickly becomes
an issue!
Nested Class Summary 

Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence 

Sequence.State 
Field Summary  

private List<Integer> 
calculated
The Ackermann values calculated so far for m
and all n smaller or equal to n . 
private int 
m
The constant value of m for all Ackermann values v = A(m,n) calculated by this sequence. 
private int 
maximumN
The maximum n value to consider. 
private int 
n
The value of n for the Ackermann value v = A(m,n) currently set for this sequence. 
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence 

state 
Constructor Summary  

AckermannSequence()
Constructor, which uses zero as the value of m. 

AckermannSequence(AckermannSequence sequence)
Copy constructor. 

AckermannSequence(int m)
Constructor, which uses the fixed value of m supplied as m . 

AckermannSequence(int m,
int maximumN)
Constructor, which uses the fixed value of m supplied as m . 
Method Summary  

boolean 
bounded()
Returns true if this sequence is bounded, i.e. 
private int 
calculate(int m,
int n)
Calculates A(m,n) and returns the value. 
(package private) int 
calculate(int m,
int n,
Map<Integer,Map<Integer,Integer>> ms)
Calculates all A(m,n). 
boolean 
consistent()
Returns true. 
AckermannSequence 
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. 
boolean 
equals(Object object)
Returns true if object is an instance of
this sequence type using the same m as
this sequence and currently at the same n,
false if not. 
int 
hashCode()
Returns the hash code of this sequence. 
int 
m()
Returns the constant value of m for all Ackermann values v = A(m,n) calculated by this sequence. 
int 
n()
The value of n for the Ackermann value v = A(m,n) currently set for this sequence. 
Integer 
next()
Returns the next element from this sequence. 
void 
reset()
Resets this sequence to start over if it is consistent. 
boolean 
unique()
Returns true. 
Methods inherited from class dk.rode.thesis.meta.model.AbstractSequence 

getStringablePolicy, state, toString, toString 
Methods inherited from class java.lang.Object 

clone, finalize, getClass, 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 List<Integer> calculated
m
and all n smaller or equal to n
. Never null.
private final int m
private final int maximumN
A value of Const.INFINITE
means no maximum n
value.
private int n
currently
set for this sequence.
n will be increased with each call to next()
until maximumN
value has been reached, if any, which
will cause this sequence to restart.
Constructor Detail 

public AckermannSequence()
There is no maximum value of n, i.e. from zero to infinity.
public AckermannSequence(AckermannSequence sequence)
sequence
 The sequence to copy; cannot be null.
NullPointerException
 If sequence
is null.public AckermannSequence(int m)
m
. There is no maximum value of n, i.e. from zero to infinity.
m
 The fixed m value used for all n
in A(m,n) when calculating the next
value by this sequence; cannot be negative.
IllegalArgumentException
 If m
is negative.public AckermannSequence(int m, int maximumN)
m
.
n will run from zero to maximumN
, if
maximumN
is not Const.INFINITE
.
m
 The fixed m value used for all n
in A(m,n) when calculating the next
value by this sequence; cannot be negative.maximumN
 The maximum value for n to consider. A value
of Const.INFINITE
means no maximum. Cannot be
negative.
IllegalArgumentException
 If m
or maximumN
are negative.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<Integer>
Sequence.unique()
private final int calculate(int m, int n)
m
 The m argument.n
 The n argument.
final int calculate(int m, int n, Map<Integer,Map<Integer,Integer>> ms)
m
 The m value.n
 The n value.ms
 A map storing already calculated values with m and n as keys.
public boolean consistent()
consistent
in interface Sequence<Integer>
public AckermannSequence copy()
Sequence
copy
in interface Sequence<Integer>
copy
in interface Copyable<Sequence<Integer>>
public Integer 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<Integer>
public boolean equals(Object object)
object
is an instance of
this sequence type using the same m as
this sequence and currently at the same n,
false if not.
equals
in class Object
object
 The object to test; can be null.
public int hashCode()
hashCode
in class Object
public int m()
public int n()
currently
set for this sequence.
public Integer next()
Sequence
next
in interface Sequence<Integer>
Sequence.current()
,
Sequence.state()
public void reset()
Sequence
If this sequence is consistent
, the
sequence will restart.
reset
in interface Sequence<Integer>
reset
in class AbstractSequence<Integer>
public boolean unique()
unique
in interface Sequence<Integer>
Sequence.consistent()

Gunni Rode / rode.dk  
PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 