Skip to content

Commit

Permalink
adding GB and FI sub-territories support (arturmkrtchyan#100)
Browse files Browse the repository at this point in the history
Co-authored-by: Remy Duval <[email protected]>
  • Loading branch information
2 people authored and hajk1 committed Oct 2, 2023
1 parent e30eb47 commit 3c37aa6
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 35 deletions.
73 changes: 38 additions & 35 deletions src/main/java/org/iban4j/bban/BbanStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.accountNumber(11, 'c'),
BbanStructureEntry.nationalCheckDigit(2, 'n'));

private final static BbanStructure UNITED_KINGDOM_STRUCTURE = new BbanStructure(
BbanStructureEntry.bankCode(4, 'a'),
BbanStructureEntry.branchCode(6, 'n'),
BbanStructureEntry.accountNumber(8, 'n'));

private final static BbanStructure FINLAND_STRUCTURE = new BbanStructure(
BbanStructureEntry.bankCode(6, 'n'),
BbanStructureEntry.accountNumber(7, 'n'),
BbanStructureEntry.nationalCheckDigit(1, 'n'));

static {
structures = new EnumMap<CountryCode, BbanStructure>(CountryCode.class);

Expand Down Expand Up @@ -101,8 +111,6 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.accountType(2, 'n'),
BbanStructureEntry.accountNumber(8, 'c')));

structures.put(CountryCode.BL, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.BY,
new BbanStructure(
BbanStructureEntry.bankCode(4, 'c'),
Expand Down Expand Up @@ -165,13 +173,24 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.accountNumber(9, 'n'),
BbanStructureEntry.nationalCheckDigit(1, 'n')));

structures.put(CountryCode.FI,
new BbanStructure(
BbanStructureEntry.bankCode(6, 'n'),
BbanStructureEntry.accountNumber(7, 'n'),
BbanStructureEntry.nationalCheckDigit(1, 'n')));
// Finland and its sub-territory (see https://www.iban.com/structure)
structures.put(CountryCode.FI, BbanStructure.FINLAND_STRUCTURE);
structures.put(CountryCode.AX, BbanStructure.FINLAND_STRUCTURE);

// France and its sub-territories (see https://www.iban.com/structure)
structures.put(CountryCode.FR, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.GF, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.GP, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.MQ, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.RE, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.PF, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.TF, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.YT, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.NC, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.BL, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.MF, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.PM, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.WF, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.GA,
new BbanStructure(
Expand All @@ -184,8 +203,6 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.bankCode(2, 'a'),
BbanStructureEntry.accountNumber(16, 'n')));

structures.put(CountryCode.GF, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.GI,
new BbanStructure(
BbanStructureEntry.bankCode(4, 'a'),
Expand All @@ -196,8 +213,6 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.bankCode(4, 'n'),
BbanStructureEntry.accountNumber(10, 'n')));

structures.put(CountryCode.GP, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.GR,
new BbanStructure(
BbanStructureEntry.bankCode(3, 'n'),
Expand Down Expand Up @@ -293,8 +308,6 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.bankCode(3, 'n'),
BbanStructureEntry.accountNumber(13, 'c')));

structures.put(CountryCode.MF, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.MK,
new BbanStructure(
BbanStructureEntry.bankCode(3, 'n'),
Expand Down Expand Up @@ -325,18 +338,19 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.bankCode(2, 'c'),
BbanStructureEntry.accountNumber(18, 'c')));

structures.put(CountryCode.MC, BbanStructure.FRENCH_STRUCTURE);
structures.put(CountryCode.MC,
new BbanStructure(
BbanStructureEntry.bankCode(5, 'n'),
BbanStructureEntry.branchCode(5, 'n'),
BbanStructureEntry.accountNumber(11, 'c'),
BbanStructureEntry.nationalCheckDigit(2, 'n')));

structures.put(CountryCode.ME,
new BbanStructure(
BbanStructureEntry.bankCode(3, 'n'),
BbanStructureEntry.accountNumber(13, 'n'),
BbanStructureEntry.nationalCheckDigit(2, 'n')));

structures.put(CountryCode.MQ, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.NC, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.NL,
new BbanStructure(
BbanStructureEntry.bankCode(4, 'a'),
Expand All @@ -348,15 +362,11 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.accountNumber(6, 'n'),
BbanStructureEntry.nationalCheckDigit(1, 'n')));

structures.put(CountryCode.PF, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.PK,
new BbanStructure(
BbanStructureEntry.bankCode(4, 'c'),
BbanStructureEntry.accountNumber(16, 'n')));

structures.put(CountryCode.PM, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.PS,
new BbanStructure(
BbanStructureEntry.bankCode(4, 'a'),
Expand All @@ -376,8 +386,6 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.accountNumber(11, 'n'),
BbanStructureEntry.nationalCheckDigit(2, 'n')));

structures.put(CountryCode.RE, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.RO,
new BbanStructure(
BbanStructureEntry.bankCode(4, 'a'),
Expand Down Expand Up @@ -453,8 +461,6 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.bankCode(5, 'n'),
BbanStructureEntry.accountNumber(12, 'c')));

structures.put(CountryCode.TF, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.TN,
new BbanStructure(
BbanStructureEntry.bankCode(2, 'n'),
Expand All @@ -472,11 +478,12 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.bankCode(6, 'n'),
BbanStructureEntry.accountNumber(19, 'n')));

structures.put(CountryCode.GB,
new BbanStructure(
BbanStructureEntry.bankCode(4, 'a'),
BbanStructureEntry.branchCode(6, 'n'),
BbanStructureEntry.accountNumber(8, 'n')));

// UK and its sub-territories (see https://www.iban.com/structure)
structures.put(CountryCode.GB, BbanStructure.UNITED_KINGDOM_STRUCTURE);
structures.put(CountryCode.IM, BbanStructure.UNITED_KINGDOM_STRUCTURE);
structures.put(CountryCode.GG, BbanStructure.UNITED_KINGDOM_STRUCTURE);
structures.put(CountryCode.JE, BbanStructure.UNITED_KINGDOM_STRUCTURE);

structures.put(CountryCode.AE,
new BbanStructure(
Expand All @@ -499,17 +506,13 @@ private BbanStructure(final BbanStructureEntry... entries) {
BbanStructureEntry.accountNumber(14, 'n'),
BbanStructureEntry.nationalCheckDigit(2, 'n')));

structures.put(CountryCode.WF, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.XK,
new BbanStructure(
BbanStructureEntry.bankCode(2, 'n'),
BbanStructureEntry.branchCode(2, 'n'),
BbanStructureEntry.accountNumber(10, 'n'),
BbanStructureEntry.nationalCheckDigit(2, 'n')));

structures.put(CountryCode.YT, BbanStructure.FRENCH_STRUCTURE);

structures.put(CountryCode.IQ,
new BbanStructure(
BbanStructureEntry.bankCode(4, 'a'),
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/iban4j/TestDataHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ public static Collection<Object[]> getIbanData() {
.accountNumber("0000078")
.nationalCheckDigit("5")
.build(), "FI2112345600000785"},
{new Iban.Builder()
.countryCode(CountryCode.AX)
.bankCode("987654")
.accountNumber("0002033")
.nationalCheckDigit("5")
.build(), "AX7898765400020335"},
{new Iban.Builder()
.countryCode(CountryCode.FR)
.bankCode("20041")
Expand Down Expand Up @@ -496,6 +502,24 @@ public static Collection<Object[]> getIbanData() {
.branchCode("601613")
.accountNumber("31926819")
.build(), "GB29NWBK60161331926819"},
{new Iban.Builder()
.countryCode(CountryCode.IM)
.bankCode("HBUK")
.branchCode("401276")
.accountNumber("12345678")
.build(), "IM20HBUK40127612345678"},
{new Iban.Builder()
.countryCode(CountryCode.GG)
.bankCode("INGB")
.branchCode("238859")
.accountNumber("12345678")
.build(), "GG65INGB23885912345678"},
{new Iban.Builder()
.countryCode(CountryCode.JE)
.bankCode("DEUT")
.branchCode("405081")
.accountNumber("12345678")
.build(), "JE51DEUT40508112345678"},
{new Iban.Builder()
.countryCode(CountryCode.VA)
.bankCode("001")
Expand Down

0 comments on commit 3c37aa6

Please sign in to comment.