Class Modulus11iWeightCheckDigit
- All Implemented Interfaces:
Serializable,CheckDigit
- Direct Known Subclasses:
Modulus11iBSNCheckDigit,Modulus11XCheckDigit,TidVATidSKCheckDigi,VATidSICheckDigit
Digits are weighted based by their position, from right to left.
This module is used to calculate some VATIN and TIN check digits. For instance: o nĂºmero de identificacao para efeitos do imposto sobre o valor acrescentado (NIPC) in Portugal or Burgerservicenummer (BSN) in the Netherlands. See Wikipedia - VAT IN for Portugal for more details.
A prominent possible subclass is ISBN10CheckDigit).
- Since:
- 1.10.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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, calculateModulus, 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 to handle weights as right position.
- 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
-
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 handle charValue 10.
- 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
-