Class ECNumberCheckDigit
java.lang.Object
org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
org.apache.commons.validator.routines.checkdigit.ECNumberCheckDigit
- All Implemented Interfaces:
Serializable, CheckDigit
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:
-
Method Summary
Modifier and TypeMethodDescriptionCalculates a modulus Check Digit for a code which does not yet have one.static CheckDigitGets the singleton instance of this validator.booleanValidates a modulus check digit for a code.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 ModulusCheckDigit
calculateModulus, getModulus, sumDigits, toCheckDigit, toIntModifier and TypeMethodDescriptionprotected intcalculateModulus(String code, boolean includesCheckDigit) Calculates the modulus for a code.intGets the modulus value this check digit routine is based on.static intsumDigits(int number) Adds together the individual digits in a number.protected StringtoCheckDigit(int charValue) Converts an integer value to a check digit.protected inttoInt(char character, int leftPos, int rightPos) Converts a character at a specified position to an integer value.
-
Method Details
-
getInstance
Gets the singleton instance of this validator.- Returns:
- A singleton instance of the EC Number validator.
-
calculate
Calculates 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.
-
isValid
Validates a modulus check digit for a code.- Specified by:
isValidin interfaceCheckDigit- Overrides:
isValidin classModulusCheckDigit- Parameters:
code- The code to validate.- Returns:
trueif the check digit is valid, otherwisefalse.
-
weightedValue
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:
weightedValuein classModulusCheckDigit- 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.
-