-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce the CheckDigit interface (closes #174)
- Loading branch information
1 parent
7776eea
commit 3bc7077
Showing
7 changed files
with
60 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/fr/marcwrobel/jbanking/checkdigit/CheckDigit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package fr.marcwrobel.jbanking.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. | ||
* | ||
* <p> | ||
* 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. | ||
* | ||
* <p> | ||
* A class that implements this interface implements one of the many existing algorithms for calculating and validating | ||
* check digits, such as one defined in <a href="https://wikipedia.org/wiki/ISO/IEC_7064">ISO/IEC 7064</a>. | ||
* | ||
* @see <a href="https://wikipedia.org/wiki/Check_digit">Check digit</a> | ||
*/ | ||
public interface CheckDigit { | ||
|
||
/** | ||
* Calculates the check digit for a given input string. | ||
* | ||
* @param input the non-null input string to calculate the check digit for | ||
* @return a non-null string | ||
* @throws IllegalArgumentException if the check digit cannot be computed for the given input string (because it is | ||
* {@code null}, to short...) | ||
*/ | ||
String calculate(String input); | ||
|
||
/** | ||
* Validates the check digit for the given input string. | ||
* | ||
* <p> | ||
* Invalid input strings, such as {@code null}, are considered invalid and do not throw any exception. | ||
* | ||
* @param input the input string to validate, may be null | ||
* @return {@code true} if the check digit is verified, {@code false} otherwise | ||
*/ | ||
boolean validate(String input); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/fr/marcwrobel/jbanking/checkdigit/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* Classes that relates to {@link fr.marcwrobel.jbanking.checkdigit.CheckDigit check digits} computation and | ||
* validation. | ||
*/ | ||
package fr.marcwrobel.jbanking.checkdigit; |
2 changes: 1 addition & 1 deletion
2
src/main/java/fr/marcwrobel/jbanking/creditor/CreditorIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters