Class IsoIec7064PurePolynomialSystem
- All Implemented Interfaces:
Serializable
,CheckDigit
- Direct Known Subclasses:
IsoIecPolynomial11System
,IsoIecPolynomial1271System
,IsoIecPolynomial37System
,IsoIecPolynomial661System
,IsoIecPolynomial97System
- 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 int[]
Gets precomputed weights.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.IsoIec7064PureSystem
getCharacterSet, getCheckdigitLength, getRadix, isValid, toCheckDigit, toInt
Methods inherited from class org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
getModulus, sumDigits
-
Method Details
-
calculate
Calculate a modulus Check Digit for a code which does not yet have one.The polynomial method for the pure ISO/IEC 7064 Systems is computed by multiplying the value for each Character in the string by its weight.
- Specified by:
calculate
in interfaceCheckDigit
- Overrides:
calculate
in classIsoIec7064PureSystem
- 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.The polynomial method for the pure ISO/IEC 7064 Systems is computed by multiplying the value for each Character in the string by its weight. The weights can be precalculated.
- Overrides:
calculateModulus
in classIsoIec7064PureSystem
- 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
-
getWeightings
protected int[] getWeightings()Gets precomputed weights. Override this in subclasses.- Returns:
- precalculated weights defined for the first positions.
-
weightedValue
Description copied from class:IsoIec7064PureSystem
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.- Overrides:
weightedValue
in classIsoIec7064PureSystem
- 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
-