Package org.trustdeck.algorithms
Class LuhnCheckDigit
java.lang.Object
org.trustdeck.algorithms.LuhnCheckDigit
- Direct Known Subclasses:
LuhnMod10CheckDigit,LuhnMod16CheckDigit,LuhnMod26CheckDigit,LuhnMod32CheckDigit,LuhnMod36CheckDigit,LuhnModNCheckDigit
Abstract class that provides the functionalities for calculating a check digit for an arbitrary list of characters
as long as the length of this list is divisible by two.
- Author:
- Armin Müller
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncomputeCheckDigit(String input, String domainPrefix) Method to validate the check digit from the given input.standardizeInput(String input, String domainPrefix) A method to standardize the input strings (e.g.validateCheckDigit(String input, String domainPrefix) Method to validate the check digit from the given input.
-
Constructor Details
-
LuhnCheckDigit
Basic constructor. A list of allowed characters needs to be provided. The list's length must be divisible by two.- Parameters:
allowedCharacters-
-
-
Method Details
-
standardizeInput
A method to standardize the input strings (e.g. turns input into upper case, removes domain prefix, ...).- Parameters:
input- the unsanitized input stringdomainPrefix- the prefix of the domain where the input is in, including hyphens- Returns:
- the sanitized input string
-
computeCheckDigit
Method to validate the check digit from the given input.- Parameters:
input- the unsanitized input stringdomainPrefix- the prefix of the domain where the input should be in, including hyphens- Returns:
- the check digit for the provided input,
nullwhen a character was encountered that is not part of the list of allowed characters
-
validateCheckDigit
Method to validate the check digit from the given input.- Parameters:
input- the unsanitized input stringdomainPrefix- the prefix of the domain where the input is in, including hyphens- Returns:
truewhen the check digit is valid,falsewhen it is invalid, andnullwhen there was a character in the input that is not part of the allowed characters.
-