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 * Although Commons Validator is primarily concerned with validation,
30 * {@link CheckDigit} also defines behaviour for calculating/generating check
31 * digits, since it makes sense that users will want to (re-)use the
32 * same logic for both. The {@link org.apache.commons.validator.routines.ISBNValidator}
33 * makes specific use of this feature by providing the facility to validate ISBN-10 codes
34 * and then convert them to the new ISBN-13 standard.
35 * <p>
36 * {@link CheckDigit} is used by the new generic
37 * <a href="..\CodeValidator.html">CodeValidator</a> implementation.
38 * <p>
39 * <h3>Implementations</h3>
40 * See the
41 * <a href="package-summary.html">Package Summary</a> for a full
42 * list of implementations provided within Commons Validator.
43 *
44 * @see org.apache.commons.validator.routines.CodeValidator
45 * @version $Revision: 589328 $ $Date: 2007-10-28 06:43:47 -0400 (Sun, 28 Oct 2007) $
46 * @since Validator 1.4
47 */
48 public interface CheckDigit {
49
50 /**
51 * Calculate the <i>Check Digit</i> for a code.
52 *
53 * @param code The code to calculate the Check Digit for.
54 * @return The calculated Check Digit
55 * @throws CheckDigitException if an error occurs.
56 */
57 public String calculate(String code) throws CheckDigitException;
58
59 /**
60 * Validate the check digit for the code.
61 *
62 * @param code The code to validate.
63 * @return <code>true</code> if the check digit is valid, otherwise
64 * <code>false</code>.
65 */
66 public boolean isValid(String code);
67
68 }