Class IsoIec7064HybridSystem
- All Implemented Interfaces:
Serializable,CheckDigit
- Direct Known Subclasses:
IsoIecHybrid1110System,IsoIecHybrid2726System,IsoIecHybrid3736System
Hybrid system algorithms use two modulus values, M+1 and M, and generate a single check character that will be the right most character of a valid input string.
There are three subclasses that implement
- ISO/IEC 7064, MOD 11,10 applies to numeric strings (
IsoIecHybrid1110System) - ISO/IEC 7064, MOD 27,26 applies to alphabetic strings (
IsoIecHybrid2726System) - ISO/IEC 7064, MOD 37,36 applies to alphanumeric strings (
IsoIecHybrid3736System)
The two numbers following “MOD” in the designation are the two modulus.
- Since:
- 1.10.0
- Author:
- EUG https://github.com/homebeaver
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionCalculate a modulus Check Digit for a code which does not yet have one.protected intcalculateModulus(String code, boolean includesCheckDigit) Calculate the modulus for a code.protected abstract StringThe character set of the item to be protected.booleanValidate a modulus check digit for a code.protected StringtoCheckDigit(int checkdigit) Convert an integer value to a check digit.protected inttoInt(char character, int leftPos, int rightPos) Convert a character at a specified position to an integer value.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 org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
getModulus, sumDigits
-
Method Details
-
getCharacterSet
The character set of the item to be protected.- Returns:
- a String of characters (numeric, alphabetic or alphanumeric)
-
weightedValue
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.
Overrides because there is no need for a weight
- Specified by:
weightedValuein classModulusCheckDigit- Parameters:
charValue- The numeric value of the characterleftPos- The position of the character in the code, counting from left to rightrightPos- 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
Description copied from class:ModulusCheckDigitConvert 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.
- Overrides:
toCheckDigitin classModulusCheckDigit- Parameters:
checkdigit- The integer value of the character- Returns:
- The converted character
- Throws:
CheckDigitException- if integer character value doesn't represent a numeric character
-
calculate
Calculate 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
-
calculateModulus
Calculate the modulus for a code.- Overrides:
calculateModulusin classModulusCheckDigit- Parameters:
code- The code to calculate the modulus for.includesCheckDigit- Whether the code includes the Check Digit or not.- Returns:
- The modulus value
- Throws:
CheckDigitException- if an error occurs calculating the modulus for the specified code
-
isValid
Validate 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
-
toInt
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 to handle numeric, alphabetic or alphanumeric values respectively.
- Overrides:
toIntin classModulusCheckDigit- Parameters:
character- The character to convertleftPos- 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
-