diff --git a/src/main/java/org/apache/commons/validator/routines/VATINValidator.java b/src/main/java/org/apache/commons/validator/routines/VATINValidator.java index 4c3551c6a..bb373c543 100644 --- a/src/main/java/org/apache/commons/validator/routines/VATINValidator.java +++ b/src/main/java/org/apache/commons/validator/routines/VATINValidator.java @@ -170,7 +170,7 @@ public RegexValidator getRegexValidator() { new Validator("RO", VATidROCheckDigit.getInstance(), 12, "[1-9](\\d)?(\\d)?(\\d)?(\\d)?(\\d)?(\\d)?(\\d)?(\\d)?\\d"), new Validator("SE", VATidSECheckDigit.getInstance(), 14, "\\d{10}01"), new Validator("SI", VATidSICheckDigit.getInstance(), 10, "[1-9]\\d{7}"), - // ne of 2, 3, 4, 7, 8, 9 + // 2nd digit: one of 2, 3, 4, 7, 8, 9 new Validator("SK", VATidSKCheckDigit.getInstance(), 12, "[1-9]\\d[2-4,7-9]\\d{7}"), new Validator("XI", VATidGBCheckDigit.getInstance(), 14, "(\\d{3})?\\d{9}"), }; diff --git a/src/main/java/org/apache/commons/validator/routines/checkdigit/Modulus11TenCheckDigit.java b/src/main/java/org/apache/commons/validator/routines/checkdigit/Modulus11TenCheckDigit.java index 82eeb241d..4754c93be 100644 --- a/src/main/java/org/apache/commons/validator/routines/checkdigit/Modulus11TenCheckDigit.java +++ b/src/main/java/org/apache/commons/validator/routines/checkdigit/Modulus11TenCheckDigit.java @@ -84,7 +84,6 @@ public String calculate(final String code) throws CheckDigitException { if (GenericTypeValidator.formatLong(code) == 0) { throw new CheckDigitException(CheckDigitException.ZERO_SUM); } - return toCheckDigit(calculateModulus(code, false)); } diff --git a/src/main/java/org/apache/commons/validator/routines/checkdigit/Modulus97CheckDigit.java b/src/main/java/org/apache/commons/validator/routines/checkdigit/Modulus97CheckDigit.java index 00c52a239..13cfff820 100644 --- a/src/main/java/org/apache/commons/validator/routines/checkdigit/Modulus97CheckDigit.java +++ b/src/main/java/org/apache/commons/validator/routines/checkdigit/Modulus97CheckDigit.java @@ -16,8 +16,6 @@ */ package org.apache.commons.validator.routines.checkdigit; -import java.io.Serializable; - import org.apache.commons.validator.GenericTypeValidator; import org.apache.commons.validator.GenericValidator; @@ -34,9 +32,7 @@ * * @since 1.10.0 */ -public class Modulus97CheckDigit extends AbstractCheckDigit implements Serializable { - - private static final long serialVersionUID = -5746038014913492394L; +public class Modulus97CheckDigit extends AbstractCheckDigit { /** Singleton Check Digit instance */ private static final Modulus97CheckDigit INSTANCE = new Modulus97CheckDigit(); @@ -144,7 +140,6 @@ public boolean isValid(final String code) { if (icheck == null) { return false; } - try { long mr = calculateModulus(code, false); int modulusResult = (int) (mr % modulus); diff --git a/src/main/java/org/apache/commons/validator/routines/checkdigit/TidDECheckDigit.java b/src/main/java/org/apache/commons/validator/routines/checkdigit/TidDECheckDigit.java index 2f0f9a3b0..6ab45c44a 100644 --- a/src/main/java/org/apache/commons/validator/routines/checkdigit/TidDECheckDigit.java +++ b/src/main/java/org/apache/commons/validator/routines/checkdigit/TidDECheckDigit.java @@ -30,19 +30,6 @@ * * @since 1.10.0 */ -/* (de) - * deutsche persönliche Steuer-Identifikationsnummer. - * - * Algorithmus siehe bgbl193s0736, Bundesgesetztblatt, Jahrgang 1993, Teil I - * Anlage 3 (zu §9) - * - * hybrides MOD 11,10 Verfahren - * Aufbau: nnnnnnnnnnp. - * - * Quelle: Bayerisches Landesamt für Steuern: elster.de - * Beispiel: 02476291358 : TestID da führende 0 - * - */ public final class TidDECheckDigit extends Modulus11TenCheckDigit { private static final long serialVersionUID = 4222306963463322195L; diff --git a/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidBECheckDigit.java b/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidBECheckDigit.java index c3289128f..3043da037 100644 --- a/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidBECheckDigit.java +++ b/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidBECheckDigit.java @@ -37,8 +37,6 @@ */ public final class VATidBECheckDigit extends Modulus97CheckDigit { - private static final long serialVersionUID = 4622288405648808179L; - /** Singleton Check Digit instance */ private static final VATidBECheckDigit INSTANCE = new VATidBECheckDigit(); @@ -59,7 +57,9 @@ private VATidBECheckDigit() { /** * {@inheritDoc} - * return expression overridden + *

+ * Overridden because the check digits are calculated as 97 - modulusResult + *

*/ @Override public String calculate(final String code) throws CheckDigitException { @@ -90,7 +90,6 @@ public boolean isValid(final String code) { if (code.length() < MIN_CODE_LEN) { return false; } - String check = code.substring(code.length() - CHECKDIGIT_LEN); Integer icheck = GenericTypeValidator.formatInt(check); if (icheck == null) { diff --git a/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidBGCheckDigit.java b/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidBGCheckDigit.java index a7650fcec..0856dff9f 100644 --- a/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidBGCheckDigit.java +++ b/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidBGCheckDigit.java @@ -55,10 +55,12 @@ public static CheckDigit getInstance() { } /** - * there ate three length - * 9 for legal entities (standard DDS), - * 10 for physical persons (civil number), - * 13 for legal entities with branch number (not used for VATIN) + * There are three length + * */ static final int LEN = 9; // with Check Digit static final int LENCN = 10; // with Check Digit diff --git a/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidCYCheckDigit.java b/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidCYCheckDigit.java index 43230d78b..531a14374 100644 --- a/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidCYCheckDigit.java +++ b/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidCYCheckDigit.java @@ -89,7 +89,9 @@ protected String toCheckDigit(final int charValue) throws CheckDigitException { */ @Override protected int weightedValue(final int charValue, final int leftPos, final int rightPos) { - if (leftPos % 2 == 0) return charValue; + if (leftPos % 2 == 0) { + return charValue; + } return POSITION_WEIGHT[charValue]; } diff --git a/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidFRCheckDigit.java b/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidFRCheckDigit.java index acbd50d00..69940cd7e 100644 --- a/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidFRCheckDigit.java +++ b/src/main/java/org/apache/commons/validator/routines/checkdigit/VATidFRCheckDigit.java @@ -57,9 +57,6 @@ public static CheckDigit getInstance() { private static final int MODULUS_97 = 97; private static final SireneValidator SIRENE_VALIDATOR = SireneValidator.getInstance(); - /** - * Constructs a Check Digit routine. - */ private VATidFRCheckDigit() { super(MODULUS_97); } @@ -101,10 +98,9 @@ public String calculate(final String code) throws CheckDigitException { if (!SIRENE_VALIDATOR.isValid(code)) { throw new CheckDigitException("Invalid code, " + code + " is not valid SIREN"); } - // There are more than one possible VATIN check digit C(1-2) for a given SIREN, // thus, it isn't possible to compute it. - + // // convert two-digit numeric values to String return Modulus97CheckDigit.toCheckDigit(calcOldStyle(code)); } @@ -122,6 +118,7 @@ private int calcOldStyle(final String code) throws CheckDigitException { } return (int) (cde12 % MODULUS_97); } + private boolean isValidOldStyle(final String code) throws CheckDigitException { int cd = GenericTypeValidator.formatInt(code.substring(0, CHECKDIGIT_LEN)); Long cde = GenericTypeValidator.formatLong((code + "12").substring(CHECKDIGIT_LEN)); @@ -151,6 +148,7 @@ private boolean isValid(final String siren, final int s0, final int s1) { int r2 = (GenericTypeValidator.formatInt(siren) + p) % MODULUS_11; return r1 == r2; } + /** * {@inheritDoc} *