All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.commons.validator.routines.checkdigit.CheckDigit Maven / Gradle / Ivy

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.validator.routines.checkdigit;

/**
 * Check Digit calculation and validation.
 * 

* 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. {@link 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, * {@link CheckDigit} also defines behaviour for calculating/generating check * digits, since it makes sense that users will want to (re-)use the * same logic for both. The {@link org.apache.commons.validator.routines.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. *

* *

Implementations

* See the * Package Summary for a full * list of implementations provided within Commons Validator. * * @see org.apache.commons.validator.routines.CodeValidator * @version $Revision: 1649287 $ * @since Validator 1.4 */ public interface CheckDigit { /** * Calculates the Check Digit for a code. * * @param code The code to calculate the Check Digit for. * The string must not include the check digit * @return The calculated Check Digit * @throws CheckDigitException if an error occurs. */ String calculate(String code) throws CheckDigitException; /** * Validates the check digit for the code. * * @param code The code to validate, the string must include the check digit. * @return true if the check digit is valid, otherwise * false. */ boolean isValid(String code); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy