public class ObservableDomino extends java.util.Observable implements DominoSpecification
DominoSpecification
that makes it Observable
.Observable
being an abstract class and not an interface
(a problem with the Java API design).DominoSpecification
behaviour with
a randomize method, which is added in order to allow the construction of a new random
DominoSpecification
attribute without having to reconstruct the Observable objectModifier and Type | Field and Description |
---|---|
(package private) DominoSpecification |
domino |
INVARIANT, MAX, MIN, NUMBER_OF_DOMINOES_POSSIBLE, RANGE_OF_VALUES
Constructor and Description |
---|
ObservableDomino() |
ObservableDomino(int l,
int r) |
ObservableDomino(java.util.Random rng) |
Modifier and Type | Method and Description |
---|---|
DominoSpecification |
copy()
Constructs a new domino using a copy of the left and right values of
this Tested by JUnit_DominoSpecification.test_copy() |
boolean |
equals(java.lang.Object o)
Tested by
JUnit_DominoSpecification.test_equals() |
int |
getLeftValue()
Getter function of the left value.
Tested by JUnit_DominoSpecification.test_getLeft() |
int |
getRightValue()
Getter function of the right value.
Tested by JUnit_DominoSpecification.test_getRight() |
int |
hashCode()
|
boolean |
invariant()
Should check that the left and right values are in allowed range
DominoSpecification.MIN .. |
void |
randomize()
update the state of the object in a random (safe) manner.
|
void |
randomize(java.util.Random rng)
update the state of the object in a random (safe) manner
|
void |
switchSides()
Swap the left and right values - to model flipping/switching the domino around.
|
java.lang.String |
toString()
|
DominoSpecification domino
public ObservableDomino(int l, int r) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public ObservableDomino()
public ObservableDomino(java.util.Random rng)
public void switchSides()
DominoSpecification
JUnit_DominoSpecification.test_switchSides()
switchSides
in interface DominoSpecification
public int getRightValue()
DominoSpecification
JUnit_DominoSpecification.test_getRight()
getRightValue
in interface DominoSpecification
public int getLeftValue()
DominoSpecification
JUnit_DominoSpecification.test_getLeft()
getLeftValue
in interface DominoSpecification
public boolean invariant()
DominoSpecification
DominoSpecification.MIN
.. DominoSpecification.MAX
invariant
in interface DominoSpecification
invariant
in interface HasInvariant
public java.lang.String toString()
DominoSpecification
toString
in interface DominoSpecification
toString
in class java.lang.Object
public DominoSpecification copy()
DominoSpecification
this
JUnit_DominoSpecification.test_copy()
copy
in interface DominoSpecification
this
public boolean equals(java.lang.Object o)
DominoSpecification
JUnit_DominoSpecification.test_equals()
equals
in interface DominoSpecification
equals
in class java.lang.Object
o
- is compared to thisDominoSpecification.hashCode()
public int hashCode()
DominoSpecification
hashCode
in interface DominoSpecification
hashCode
in class java.lang.Object
DominoSpecification.equals(java.lang.Object)
methodDominoSpecification.equals(java.lang.Object)
public void randomize()
Randomizable
randomize
in interface Randomizable
public void randomize(java.util.Random rng) throws InvariantBrokenException
Randomizable
randomize
in interface Randomizable
rng
- the random number generator used to randomly set the domino values, if this is null then we construct itInvariantBrokenException
- if the domino state is not valid after execution (this should not happen)