org.pealfactory.ring
Class PN

java.lang.Object
  |
  +--org.pealfactory.ring.PN
All Implemented Interfaces:
Constants

public class PN
extends java.lang.Object
implements Constants

Represents a set of place notation, parsed from a String which may be in any recognised format. The place notation is held in an internal format in which each change is represented by a byte array - see getChange(int). These byte arrays are suitable for application to Row objects using the call Row.applyPN(byte[]). Symmetric notations are expanded during parsing, so one place notation change is available for every row of a method's lead.

For information about the notation formats supported by this class, see the javadoc for the (private) parse() method. For the bell place characters expected on higher numbers, see Constants.kROUNDS.

Various properties of the place notation are available for query once the PN object has been constructed, including whether the notation is symmetric, whether it is right-place, and the stage (highest bell number) it applies to. The latter property is "guessed" by the parser and may not be accurate for notation formats in which final external places are not given.

Some attention to performance issues has been paid in the design of this class, but if performance is critical direct use of place notation permutations should be avoided.


Field Summary
private  boolean fContainsCross
          True if PN contains cross notation - used for guessing number of bells
private  int fHighestPlace
          The highest place made in the PN, used for guessing number of bells (0 = lead)
private  int fHighestPlaceNotHalfLead
          The highest place made in the PN not at the half-lead, used for guessing number of bells (0 = lead)
private  java.lang.String fOriginalString
           
private  byte[][] fPN
          Contains a byte[] for each change in original PN
private static byte[] kCROSSCHANGE
          Cross change X represented as a 0-length array
 
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
PN(java.lang.String pn)
           
 
Method Summary
private  boolean changesEqual(byte[] pn1, byte[] pn2)
          Returns true if two place notation changes are equal - note that the final place is important, so if one change specifies "n" and the other doesn't, they won't match.
 byte[] getChange(int i)
          Gets the place notation for a particular change.
 int getLength()
           
 int guessNBells()
          Tries to work out the stage of the method represented by the place notation.
 int highestPlace()
          Returns the highest place made in the pn.
 boolean isRightPlace()
          A right-place method has an even-length lead, and every even change is a cross.
 boolean isRotationallySymmetric(int nbells)
          Returns true if the place notation has double-method symmetry (to see whether it represents a double method, test isSymmetric() as well).
 boolean isSymmetric()
          Returns true if place notation is symmetrical about the halfway point.
private  void parse()
          Parses place notation String, placing results into internal format array ready for use.
private  int reflectSymmetricNotation(int fromHere, java.util.Vector pn)
          Adds reflected notation between fromHere up to but not including the current PN entry, which is taken as the pivot point.
private  byte[] reverseChange(byte[] pn1, int nbells)
          Swap change front to back, e.g.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

kCROSSCHANGE

private static final byte[] kCROSSCHANGE
Cross change X represented as a 0-length array

fOriginalString

private java.lang.String fOriginalString

fPN

private byte[][] fPN
Contains a byte[] for each change in original PN

fHighestPlace

private int fHighestPlace
The highest place made in the PN, used for guessing number of bells (0 = lead)

fHighestPlaceNotHalfLead

private int fHighestPlaceNotHalfLead
The highest place made in the PN not at the half-lead, used for guessing number of bells (0 = lead)

fContainsCross

private boolean fContainsCross
True if PN contains cross notation - used for guessing number of bells
Constructor Detail

PN

public PN(java.lang.String pn)
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getLength

public int getLength()

getChange

public byte[] getChange(int i)
Gets the place notation for a particular change. This is a parsed representation as a byte array which lists the places made, where 0 = lead. Initial external places (ie 0) are always present, but final external places (ie nbells-1) may not be. An empty byte[] represents the cross change X.

guessNBells

public int guessNBells()
Tries to work out the stage of the method represented by the place notation. Not necessarily accurate if external places haven't been given!

highestPlace

public int highestPlace()
Returns the highest place made in the pn.

isRightPlace

public boolean isRightPlace()
A right-place method has an even-length lead, and every even change is a cross.

isSymmetric

public boolean isSymmetric()
Returns true if place notation is symmetrical about the halfway point.

isRotationallySymmetric

public boolean isRotationallySymmetric(int nbells)
Returns true if the place notation has double-method symmetry (to see whether it represents a double method, test isSymmetric() as well).

changesEqual

private boolean changesEqual(byte[] pn1,
                             byte[] pn2)
Returns true if two place notation changes are equal - note that the final place is important, so if one change specifies "n" and the other doesn't, they won't match.

reverseChange

private byte[] reverseChange(byte[] pn1,
                             int nbells)
Swap change front to back, e.g. for double method testing.

parse

private void parse()
Parses place notation String, placing results into internal format array ready for use. It automatically handles any of the following standard notations: In any format, either 'x' or '-' can be used to represent the cross change. Other standard characters are '.' to separate adjacent non-cross notations, and of course letters from the Rounds string "1234567890ETABCDFGHJ" to represent places made. Spaces are normally ignored (except in the special case before a leadhead in the CC format) and upper or lower case characters are always treated the same.

reflectSymmetricNotation

private int reflectSymmetricNotation(int fromHere,
                                     java.util.Vector pn)
Adds reflected notation between fromHere up to but not including the current PN entry, which is taken as the pivot point.
Returns:
the number of relected changes added.