001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.validator.routines.checkdigit; 018 019 /** 020 * <b>Check Digit</b> calculation and validation. 021 * <p> 022 * The logic for validating check digits has previously been 023 * embedded within the logic for specific code validation, which 024 * includes other validations such as verifying the format 025 * or length of a code. {@link CheckDigit} provides for separating out 026 * the check digit calculation logic enabling it to be more easily 027 * tested and reused. 028 * <p> 029 * Although Commons Validator is primarily concerned with validation, 030 * {@link CheckDigit} also defines behaviour for calculating/generating check 031 * digits, since it makes sense that users will want to (re-)use the 032 * same logic for both. The {@link org.apache.commons.validator.routines.ISBNValidator} 033 * makes specific use of this feature by providing the facility to validate ISBN-10 codes 034 * and then convert them to the new ISBN-13 standard. 035 * <p> 036 * {@link CheckDigit} is used by the new generic 037 * <a href="..\CodeValidator.html">CodeValidator</a> implementation. 038 * <p> 039 * <h3>Implementations</h3> 040 * See the 041 * <a href="package-summary.html">Package Summary</a> for a full 042 * list of implementations provided within Commons Validator. 043 * 044 * @see org.apache.commons.validator.routines.CodeValidator 045 * @version $Revision: 589328 $ $Date: 2007-10-28 11:43:47 +0100 (So, 28. Okt 2007) $ 046 * @since Validator 1.4 047 */ 048 public interface CheckDigit { 049 050 /** 051 * Calculate the <i>Check Digit</i> for a code. 052 * 053 * @param code The code to calculate the Check Digit for. 054 * @return The calculated Check Digit 055 * @throws CheckDigitException if an error occurs. 056 */ 057 public String calculate(String code) throws CheckDigitException; 058 059 /** 060 * Validate the check digit for the code. 061 * 062 * @param code The code to validate. 063 * @return <code>true</code> if the check digit is valid, otherwise 064 * <code>false</code>. 065 */ 066 public boolean isValid(String code); 067 068 }