Interface CheckDigit
-
- All Known Implementing Classes:
ABANumberCheckDigit
,CUSIPCheckDigit
,EAN13CheckDigit
,IBANCheckDigit
,ISBN10CheckDigit
,ISBNCheckDigit
,ISINCheckDigit
,ISSNCheckDigit
,LuhnCheckDigit
,ModulusCheckDigit
,ModulusTenCheckDigit
,SedolCheckDigit
,VerhoeffCheckDigit
public interface CheckDigit
Check Digit calculation and validation.The logic for validating check digits has previously been embedded within the logic for specific code validation, which includes other validations such as verifying the format or length of a code.
CheckDigit
provides for separating out the check digit calculation logic enabling it to be more easily tested and reused.Although Commons Validator is primarily concerned with validation,
CheckDigit
also defines behaviour for calculating/generating check digits, since it makes sense that users will want to (re-)use the same logic for both. TheISBNValidator
makes specific use of this feature by providing the facility to validate ISBN-10 codes and then convert them to the new ISBN-13 standard.CheckDigit is used by the new generic @link CodeValidator} implementation.
Implementations
See the Package Summary for a full list of implementations provided within Commons Validator.- Since:
- Validator 1.4
- Version:
- $Revision: 1649287 $
- See Also:
CodeValidator
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.String
calculate(java.lang.String code)
Calculates the Check Digit for a code.boolean
isValid(java.lang.String code)
Validates the check digit for the code.
-
-
-
Method Detail
-
calculate
java.lang.String calculate(java.lang.String code) throws CheckDigitException
Calculates the Check Digit for a code.- Parameters:
code
- The code to calculate the Check Digit for. The string must not include the check digit- Returns:
- The calculated Check Digit
- Throws:
CheckDigitException
- if an error occurs.
-
isValid
boolean isValid(java.lang.String code)
Validates the check digit for the code.- Parameters:
code
- The code to validate, the string must include the check digit.- Returns:
true
if the check digit is valid, otherwisefalse
.
-
-