public final class ISSNCheckDigit extends ModulusCheckDigit
The format is: ISSN dddd-dddC where: d = decimal digit (0-9) C = checksum (0-9 or X) The checksum is formed by adding the first 7 digits multiplied by the position in the entire number (counting from the right). For example, abcd-efg would be 8a + 7b + 6c + 5d + 4e +3f +2g. The check digit is modulus 11, where the value 10 is represented by 'X' For example: ISSN 0317-8471 ISSN 1050-124X
Note: This class expects the input to be numeric only, with all formatting removed. For example:
03178471 1050124X
Modifier and Type | Field and Description |
---|---|
static CheckDigit |
ISSN_CHECK_DIGIT
Singleton ISSN Check Digit instance
|
Constructor and Description |
---|
ISSNCheckDigit()
Creates the instance using a checkdigit modulus of 11
|
Modifier and Type | Method and Description |
---|---|
protected String |
toCheckDigit(int charValue)
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.
|
calculate, calculateModulus, getModulus, isValid, sumDigits
public static final CheckDigit ISSN_CHECK_DIGIT
public ISSNCheckDigit()
protected int weightedValue(int charValue, int leftPos, int rightPos) throws CheckDigitException
ModulusCheckDigit
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.
weightedValue
in class ModulusCheckDigit
charValue
- The numeric value of the characterleftPos
- The position of the character in the code, counting from left to rightrightPos
- The positionof the character in the code, counting from right to leftCheckDigitException
- if an error occurs calculating
the weighted valueprotected String toCheckDigit(int charValue) throws CheckDigitException
ModulusCheckDigit
Note: this implementation only handles single-digit numeric values For non-numeric characters, override this method to provide integer-->character conversion.
toCheckDigit
in class ModulusCheckDigit
charValue
- The integer value of the characterCheckDigitException
- if integer character value
doesn't represent a numeric characterprotected int toInt(char character, int leftPos, int rightPos) throws CheckDigitException
ModulusCheckDigit
Note: this implementation only handlers numeric values For non-numeric characters, override this method to provide character-->integer conversion.
toInt
in class ModulusCheckDigit
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)CheckDigitException
- if character is non-numericCopyright © 2002–2020 The Apache Software Foundation. All rights reserved.