Class VerhoeffCheckDigit
java.lang.Object
org.apache.commons.validator.routines.checkdigit.VerhoeffCheckDigit
- All Implemented Interfaces:
Serializable
,CheckDigit
Verhoeff (Dihedral) Check Digit calculation/validation.
Check digit calculation for numeric codes using a Dihedral Group of order 10.
See Wikipedia - Verhoeff algorithm for more details.
- Since:
- Validator 1.4
- Version:
- $Revision: 1649191 $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[][]
D - multiplication tableprivate static final int[]
inv: inverse tableprivate static final int[][]
P - permutation tableprivate static final long
static final CheckDigit
Singleton Verhoeff Check Digit instance -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
VERHOEFF_CHECK_DIGIT
Singleton Verhoeff Check Digit instance -
D_TABLE
private static final int[][] D_TABLED - multiplication table -
P_TABLE
private static final int[][] P_TABLEP - permutation table -
INV_TABLE
private static final int[] INV_TABLEinv: inverse table
-
-
Constructor Details
-
VerhoeffCheckDigit
public VerhoeffCheckDigit()
-
-
Method Details
-
isValid
Validate the Verhoeff Check Digit for a code.- Specified by:
isValid
in interfaceCheckDigit
- Parameters:
code
- The code to validate- Returns:
true
if the check digit is valid, otherwisefalse
-
calculate
Calculate a Verhoeff Check Digit for a code.- Specified by:
calculate
in interfaceCheckDigit
- Parameters:
code
- The code to calculate the Check Digit for- Returns:
- The calculated Check Digit
- Throws:
CheckDigitException
- if an error occurs calculating the check digit for the specified code
-
calculateChecksum
Calculate the checksum.- Parameters:
code
- The code to calculate the checksum for.includesCheckDigit
- Whether the code includes the Check Digit or not.- Returns:
- The checksum value
- Throws:
CheckDigitException
- if the code contains an invalid character (i.e. not numeric)
-