sebbASF commented on code in PR #271:
URL: https://github.com/apache/commons-validator/pull/271#discussion_r1936500145


##########
src/main/java/org/apache/commons/validator/routines/checkdigit/VATidLUCheckDigit.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.GenericTypeValidator;
+import org.apache.commons.validator.GenericValidator;
+
+/**
+ * Luxemburg VAT identification number (VATIN) Check Digit 
calculation/validation.
+ * <p>
+ * Numéro d'identification à la taxe sur la valeur ajoutée {@code 123456pp}.
+ * </p>
+ * <p>
+ * The check digits are calculated as 89 - MOD 89

Review Comment:
   That does not agree with the code in the calculate method, which does not 
subtract.



##########
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);
+        }
+        try {
+            final long l = Long.parseLong(code); // throws 
NumberFormatException
+            if (l == 0) {
+                throw new CheckDigitException(CheckDigitException.ZERO_SUM);
+            }
+            final int r = (int) (l % MODULUS_97); // MOD 97 reminder
+            return toCheckDigit(MODULUS_97 - r);
+        } catch (final NumberFormatException ex) {
+            // Expected exception for high codes f.i. 99999999999999999999999
+            throw new CheckDigitException("Invalid Code " + code);
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isValid(final String code) {
+        if (GenericValidator.isBlankOrNull(code)) {
+            return false;
+        }
+        if (code.length() <= CHECKDIGIT_LEN) {

Review Comment:
   Surely this should check against MIN_CODE_LEN?



##########
src/main/java/org/apache/commons/validator/routines/checkdigit/VATidLUCheckDigit.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * 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.GenericTypeValidator;
+import org.apache.commons.validator.GenericValidator;
+
+/**
+ * Luxemburg VAT identification number (VATIN) Check Digit 
calculation/validation.
+ * <p>
+ * Numéro d'identification à la taxe sur la valeur ajoutée {@code 123456pp}.
+ * </p>
+ * <p>
+ * The check digits are calculated as 89 - MOD 89
+ * </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 VATidLUCheckDigit extends Modulus97CheckDigit {
+
+    private static final long serialVersionUID = 6690723004719444647L;
+
+    /** Singleton Check Digit instance */
+    private static final VATidLUCheckDigit INSTANCE = new VATidLUCheckDigit();
+
+    /**
+     * Gets the singleton instance of this validator.
+     * @return A singleton instance of the class.
+     */
+    public static CheckDigit getInstance() {
+        return INSTANCE;
+    }
+
+    static final int MODULUS_89 = 89;
+
+    /**
+     * Constructs a Check Digit routine.
+     */
+    private VATidLUCheckDigit() {
+        super(MODULUS_89);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String calculate(final String code) throws CheckDigitException {
+        if (GenericValidator.isBlankOrNull(code)) {
+            throw new CheckDigitException(CheckDigitException.MISSING_CODE);
+        }
+        if (code.length() < MIN_CODE_LEN) {
+            throw new CheckDigitException("Invalid Code length=" + 
code.length());
+        }
+        final long mr = calculateModulus(code, false);
+        if (mr == 0) {
+            throw new CheckDigitException(CheckDigitException.ZERO_SUM);
+        }
+        final int modulusResult = (int) (mr % MODULUS_89);

Review Comment:
   Does not agree with class comment



##########
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:
   Why does this not check the length against MIN_CODE_LEN?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to