Class TidBRCheckDigit
java.lang.Object
org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
org.apache.commons.validator.routines.checkdigit.Modulus11iWeightCheckDigit
org.apache.commons.validator.routines.checkdigit.TidBRCheckDigit
- All Implemented Interfaces:
Serializable,CheckDigit
Brazil Tax identification number (TIN) Check Digit calculation/validation (Cadastro de Pessoas FĂsicas).
There are two checkdigits, both weighted with right position.
See Wikipedia (pt)r for more details.
- Since:
- 2.10.7
- Author:
- EUG https://github.com/homebeaver
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionCalculate a modulus Check Digit for a code which does not yet have one.protected intstatic CheckDigitGets the singleton instance of this validator.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.Modulus11iWeightCheckDigit
isValid, toCheckDigitMethods inherited from class org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
calculateModulus, getModulus, sumDigits, toInt
-
Method Details
-
getInstance
Gets the singleton instance of this validator.- Returns:
- A singleton instance of the class.
-
getCheckdigitLength
protected int getCheckdigitLength()Override because there are two checkdigits.
- Overrides:
getCheckdigitLengthin classModulusCheckDigit
-
weightedValue
Calculates the weighted value of a character in the code at a specified position.TIN digits are weighted by their position from right to left. Override for the first check digit. Weight is
(rightPos - 1).- Overrides:
weightedValuein classModulus11iWeightCheckDigit- Parameters:
charValue- The numeric value of the character.leftPos- The position of the character in the code, counting from left to rightrightPos- The positionof 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
-
calculate
Calculate 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
-