|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.pealfactory.ring.Row
public class Row
Represents a single row of bells, at any stage between kMINNBELLS and kMAXNBELLS (inclusive). The current number of bells in the row is kept, as well as the row itself as a character array. Methods are provided to permute rows (including applying place notation changes), and to analyse them, for example to discover whether the tenors are together, or whether the row is found in the plain course of Plain Bob at the appropriate stage.
Rows can be constructed from Strings of bell characters.
Normally these will look like the kROUNDS constant ("12345678"),
but we can use anything - e.g. "1--------" to draw just the treble
path. Rows constructed from kROUNDS can be converted to a byte array
representation using numbers 1...nbells - see toBytes().
Since Rows are mutable, we allow cloning for clients who want
to preserve a copy of a particular row. See also ImmutableRow.
Efficiency is a prime concern of this class, so methods are provided which avoid slow String operations and deal directly with Row and byte array objects. Performance advice for each method is given in the method javadoc.
| Field Summary | |
|---|---|
protected int |
fNBells
The 'size' (number of bells) of the row |
protected char[] |
fRow
Internal representation of the row |
| 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 | |
|---|---|
Row(int nbells)
Construct a row containing rounds on nbells. |
|
Row(Row r)
Make a Row from another Row (just like clone really). |
|
Row(java.lang.String s)
Construct a row from the String s, setting the number of bells from the string length. |
|
| Method Summary | |
|---|---|
void |
applyPermutation(byte[] permutation)
Permutes this row by the given change. |
void |
applyPermutation(Row permutation)
Permutes this row by the given Row transformation. |
void |
applyPN(byte[] pn)
Permute the row by a single change of place notation. |
int |
bellAt(int place)
Place is 1..nbells. |
void |
calcPermutation(Row r,
byte[] perm)
Given a Row r, calculates the permutation (as a byte[]) which would permute us to that row. |
java.lang.Object |
clone()
|
boolean |
equals(java.lang.Object o)
As well as comparing Row with Row, we can compare with a String - in this case, it doesn't matter if the String is longer than us, as the extra characters are dropped. |
int |
findBell(char bell)
Given a bell character from kROUNDS, returns the index at which the bell occurs in the row, 1..nbells. |
int |
getCoursingPairBitmap()
For lead heads only - returns a bitmap indicating which pairs of bells are in a coursing position at this lead. |
int |
getNBells()
Returns the current number of bells defined for this row. |
int |
hashCode()
The hashcode is based on that of the underlying row string, however the calculation is performed directly, to avoid the slow toString() conversion. |
boolean |
isPBrow()
Returns true if the current row occurs in a plain course of Plain Bob at this stage. |
private boolean |
isPBrow(boolean direction)
Returns true if the current row occurs in a plain course of Plain Bob at backstroke (when direction=true) or handstroke (direction=false). |
boolean |
isTenorsHome()
Returns true if the tenors (bells 7..n) are home. |
boolean |
isTenorsTogether()
Returns true if the tenors (bells 7..n) are in a PB leadhead position Calculates the answer every time, so cache if you want speed. |
int |
nextCourseBell(int i,
boolean evensUp)
Finds the next bell in Plain Bob coursing order from i (where i = 1..nbells). |
int |
nextCourseBellNoTreble(int i,
boolean evensUp)
Just like nextCourseBell() above, but always skips the treble (i.e. |
protected void |
setNBells(int n)
The number of bells in the row can be reduced but not increased. |
void |
setRow(Row r)
This is an efficient way to assign the contents of another Row to ourselves. |
void |
setRow(java.lang.String s)
Resets the row to the contents of the given String. |
void |
swap(int i,
int j)
Swap bells at i and j in this row, numbering from 1 as usual. |
void |
test(PN pn)
|
byte[] |
toBytes()
Returns the row as a byte[] with bells represented by bytes 1..nbells, not bell characters. |
java.lang.String |
toString()
Return the row as a String whose length is the current number of bells. |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected char[] fRow
protected int fNBells
| Constructor Detail |
|---|
public Row(int nbells)
nbells.
public Row(Row r)
public Row(java.lang.String s)
| Method Detail |
|---|
public void setRow(java.lang.String s)
public void setRow(Row r)
protected void setNBells(int n)
public java.lang.String toString()
toString in class java.lang.Objectpublic final byte[] toBytes()
public boolean equals(java.lang.Object o)
Optimisation: slow toString() conversions avoided.
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic final int getNBells()
public java.lang.Object clone()
clone in class java.lang.Objectpublic int findBell(char bell)
public final int bellAt(int place)
public void swap(int i,
int j)
public void test(PN pn)
public void applyPermutation(Row permutation)
public void applyPermutation(byte[] permutation)
public final void calcPermutation(Row r,
byte[] perm)
Final for speed.
public void applyPN(byte[] pn)
PN.getChange(int).
public boolean isTenorsHome()
public boolean isTenorsTogether()
public int nextCourseBell(int i,
boolean evensUp)
evensUp set, we move even bells up two
and odd bells down two, and vice versa.
For evensUp, the effect is to incrementally generate
(on 8 bells) the numbers 2 4 6 8 7 5 3 1 2 4 6 8...
public int nextCourseBellNoTreble(int i,
boolean evensUp)
public boolean isPBrow()
private boolean isPBrow(boolean direction)
public int getCoursingPairBitmap()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||