Class VerhoeffCheckDigit
- java.lang.Object
-
- org.apache.commons.validator.routines.checkdigit.VerhoeffCheckDigit
-
- All Implemented Interfaces:
java.io.Serializable,CheckDigit
public final class VerhoeffCheckDigit extends java.lang.Object implements CheckDigit, java.io.Serializable
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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static int[][]D_TABLED - multiplication tableprivate static int[]INV_TABLEinv: inverse tableprivate static int[][]P_TABLEP - permutation tableprivate static longserialVersionUIDstatic CheckDigitVERHOEFF_CHECK_DIGITSingleton Verhoeff Check Digit instance
-
Constructor Summary
Constructors Constructor Description VerhoeffCheckDigit()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringcalculate(java.lang.String code)Calculate a Verhoeff Check Digit for a code.private intcalculateChecksum(java.lang.String code, boolean includesCheckDigit)Calculate the checksum.booleanisValid(java.lang.String code)Validate the Verhoeff Check Digit for a code.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
VERHOEFF_CHECK_DIGIT
public static final CheckDigit VERHOEFF_CHECK_DIGIT
Singleton Verhoeff Check Digit instance
-
D_TABLE
private static final int[][] D_TABLE
D - multiplication table
-
P_TABLE
private static final int[][] P_TABLE
P - permutation table
-
INV_TABLE
private static final int[] INV_TABLE
inv: inverse table
-
-
Method Detail
-
isValid
public boolean isValid(java.lang.String code)
Validate the Verhoeff Check Digit for a code.- Specified by:
isValidin interfaceCheckDigit- Parameters:
code- The code to validate- Returns:
trueif the check digit is valid, otherwisefalse
-
calculate
public java.lang.String calculate(java.lang.String code) throws CheckDigitExceptionCalculate a Verhoeff Check Digit for a code.- Specified by:
calculatein 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
private int calculateChecksum(java.lang.String code, boolean includesCheckDigit) throws CheckDigitExceptionCalculate 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)
-
-