Class ISSNCheckDigit
- All Implemented Interfaces:
Serializable, CheckDigit
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
- Since:
- 1.5.0
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanValidates a modulus check digit for a code.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.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
calculate, calculateModulus, getModulus, sumDigitsModifier and TypeMethodDescriptionCalculates a modulus Check Digit for a code which does not yet have one.protected 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.
-
Field Details
-
ISSN_CHECK_DIGIT
Singleton ISSN Check Digit instance.
-
-
Constructor Details
-
ISSNCheckDigit
public ISSNCheckDigit()Creates the instance using a checkdigit modulus of 11.
-
-
Method Details
-
isValid
Validates a modulus check digit for a code.The
9 - leftPosweighting gives a ninth character a weight of zero, so an over-length code left the trailing characters unweighted and still passed the modulus test (for example every03178471+ digit validated). The length is checked here so only a genuine eight-character ISSN reaches the check digit test.- Specified by:
isValidin interfaceCheckDigit- Overrides:
isValidin classModulusCheckDigit- Parameters:
code- The code to validate.- Returns:
trueif the check digit is valid, otherwisefalse.
-
toCheckDigit
Description copied from class:ModulusCheckDigitConverts 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:
charValue- The integer value of the character.- Returns:
- The converted character.
- Throws:
CheckDigitException- if integer character value. doesn't represent a numeric character.
-
toInt
Description copied from class:ModulusCheckDigitConverts 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:
toIntin classModulusCheckDigit- Parameters:
character- The character to convert.leftPos- The position of the character in the code, counting from left to right (for identifying 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
Description copied from class:ModulusCheckDigitCalculates 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 (for example, ISBN-10), while others use different weighting factors for odd/even positions (for example, EAN or Luhn). Implement the appropriate mechanism required by overriding this method.
- 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.
- Throws:
CheckDigitException- if an error occurs calculating. the weighted value.
-