|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--org.pealfactory.ring.Row
|
+--org.pealfactory.ring.ImmutableRow
This is an immutable version of the basic class which represents rows -
Row.
It is often more convenient and less error-prone to deal with immutable rows,
especially when you need to keep semi-permanent references to them.
When applying permutations to ImmutableRows, the Row methods applyPermutation()
and applyPN() cannot be used. Instead, permute(org.pealfactory.ring.ImmutableRow) and change(byte[])
methods are provided, which return a new ImmutableRow and do not alter the
current one.
Performance is critical for this class, so some methods are final to allow inlining by compiling VMs. The hashcode, rounds, tenorsTogether, tenorsHome and PBrow properties provided by the Row class are also cached.
In an ideal class design ImmutableRow and Row would share a common interface and have different implementations. However these classes are used in applet code where download size is crucial, so to keep the code size and number of classes as small as possible, ImmutableRow extends Row directly. All Row methods which alter internal state are overridden and will throw RuntimeExceptions - a somewhat messy way to provide immutability, but it works.
| Field Summary | |
private int |
fHashcode
|
private boolean |
fHashcodeSet
|
private boolean |
fPBRow
|
private boolean |
fPBRowSet
|
private boolean |
fRounds
|
private boolean |
fTenorsHome
|
private boolean |
fTenorsTogether
|
private boolean |
fTHSet
|
private boolean |
fTTSet
|
static ImmutableRow |
kROUNDS_ROW
|
| Fields inherited from class org.pealfactory.ring.Row |
fNBells, fRow |
| Fields inherited from interface org.pealfactory.ring.Constants |
kCALL_BOB, kCALL_EXTREME, kCALL_PLAIN, kCALL_SINGLE, kCALL_USER, kCHAR_CROSS, kCHAR_LH, kMAXNBELLS, kMINNBELLS, kROUNDS |
| Constructor Summary | |
ImmutableRow(int nbells)
Construct a row containing rounds on nbells. |
|
ImmutableRow(Row row)
Construct a row from another Row - faster than doing new ImmutableRow(row.toString()). |
|
ImmutableRow(java.lang.String row)
Construct a row from the String s, setting the number of bells from the string length. |
|
| Method Summary | |
void |
applyPermutation(byte[] permutation)
Not allowed because we are immutable - use permute() instead. |
void |
applyPermutation(Row permutation)
Not allowed because we are immutable - use permute() instead. |
void |
applyPN(byte[] pn)
Not allowed because we are immutable - use change() instead. |
ImmutableRow |
change(byte[] pn)
Permute the row by a single change of place notation. |
int |
hashCode()
Hashcode same as underlying string. |
boolean |
isPBrow()
Cache value for speed |
boolean |
isRounds()
Final for speed |
boolean |
isTenorsHome()
Cache value for speed |
boolean |
isTenorsTogether()
Cache value for speed |
ImmutableRow |
permute(byte[] perm)
Permutes this row by the given change. |
ImmutableRow |
permute(ImmutableRow r)
Permutes this row by the given transformation. |
void |
setRow(Row r)
Not allowed - we are immutable |
void |
setRow(java.lang.String s)
Not allowed - we are immutable |
void |
swap(int i,
int j)
Not allowed - we are immutable |
| Methods inherited from class org.pealfactory.ring.Row |
bellAt, calcPermutation, clone, equals, findBell, getNBells, isPBrow, nextCourseBell, nextCourseBellNoTreble, setNBells, test, toBytes, toString |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
public static final ImmutableRow kROUNDS_ROW
private boolean fRounds
private transient boolean fHashcodeSet
private transient int fHashcode
private transient boolean fPBRowSet
private transient boolean fPBRow
private transient boolean fTTSet
private transient boolean fTenorsTogether
private transient boolean fTHSet
private transient boolean fTenorsHome
| Constructor Detail |
public ImmutableRow(int nbells)
nbells.public ImmutableRow(Row row)
public ImmutableRow(java.lang.String row)
| Method Detail |
public final int hashCode()
hashCode in class Rowpublic final boolean isRounds()
public final boolean isTenorsTogether()
isTenorsTogether in class Rowpublic final boolean isTenorsHome()
isTenorsHome in class Rowpublic final boolean isPBrow()
isPBrow in class Rowpublic ImmutableRow permute(ImmutableRow r)
public ImmutableRow permute(byte[] perm)
public ImmutableRow change(byte[] pn)
PN.getChange(int).public void setRow(java.lang.String s)
setRow in class Rowpublic void setRow(Row r)
setRow in class Row
public void swap(int i,
int j)
swap in class Rowpublic void applyPermutation(Row permutation)
applyPermutation in class Rowpublic void applyPermutation(byte[] permutation)
applyPermutation in class Rowpublic void applyPN(byte[] pn)
applyPN in class Row
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||