Skip to content

Commit 9d69884

Browse files
committed
TidDECheckDigit mit korrekter oberklasse und längenprüfung + test
in commons-validator wg LOG entfernt
1 parent e8f0cff commit 9d69884

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

src/main/java/org/apache/commons/validator/routines/checkdigit/TidDECheckDigit.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
21+
import org.apache.commons.validator.GenericTypeValidator;
22+
import org.apache.commons.validator.GenericValidator;
2123

2224
/**
2325
* German Steuer-Identifikationsnummer (TIN – in short: IdNr.) is available since 2008,
@@ -30,14 +32,16 @@
3032
*
3133
* @since 1.10.0
3234
*/
33-
public final class TidDECheckDigit extends Modulus11TenCheckDigit {
35+
public final class TidDECheckDigit extends IsoIecHybrid1110System {
3436

3537
private static final long serialVersionUID = 4222306963463322195L;
3638
private static final Log LOG = LogFactory.getLog(TidDECheckDigit.class);
3739

3840
/** Singleton Check Digit instance */
3941
private static final TidDECheckDigit INSTANCE = new TidDECheckDigit();
4042

43+
static final int LEN = 11; // with Check Digit
44+
4145
/**
4246
* Gets the singleton instance of this validator.
4347
* @return A singleton instance of the class.
@@ -65,6 +69,17 @@ private TidDECheckDigit() {
6569
*/
6670
@Override
6771
protected int calculateModulus(final String code, final boolean includesCheckDigit) throws CheckDigitException {
72+
// anders als ISO/IEC 7064, MOD 11,10 akzeptieren wir keine Leerstrings
73+
if (GenericValidator.isBlankOrNull(code)) {
74+
throw new CheckDigitException(CheckDigitException.MISSING_CODE);
75+
}
76+
int len = includesCheckDigit ? LEN : LEN - 1;
77+
if (code.length() != len) {
78+
throw new CheckDigitException(CheckDigitException.invalidCode(code, "length error"));
79+
}
80+
if (GenericTypeValidator.formatLong(code.substring(0, len -1)) == 0) {
81+
throw new CheckDigitException(CheckDigitException.ZERO_SUM);
82+
}
6883
int product = MODULUS_10;
6984
int sum = 0;
7085
final int[] anzahl = new int[10]; // CHECKSTYLE IGNORE MagicNumber
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.commons.validator.routines.checkdigit;
18+
19+
import org.junit.jupiter.api.BeforeEach;
20+
21+
/**
22+
* DE Tax Id Check Digit Tests.
23+
*
24+
Quelle: Bayerisches Landesamt für Steuern:
25+
<a href="https://download.elster.de/download/schnittstellen/Pruefung_der_Steuer_und_Steueridentifikatsnummer.pdf">Prüfung der Steuer- und Steueridentifikationsnummer</a>
26+
27+
Die Steueridentifikationsnummer ist eine elfstellige Ziffernfolge, // Check in TINValidator
28+
die elfte Stelle ist eine Prüfziffer.
29+
Die Steueridentifikationsnummer muss folgenden Kriterien entsprechen:
30+
31+
Keine führenden Nullen erlaubt, // Check in TINValidator
32+
außer es ist eine Testidentifikationsnummer
33+
In den ersten 10 Stellen der Identifikationsnummer muss genau eine Ziffer doppelt oder dreifach vorkommen.
34+
Existieren drei gleiche Ziffern an den Positionen 1 bis 10,
35+
dürfen diese gleichen Ziffern niemals an direkt aufeinander folgenden Stellen stehen.
36+
37+
Beispiele
38+
39+
02476291358 : TestID da führende 0, doppelte Ziffer : 2
40+
86095742719 : doppelte Ziffer : 7
41+
47036892816 : doppelte Ziffer : 8
42+
65929970489 : keine doppelte Ziffer, dreifache Ziffer : 9
43+
57549285017 : keine doppelte Ziffer, dreifache Ziffer : 5
44+
25768131411 : keine doppelte Ziffer, dreifache Ziffer : 1
45+
46+
*/
47+
public class TidDECheckDigitTest extends AbstractCheckDigitTest {
48+
49+
/**
50+
* Sets up routine & valid codes.
51+
*/
52+
@BeforeEach
53+
protected void setUp() {
54+
routine = TidDECheckDigit.getInstance();
55+
valid = new String[] {"81872495633" // aus http://www.pruefziffernberechnung.de/I/Identifikationsnummer.shtml
56+
, "02476291358"
57+
, "86095742719"
58+
, "47036892816"
59+
, "65929970489"
60+
, "57549285017"
61+
, "25768131411"
62+
, "11012234564" // 2 doppelt und 1 dreifach
63+
, "11234567890" // doppelte Ziffer : 1 direkt hintereinander
64+
, "11012345675" // dreifach Ziffer : 1 nicht direkt hintereinander
65+
/* diese Steuernummer wurde vergeben, sie hat aber zwei doppelte Ziffer
66+
, "12720320213" // 0 und 1 doppelt und 2 vierfach
67+
*/
68+
};
69+
invalid = new String[] {"00000000010" // theoretical minimum
70+
, "99999999994" // theoretical maximum
71+
, "12345678903" // keine Ziffer doppelt oder dreifach
72+
, "98765432106" // keine Ziffer doppelt oder dreifach
73+
, "11012134569" // vierfache Ziffer : 1
74+
, "11223456785" // zwei doppelte Ziffer : 1 und 2
75+
, "11212234562" // zwei dreifache Ziffer : 1 und 2
76+
, "11123456786" // dreifach Ziffer : 1 direkt hintereinander
77+
};
78+
}
79+
80+
}

0 commit comments

Comments
 (0)