Class Modulus11iWeightCheckDigit

java.lang.Object
org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
org.apache.commons.validator.routines.checkdigit.Modulus11iWeightCheckDigit
All Implemented Interfaces:
Serializable, CheckDigit
Direct Known Subclasses:
Modulus11iBSNCheckDigit, Modulus11XCheckDigit, TidVATidSKCheckDigi, VATidSICheckDigit

public class Modulus11iWeightCheckDigit extends ModulusCheckDigit
Check digit calculation based on modulus 11 and weights based on the digit position.

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 Details

    • getInstance

      public static CheckDigit getInstance()
      Gets the singleton instance of this validator.
      Returns:
      A singleton instance of the class.
    • 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.

      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:
      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 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

      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 handle charValue 10.

      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
    • 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