homebeaver commented on code in PR #271: URL: https://github.com/apache/commons-validator/pull/271#discussion_r1936934674
########## src/main/java/org/apache/commons/validator/routines/checkdigit/VATidBECheckDigit.java: ########## @@ -0,0 +1,104 @@ +/* + * 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; + +import org.apache.commons.validator.GenericValidator; + +/** + * Belgian VAT identification number (VATIN) Check Digit calculation/validation. + * <p> + * Numéro T.V.A. BTW-nummer (Nº TVA BTW-nr.) old schema {@code 1234567pp}. + * Note the check digit has two characters and that the old numbering schema only had 9 characters, + * just adding a zero in front makes it a valid number in the new schema {@code 01234567pp}. + * </p> + * <p> + * The check digits are calculated as 97 - MOD 97 + * </p> + * <p> + * See <a href="https://en.wikipedia.org/wiki/VAT_identification_number">Wikipedia - VAT IN</a> + * for more details. + * </p> + * + * @since 1.10.0 + */ +public final class VATidBECheckDigit extends Modulus97CheckDigit { + + private static final long serialVersionUID = 4622288405648808179L; + + /** Singleton Check Digit instance */ + private static final VATidBECheckDigit INSTANCE = new VATidBECheckDigit(); + + /** + * Gets the singleton instance of this validator. + * @return A singleton instance of the class. + */ + public static CheckDigit getInstance() { + return INSTANCE; + } + + /** + * Constructs a Check Digit routine. + */ + private VATidBECheckDigit() { + super(); + } + + /** + * {@inheritDoc} + * <p> + * Overridden because the check digits are calculated as 97 - modulusResult + * </p> + */ + @Override + public String calculate(final String code) throws CheckDigitException { + if (GenericValidator.isBlankOrNull(code)) { + throw new CheckDigitException(CheckDigitException.MISSING_CODE); + } Review Comment: You can find the explanation in `package-info` of package `org.apache.commons.validator.routines.checkdigit`: _This package contains Check Digit validation/calculation routines._ _Note that these **do not validate the input for length** or syntax. Such validation is performed by the org.apache.commons.validator.routines.XYZValidator classes._ `VATINValidator` class validates against reg-ex `"[0-1]\\d{9}"` In checkdigit package I use LEN only if it is absolute necessary for the implementation of the check. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org