Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CheckDigit |
|
| 1.0;1 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | package org.apache.commons.validator.routines.checkdigit; | |
18 | ||
19 | /** | |
20 | * <b>Check Digit</b> calculation and validation. | |
21 | * <p> | |
22 | * The logic for validating check digits has previously been | |
23 | * embedded within the logic for specific code validation, which | |
24 | * includes other validations such as verifying the format | |
25 | * or length of a code. {@link CheckDigit} provides for separating out | |
26 | * the check digit calculation logic enabling it to be more easily | |
27 | * tested and reused. | |
28 | * </p> | |
29 | * <p> | |
30 | * Although Commons Validator is primarily concerned with validation, | |
31 | * {@link CheckDigit} also defines behaviour for calculating/generating check | |
32 | * digits, since it makes sense that users will want to (re-)use the | |
33 | * same logic for both. The {@link org.apache.commons.validator.routines.ISBNValidator} | |
34 | * makes specific use of this feature by providing the facility to validate ISBN-10 codes | |
35 | * and then convert them to the new ISBN-13 standard. | |
36 | * </p> | |
37 | * <p> | |
38 | * CheckDigit is used by the new generic @link CodeValidator} implementation. | |
39 | * </p> | |
40 | * | |
41 | * <h3>Implementations</h3> | |
42 | * See the | |
43 | * <a href="package-summary.html">Package Summary</a> for a full | |
44 | * list of implementations provided within Commons Validator. | |
45 | * | |
46 | * @see org.apache.commons.validator.routines.CodeValidator | |
47 | * @version $Revision: 1649287 $ | |
48 | * @since Validator 1.4 | |
49 | */ | |
50 | public interface CheckDigit { | |
51 | ||
52 | /** | |
53 | * Calculates the <i>Check Digit</i> for a code. | |
54 | * | |
55 | * @param code The code to calculate the Check Digit for. | |
56 | * The string must not include the check digit | |
57 | * @return The calculated Check Digit | |
58 | * @throws CheckDigitException if an error occurs. | |
59 | */ | |
60 | String calculate(String code) throws CheckDigitException; | |
61 | ||
62 | /** | |
63 | * Validates the check digit for the code. | |
64 | * | |
65 | * @param code The code to validate, the string must include the check digit. | |
66 | * @return <code>true</code> if the check digit is valid, otherwise | |
67 | * <code>false</code>. | |
68 | */ | |
69 | boolean isValid(String code); | |
70 | ||
71 | } |