Class Modulus10_731CheckDigit
java.lang.Object
org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
org.apache.commons.validator.routines.checkdigit.Modulus10_731CheckDigit
- All Implemented Interfaces:
Serializable,CheckDigit,IsoIecConstants
Modulus 10 module for Check Digit calculation/validation of machine-readable travel document (MRTD).
MRTD has alphanumeric code. The last (check) digit is numeric.
Check digit calculation is based on modulus 10 with digits being weighted based by their position, to left to right.
See International Civil Aviation Organization, Doc 9303: Machine Readable Travel Documents, Part 3: Specifications Common to all MRTDs for more details.
- Since:
- 2.10.5
- See Also:
-
Field Summary
Fields inherited from interface org.apache.commons.validator.routines.checkdigit.IsoIecConstants
ALPHABETIC, ALPHABETIC23, ALPHANUMERIC, ALPHANUMERIC_PLUS_STAR, ALPHANUMERIC31, MODULUS_1271, MODULUS_23, MODULUS_31, MODULUS_37, MODULUS_661, MODULUS_97, NUMERIC, NUMERIC_PLUS_X, RADIX_10, RADIX_2, RADIX_26, RADIX_36 -
Method Summary
Modifier and TypeMethodDescriptionCalculate a modulus Check Digit for a code which does not yet have one.protected Stringstatic CheckDigitGets the singleton instance of this class.booleanValidate a modulus check digit for a code.protected inttoInt(char character, int leftPos, int rightPos) Convert a character at a specified position to an integer value.protected intweightedValue(int charValue, int leftPos, int rightPos) Calculates the weighted value of a character in the code at a specified position.Methods inherited from class org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
calculateModulus, getCheckdigitLength, getModulus, sumDigits, toCheckDigit
-
Method Details
-
getInstance
Gets the singleton instance of this class.- Returns:
- A singleton instance of the class.
-
weightedValue
protected int weightedValue(int charValue, int leftPos, int rightPos) Calculates the weighted value of a character in the code at a specified position.MRTD numbers are weighted in the following manner:
left position: 1 2 3 4 5 6 7 8 9 weight: 7 3 1 7 3 1 7 3 1- Specified by:
weightedValuein classModulusCheckDigit- Parameters:
charValue- The numeric value of the character.leftPos- The position of the character in the code, counting from left to rightrightPos- The position of the character in the code, counting from right to left- Returns:
- The weighted value of the character.
-
getCharacterSet
-
toInt
Convert a character at a specified position to an integer value.Note: this implementation only handlers numeric values For non-numeric characters, override this method to provide character-->integer conversion.
Overrides to handle numeric, alphabetic or alphanumeric values respectively.
- Overrides:
toIntin classModulusCheckDigit- Parameters:
character- The character to convertleftPos- The position of the character in the code, counting from left to right (for identifiying the position in the string)rightPos- The position of the character in the code, counting from right to left (not used here)- Returns:
- The integer value of the character
- Throws:
CheckDigitException- if character is non-numeric
-
calculate
Description copied from class:ModulusCheckDigitCalculate a modulus Check Digit for a code which does not yet have one.- Specified by:
calculatein interfaceCheckDigit- Overrides:
calculatein classModulusCheckDigit- Parameters:
code- The code for which to calculate the Check Digit; the check digit should not be included- Returns:
- The calculated Check Digit
- Throws:
CheckDigitException- if an error occurs calculating the check digit
-
isValid
Validate a modulus check digit for a code.- Specified by:
isValidin interfaceCheckDigit- Overrides:
isValidin classModulusCheckDigit- Parameters:
code- The code to validate- Returns:
trueif the check digit is valid, otherwisefalse
-