ISSNCheckDigit (Apache Commons Validator 1.11.0 API)
Description: declaration: package: org.apache.commons.validator.routines.checkdigit, class: ISSNCheckDigit

# Class ISSNCheckDigit

java.lang.Object
org.apache.commons.validator.routines.checkdigit.ModulusCheckDigit
org.apache.commons.validator.routines.checkdigit.ISSNCheckDigit

All Implemented Interfaces:
  `Serializable, CheckDigit`

public final class ISSNCheckDigit extends ModulusCheckDigit
International Standard Serial Number (ISSN) is an eight-digit serial number used to uniquely identify a serial publication.

    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:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final CheckDigit`
  `ISSN_CHECK_DIGIT`
  Singleton ISSN Check Digit instance.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ISSNCheckDigit()`
  Creates the instance using a checkdigit modulus of 11.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `isValid(String code)`
  Validates a modulus check digit for a code.
  `protected String`
  `toCheckDigit(int charValue)`
  Converts an integer value to a check digit.
  `protected int`
  `toInt(char character, int leftPos, int rightPos)`
  Converts 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 ModulusCheckDigit

  `calculate, calculateModulus, getModulus, sumDigits`
  Modifier and Type
  Method
  Description
  `String`
  `calculate(String code)`
  Calculates a modulus Check Digit for a code which does not yet have one.
  `protected int`
  `calculateModulus(String code, boolean includesCheckDigit)`
  Calculates the modulus for a code.
  `int`
  `getModulus()`
  Gets the modulus value this check digit routine is based on.
  `static int`
  `sumDigits(int number)`
  Adds together the individual digits in a number.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### ISSN_CHECK_DIGIT

    public static final CheckDigit 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

    public boolean isValid(String code)
    Validates a modulus check digit for a code.

    The `9 - leftPos` weighting 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 every `03178471` + digit validated). The length is checked here so only a genuine eight-character ISSN reaches the check digit test.

    Specified by:
      `isValid` in interface `CheckDigit`
    Overrides:
      `isValid` in class `ModulusCheckDigit`
    Parameters:
      `code` - The code to validate.
    Returns:
      `true` if the check digit is valid, otherwise `false`.

  - ### toCheckDigit

    protected String toCheckDigit(int charValue) throws CheckDigitException
    Description copied from class: `ModulusCheckDigit`
    Converts 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 class `ModulusCheckDigit`
    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

    protected int toInt(char character, int leftPos, int rightPos) throws CheckDigitException
    Description copied from class: `ModulusCheckDigit`
    Converts 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:
      `toInt` in class `ModulusCheckDigit`
    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

    protected int weightedValue(int charValue, int leftPos, int rightPos) throws CheckDigitException
    Description copied from class: `ModulusCheckDigit`
    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 (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:
      `weightedValue` in class `ModulusCheckDigit`
    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.