Class TidBRCheckDigit

All Implemented Interfaces:
Serializable, CheckDigit

public final class TidBRCheckDigit extends Modulus11iWeightCheckDigit
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 Details

    • getInstance

      public static CheckDigit 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:
      getCheckdigitLength in class ModulusCheckDigit
    • weightedValue

      protected int weightedValue(int charValue, int leftPos, int rightPos) throws CheckDigitException
      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:
      weightedValue in class Modulus11iWeightCheckDigit
      Parameters:
      charValue - The numeric value of the character.
      leftPos - The position of the character in the code, counting from left to right
      rightPos - 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

      public String calculate(String code) throws CheckDigitException
      Calculate a modulus Check Digit for a code which does not yet have one.
      Specified by:
      calculate in interface CheckDigit
      Overrides:
      calculate in class ModulusCheckDigit
      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