public final class VerhoeffCheckDigit extends java.lang.Object implements CheckDigit, java.io.Serializable
Check digit calculation for numeric codes using a Dihedral Group of order 10.
See Wikipedia - Verhoeff algorithm for more details.
Modifier and Type | Field and Description |
---|---|
private static int[][] |
D_TABLE
D - multiplication table
|
private static int[] |
INV_TABLE
inv: inverse table
|
private static int[][] |
P_TABLE
P - permutation table
|
private static long |
serialVersionUID |
static CheckDigit |
VERHOEFF_CHECK_DIGIT
Singleton Verhoeff Check Digit instance
|
Constructor and Description |
---|
VerhoeffCheckDigit() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
calculate(java.lang.String code)
Calculate a Verhoeff Check Digit for a code.
|
private int |
calculateChecksum(java.lang.String code,
boolean includesCheckDigit)
Calculate the checksum.
|
boolean |
isValid(java.lang.String code)
Validate the Verhoeff Check Digit for a code.
|
private static final long serialVersionUID
public static final CheckDigit VERHOEFF_CHECK_DIGIT
private static final int[][] D_TABLE
private static final int[][] P_TABLE
private static final int[] INV_TABLE
public boolean isValid(java.lang.String code)
isValid
in interface CheckDigit
code
- The code to validatetrue
if the check digit is valid,
otherwise false
public java.lang.String calculate(java.lang.String code) throws CheckDigitException
calculate
in interface CheckDigit
code
- The code to calculate the Check Digit forCheckDigitException
- if an error occurs calculating
the check digit for the specified codeprivate int calculateChecksum(java.lang.String code, boolean includesCheckDigit) throws CheckDigitException
code
- The code to calculate the checksum for.includesCheckDigit
- Whether the code includes the Check Digit or not.CheckDigitException
- if the code contains an invalid character (i.e. not numeric)