Class CheckDigits
java.lang.Object
org.emau.icmvc.ganimed.ttp.psn.generator.CheckDigits
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
CheckDigit
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)
- gpas-web/src/main/java/org/emau/icmvc/ttp/psn/frontend/util/Generators.java and respected at its usages,
- gpas-web/src/main/resources/classPathReference.properties:59:generator_class,
- gpas-web/src/main/resources/generatorClasses.properties,
-
gpas-web/src/main/resources/messages_de.properties with prefix
domain.checkDigitGenerator, and -
gpas-web/src/main/resources/messages_en.properties with prefix
domain.checkDigitGenerator.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidstatic Class<? extends CheckDigits> createCheckDigitClass(String checkDigitClassName) Creates a CheckDigits class for a class namestatic CheckDigitscreateCheckDigits(Class<? extends CheckDigits> checkDigitClass, Alphabet alphabet, DomainConfig config) Creates a CheckDigits instance for a given class with alphabet and domain config.static CheckDigitscreateCheckDigits(String checkDigitClassName) Creates a skeleton CheckDigits instance for a class name without alphabet and domain config.static CheckDigitscreateCheckDigits(String checkDigitClassName, Alphabet alphabet, DomainConfig config) Creates a CheckDigits instance for a class name with alphabet and domain config.abstract StringgenerateCheckDigits(String message) Returns the alphabet for this instance.abstract GeneratorAlphabetRestrictionReturns the restriction for the number of chars within the alphabet.final intReturns the maximum length of messages for which the resulting value including check digits is not longer thanDomainConfig.getMaxNumberOfCharactersInFullyQualifiedPsn().intgetEffectiveMaxMessageLength(int total) Returns the maximum length of messages for which the resulting value including check digits is not longer than the given total.intReturns the theoretic maximum length of messages this algorithm is able to compute check digits for (but at mostDomainConfig.getMaxNumberOfCharactersInFullyQualifiedPsn()).abstract intgetNumberOfCheckDigits(int messageLength) Returns the number of check digits computed by this algorithm for a message with a given length.booleanReturns true if this algorithm is deprecated and should not be used for new domains.static booleanisDeprecated(String checkDigitAlgorithm) Returns true if the given string describes a deprecated algorithm.protected StringtoMessage(int[] number) protected int[]toString()
-
Field Details
-
logger
protected final transient org.slf4j.Logger logger
-
-
Constructor Details
-
CheckDigits
protected CheckDigits() -
CheckDigits
-
-
Method Details
-
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 alphabetInvalidParameterException- 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 checkedmessageLength- length of [value] without check digits- Throws:
CharNotInAlphabetException- if the value contains characters which are not contained in the alphabetInvalidPSNException- 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 mostDomainConfig.getMaxNumberOfCharactersInFullyQualifiedPsn()).- Returns:
- the theoretic maximum length of messages this algorithm is able to compute check digits for
(but at most
DomainConfig.getMaxNumberOfCharactersInFullyQualifiedPsn())
-
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 thanDomainConfig.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
- Throws:
CharNotInAlphabetException
-
toMessage
-
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
-
isDeprecated
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 classalphabet- the alphabetconfig- the domain config- Returns:
- the instance
- Throws:
InvalidCheckDigitClassException- if the class name does not denote a visible CheckDigits classInvalidGeneratorException- 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 classalphabet- the alphabetconfig- the domain config- Returns:
- the instance
- Throws:
InvalidGeneratorException- if the CheckDigits algorithm is not compatible with the alphabet
-