Class TidITCheckDigit

java.lang.Object
org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
org.apache.commons.validator.routines.checkdigit.TidITCheckDigit
All Implemented Interfaces:
Serializable, CheckDigit, IsoIecConstants

public final class TidITCheckDigit extends ModulusCheckDigit implements IsoIecConstants
Italian Tax identification number (TIN) Check Digit calculation/validation.

Codice fiscale

See Wikipedia (it) for more details.

Since:
2.10.6
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.
    • toInt

      protected int toInt(char character, int leftPos, int rightPos) throws CheckDigitException
      Description copied from class: ModulusCheckDigit
      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:
      toInt in class ModulusCheckDigit
      Parameters:
      character - The character to convert
      leftPos - 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
    • weightedValue

      protected int weightedValue(int charValue, int leftPos, int rightPos) throws CheckDigitException
      The weighted value of a character in the the value of the character.
      Specified by:
      weightedValue in class ModulusCheckDigit
      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 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
    • isValid

      public boolean isValid(String code)
      Validate a modulus check digit for a code.
      Specified by:
      isValid in interface CheckDigit
      Overrides:
      isValid in class ModulusCheckDigit
      Parameters:
      code - The code to validate
      Returns:
      true if the check digit is valid, otherwise false
    • toCheckDigit

      protected String toCheckDigit(int charValue) throws CheckDigitException
      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 get the non numeric check character

      Overrides:
      toCheckDigit in class ModulusCheckDigit
      Parameters:
      charValue - The integer value of the character
      Returns:
      The converted character
      Throws:
      CheckDigitException - if integer character value doesn't represent a numeric character