    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 */
    017package 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 * <p>
    030 * Although Commons Validator is primarily concerned with validation,
    031 * {@link CheckDigit} also defines behavior for calculating/generating check
    032 * digits, since it makes sense that users will want to (re-)use the
    033 * same logic for both. The {@link org.apache.commons.validator.routines.ISBNValidator}
    034 * makes specific use of this feature by providing the facility to validate ISBN-10 codes
    035 * and then convert them to the new ISBN-13 standard.
    036 * </p>
    037 * <p>
    038 * CheckDigit is used by the new generic @link CodeValidator} implementation.
    039 * </p>
    040 *
    041 * <h2>Implementations</h2>
    042 * See the
    043 * <a href="package-summary.html">Package Summary</a> for a full
    044 * list of implementations provided within Commons Validator.
    045 *
    046 * @see org.apache.commons.validator.routines.CodeValidator
    047 * @version $Revision$
    048 * @since Validator 1.4
    049 */
    050public interface CheckDigit {
    051
    052    /**
    053     * Calculates the <i>Check Digit</i> for a code.
    054     *
    055     * @param code The code to calculate the Check Digit for.
    056     * The string must not include the check digit
    057     * @return The calculated Check Digit
    058     * @throws CheckDigitException if an error occurs.
    059     */
    060    String calculate(String code) throws CheckDigitException;
    061
    062    /**
    063     * Validates the check digit for the code.
    064     *
    065     * @param code The code to validate, the string must include the check digit.
    066     * @return <code>true</code> if the check digit is valid, otherwise
    067     * <code>false</code>.
    068     */
    069    boolean isValid(String code);
    070
    071}