Class Modulus31CheckDigit
java.lang.Object
org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
org.apache.commons.validator.routines.checkdigit.Modulus31CheckDigit
- All Implemented Interfaces:
Serializable,CheckDigit,IsoIecConstants
- Direct Known Subclasses:
Modulus511CheckDigit,TidVATidSKCheckDigi,VATidBECheckDigit,VATidLUCheckDigit
Implements Moduli-31 check digit calculation/validation.
Moduli-31 applies to finish TIN (HETU) number, the check digit has one alphanumeric char. See Wikipedia for more details.
- Since:
- 2.10.6
- Author:
- EUG https://github.com/homebeaver
- 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_511, MODULUS_661, MODULUS_89, MODULUS_97, NUMERIC, NUMERIC_PLUS_X, RADIX_10, RADIX_100, RADIX_2, RADIX_26, RADIX_36 -
Method Summary
Modifier and TypeMethodDescriptionprotected intcalculateModulus(String code, boolean includesCheckDigit) Calculate the modulus for a code.static CheckDigitGets the singleton instance of this validator.booleanValidate a modulus check digit for a code.protected StringtoCheckDigit(int charValue) Convert an integer value to a check digit.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
calculate, getCheckdigitLength, getModulus, sumDigits, toInt
-
Method Details
-
getInstance
Gets the singleton instance of this validator.- Returns:
- A singleton instance of the class.
-
weightedValue
Calculates the weighted value of a character in the code at a specified position.Some modulus routines weight the value of a character depending on its position in the code (e.g. ISBN-10), while others use different weighting factors for odd/even positions (e.g. EAN or Luhn). Implement the appropriate mechanism required by overriding this method.
Implement not used abstract method.
- Specified by:
weightedValuein classModulusCheckDigit- Parameters:
charValue- The numeric value of the characterleftPos- 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
- Throws:
CheckDigitException- if an error occurs calculating the weighted value
-
calculateModulus
Calculate the modulus for a code.Override to handle numeric value of code.
- Overrides:
calculateModulusin classModulusCheckDigit- Parameters:
code- The code to calculate the modulus for.includesCheckDigit- Whether the code includes the Check Digit or not.- Returns:
- The modulus value
- Throws:
CheckDigitException- if an error occurs calculating the modulus for the specified code
-
toCheckDigit
Convert an integer value to a check digit.Note: this implementation only handles single-digit numeric values For non-numeric characters, override this method to provide integer-->character conversion.
Override to map charValue to alphanumerics.
- Overrides:
toCheckDigitin classModulusCheckDigit- Parameters:
charValue- The integer value of the character- Returns:
- The converted character
- Throws:
CheckDigitException- if integer character value doesn't represent a numeric character
-
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
-