Class IsoIec7064PureSystem
- All Implemented Interfaces:
Serializable
,CheckDigit
- Direct Known Subclasses:
IsoIec7064PurePolynomialSystem
,IsoIecPure11System
,IsoIecPure1271System
,IsoIecPure37System
,IsoIecPure661System
,IsoIecPure97System
,Modulus97CheckDigit
- ISO/IEC 7064, MOD 11-2 applies to numeric strings (
IsoIecPure11System
) - ISO/IEC 7064, MOD 37-2 applies to alphanumeric strings (
IsoIecPure37System
) - ISO/IEC 7064, MOD 97-10 applies to numeric strings (
IsoIecPure97System
) - ISO/IEC 7064, MOD 661-26 applies to alphabetic strings (
IsoIecPure661System
) - ISO/IEC 7064, MOD 1271_36 applies to alphanumeric strings (
IsoIecPure1271System
)
Pure system algorithms use a single modulus value ModulusCheckDigit.getModulus()
and a radix getRadix()
,
f.i. the modulus for MOD 11-2 is 11, the radix is 2.
There is also an alternative polynomial implementation for the pure systems,
see IsoIec7064PurePolynomialSystem
and subclasses.
The standard also defines hybrid systems with two modulus values (see IsoIec7064HybridSystem
).
- 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 int
calculateModulus
(String code, boolean includesCheckDigit) Calculate the modulus for a code.protected abstract String
MOD 11-2 check characters are “0” to “9” plus “X” for example.int
Returns the lentgth of the check digit for the systemprotected abstract int
getRadix()
Radix is the second number following “MOD” in the ISO/IEC designation, f.i. 2 for "MOD 11-2"boolean
Validate a modulus check digit for a code.protected String
toCheckDigit
(int checksum) Convert an integer value to a check digit.protected int
toInt
(char character, int leftPos, int rightPos) Convert a character at a specified position to an integer value.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 org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
getModulus, sumDigits
-
Method Details
-
getRadix
protected abstract int getRadix()Radix is the second number following “MOD” in the ISO/IEC designation, f.i. 2 for "MOD 11-2"- Returns:
- the radix of the Check Digit routine
-
getCharacterSet
MOD 11-2 check characters are “0” to “9” plus “X” for example.- Returns:
- a String containing characters the check digit is build from.
This can be
IsoIecConstants.NUMERIC
,IsoIecConstants.ALPHABETIC
,IsoIecConstants.ALPHANUMERIC
,IsoIecConstants.NUMERIC_PLUS_X
,IsoIecConstants.ALPHANUMERIC_PLUS_STAR
-
getCheckdigitLength
public int getCheckdigitLength()Returns the lentgth of the check digit for the system- Returns:
- checkdigitLength can be one ore two chars
-
isValid
Description copied from class:ModulusCheckDigit
Validate a modulus check digit for a code.- Specified by:
isValid
in interfaceCheckDigit
- Overrides:
isValid
in classModulusCheckDigit
- Parameters:
code
- The code to validate- Returns:
true
if the check digit is valid, otherwisefalse
-
calculate
Description copied from class:ModulusCheckDigit
Calculate a modulus Check Digit for a code which does not yet have one.- Specified by:
calculate
in interfaceCheckDigit
- Overrides:
calculate
in 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
Description copied from class:ModulusCheckDigit
Calculate the modulus for a code.- Overrides:
calculateModulus
in 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
-
toCheckDigit
Description copied from class:ModulusCheckDigit
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.
- Overrides:
toCheckDigit
in classModulusCheckDigit
- Parameters:
checksum
- The integer value of the character- Returns:
- The converted character
- Throws:
CheckDigitException
- if integer character value doesn't represent a numeric character
-
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:
toInt
in 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
-
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 in ISO/IEC 7064 pure recursive/iterative computation. However for polynomial calculation this method is used.
Weights are defined in subclasses for the first fifteen positions only. The series can be extended indefinitely, using the formula
wi = r^(i - 1) (mod M)
where wi is the weight for Position i.NOTE: do not use
Math.pow
for high results, f.i.10^23 (mod 97) = 56
. Calculate it iteratively instead.- Specified by:
weightedValue
in 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
-