public interface CheckDigit
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 behavior for calculating/generating check
digits, since it makes sense that users will want to (re-)use the
same logic for both. The ISBNValidator
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.
CodeValidator
Modifier and Type | Method and Description |
---|---|
String |
calculate(String code)
Calculates the Check Digit for a code.
|
boolean |
isValid(String code)
Validates the check digit for the code.
|
String calculate(String code) throws CheckDigitException
code
- The code to calculate the Check Digit for.
The string must not include the check digitCheckDigitException
- if an error occurs.boolean isValid(String code)
code
- The code to validate, the string must include the check digit.true
if the check digit is valid, otherwise
false
.Copyright © 2002–2020 The Apache Software Foundation. All rights reserved.