Class CheckDigits

java.lang.Object
org.emau.icmvc.ganimed.ttp.psn.generator.CheckDigits
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
CheckDigit

public abstract class CheckDigits extends Object implements Serializable
An abstract common parent class for all check-digit-generators. Subclasses only have to provide implementations for generateCheckDigits(String), check(String, int), an getAlphabetRestriction(). For single-digit generating algorithms there is another abstract subclass CheckDigit simplifying further subclassing only leaving CheckDigit.calculateCheckDigit(String) to implement.

In order to add further implementations and making them actually visible by the system, a few other things (besides the actual implementation) must be taken into account. Their class names must be added in (or registered with)

See Also:
  • Field Details

    • logger

      protected final transient org.slf4j.Logger logger
  • Constructor Details

    • CheckDigits

      protected CheckDigits()
    • CheckDigits

      protected CheckDigits(Alphabet alphabet)
  • Method Details

    • getAlphabetRestriction

      public abstract GeneratorAlphabetRestriction getAlphabetRestriction()
      Returns the restriction for the number of chars within the alphabet.
      Returns:
      the restriction for the number of chars within the alphabet
    • generateCheckDigits

      public abstract String generateCheckDigits(String message) throws CharNotInAlphabetException, InvalidParameterException
      Parameters:
      message - string for which check digits should be generated
      Returns:
      check digits
      Throws:
      CharNotInAlphabetException - if the message contains characters which are not contained in the alphabet
      InvalidParameterException - if the message is not valid for other reasons
    • check

      public abstract void check(String value, int messageLength) throws CharNotInAlphabetException, InvalidPSNException
      Parameters:
      value - string (including check digits) to be checked
      messageLength - length of [value] without check digits
      Throws:
      CharNotInAlphabetException - if the value contains characters which are not contained in the alphabet
      InvalidPSNException - if the value is not a valid pseudonym
    • getMaxMessageLength

      public int getMaxMessageLength()
      Returns the theoretic maximum length of messages this algorithm is able to compute check digits for (but at most DomainConfig.getMaxNumberOfCharactersInFullyQualifiedPsn()).
      Returns:
      the theoretic maximum length of messages this algorithm is able to compute check digits for (but at most DomainConfig.getMaxNumberOfCharactersInFullyQualifiedPsn())
    • getAlphabet

      public Alphabet getAlphabet()
      Returns the alphabet for this instance.
      Returns:
      the alphabet for this instance
    • getNumberOfCheckDigits

      public abstract int getNumberOfCheckDigits(int messageLength)
      Returns the number of check digits computed by this algorithm for a message with a given length.
      Parameters:
      messageLength - the length of the message
      Returns:
      the number of check digits computed by this algorithm for a message with a given length
    • getEffectiveMaxMessageLength

      public final int getEffectiveMaxMessageLength()
      Returns the maximum length of messages for which the resulting value including check digits is not longer than DomainConfig.getMaxNumberOfCharactersInFullyQualifiedPsn().
      Returns:
      the maximum length of messages for which the resulting value including check digits is not longer than DomainConfig.getMaxNumberOfCharactersInFullyQualifiedPsn()
    • getEffectiveMaxMessageLength

      public int getEffectiveMaxMessageLength(int total)
      Returns the maximum length of messages for which the resulting value including check digits is not longer than the given total.
      Returns:
      the maximum length of messages for which the resulting value including check digits is not longer than the given total
    • toNumber

      protected int[] toNumber(String message) throws CharNotInAlphabetException
      Throws:
      CharNotInAlphabetException
    • toMessage

      protected String toMessage(int[] number)
    • isDeprecated

      public boolean isDeprecated()
      Returns true if this algorithm is deprecated and should not be used for new domains. Creating new domains with deprecated check digit algorithms is not permitted and leads to error messages. The default implementation returns false.
      Returns:
      true if this algorithm is deprecated and should not be used for new domains
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isDeprecated

      public static boolean isDeprecated(String checkDigitAlgorithm)
      Returns true if the given string describes a deprecated algorithm. Unknown or invalid algorithms are considered to be deprecated, too.
      Parameters:
      checkDigitAlgorithm - the algorithm class name
      Returns:
      true if the given string describes a deprecated algorithm
    • createCheckDigitClass

      public static Class<? extends CheckDigits> createCheckDigitClass(String checkDigitClassName) throws InvalidCheckDigitClassException
      Creates a CheckDigits class for a class name
      Parameters:
      checkDigitClassName - the name of the class
      Returns:
      the class for the name
      Throws:
      InvalidCheckDigitClassException - when the class name does not denote a visible CkeckDigits class
    • createCheckDigits

      public static CheckDigits createCheckDigits(String checkDigitClassName) throws InvalidCheckDigitClassException
      Creates a skeleton CheckDigits instance for a class name without alphabet and domain config.
      Parameters:
      checkDigitClassName - the name of the class
      Returns:
      the instance
      Throws:
      InvalidCheckDigitClassException - when the class name does not denote a visible CkeckDigits class
    • createCheckDigits

      public static CheckDigits createCheckDigits(String checkDigitClassName, Alphabet alphabet, DomainConfig config) throws InvalidCheckDigitClassException, InvalidGeneratorException
      Creates a CheckDigits instance for a class name with alphabet and domain config.
      Parameters:
      checkDigitClassName - the name of the class
      alphabet - the alphabet
      config - the domain config
      Returns:
      the instance
      Throws:
      InvalidCheckDigitClassException - if the class name does not denote a visible CheckDigits class
      InvalidGeneratorException - if the CheckDigits algorithm is not compatible with the alphabet
    • createCheckDigits

      public static CheckDigits createCheckDigits(Class<? extends CheckDigits> checkDigitClass, Alphabet alphabet, DomainConfig config) throws InvalidGeneratorException
      Creates a CheckDigits instance for a given class with alphabet and domain config.
      Parameters:
      checkDigitClass - the class
      alphabet - the alphabet
      config - the domain config
      Returns:
      the instance
      Throws:
      InvalidGeneratorException - if the CheckDigits algorithm is not compatible with the alphabet