Interface CheckDigit

All Known Implementing Classes:
IbanCheckDigit

public interface CheckDigit
A check digit is a form of redundancy check used for error detection on identification numbers, such as bank account numbers, which are used in an application where they will at least sometimes be input manually. It consists of one or more digits (or letters) computed by an algorithm from the other digits (or letters) in the sequence input.

With a check digit, one can detect simple errors in the input of a series of characters (usually digits) such as a single mistyped digit or some permutations of two successive digits.

A class that implements this interface implements one of the many existing algorithms for calculating and validating check digits, such as one defined in ISO/IEC 7064.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Calculates the check digit for a given input string.
    boolean
    Validates the check digit for the given input string.
  • Method Details

    • calculate

      String calculate(String input)
      Calculates the check digit for a given input string.
      Parameters:
      input - the non-null input string to calculate the check digit for
      Returns:
      a non-null string
      Throws:
      IllegalArgumentException - if the check digit cannot be computed for the given input string (because it is null, to short...)
    • validate

      boolean validate(String input)
      Validates the check digit for the given input string.

      Invalid input strings, such as null, are considered invalid and do not throw any exception.

      Parameters:
      input - the input string to validate, may be null
      Returns:
      true if the check digit is verified, false otherwise