Class ECNumberCheckDigit

  • All Implemented Interfaces:
    java.io.Serializable, CheckDigit

    public final class ECNumberCheckDigit
    extends ModulusCheckDigit
    Modulus 11 EC number Check Digit calculation/validation.

    The European Community number (EC number) is a unique seven-digit identifier that is assigned to chemical substances. For example, the EC number of arsenic is 231-148-6:

    Check digit calculation is based on modulus 11 with digits being weighted based on their position (from left to right).

    For further information see Wikipedia - EC number.

    Since:
    1.9.0
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String calculate​(java.lang.String code)
      Calculate a modulus Check Digit for a code which does not yet have one.
      static CheckDigit getInstance()
      Gets the singleton instance of this validator.
      boolean isValid​(java.lang.String code)
      Validate a modulus check digit for a code.
      protected int weightedValue​(int charValue, int leftPos, int rightPos)
      Calculates the weighted value of a character in the code at a specified position.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getInstance

        public static CheckDigit getInstance()
        Gets the singleton instance of this validator.
        Returns:
        A singleton instance of the EC Number validator.
      • calculate

        public java.lang.String calculate​(java.lang.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​(java.lang.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
      • weightedValue

        protected int weightedValue​(int charValue,
                                    int leftPos,
                                    int rightPos)
        Calculates the weighted value of a character in the code at a specified position.

        For EC number digits are weighted by their position from left to right.

        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.