From 8a42fdc38da8a8245d51042fed0640125795da50 Mon Sep 17 00:00:00 2001 From: teridax Date: Sun, 2 Jul 2023 17:45:04 +0200 Subject: [PATCH] added more documentation & restructured banking package --- src/me/teridax/jcash/Main.java | 4 ++++ src/me/teridax/jcash/banking/Bank.java | 6 ++++- src/me/teridax/jcash/banking/BankTest.java | 20 ++++++++++++++++ .../jcash/banking/{ => accounts}/Account.java | 24 +++++++++++++++---- .../{ => accounts}/CurrentAccount.java | 2 +- .../jcash/banking/{ => accounts}/Owner.java | 6 ++--- .../{ => accounts}/SavingsAccount.java | 2 +- .../BankingManagementSystem.java | 5 +++- .../BankingManagementSystemTest.java} | 4 ++-- .../banking/{ => management}/Profile.java | 18 +++++++++++++- src/me/teridax/jcash/gui/Loader.java | 2 +- .../jcash/gui/account/AccountController.java | 4 ++-- .../jcash/gui/account/AccountData.java | 2 +- .../jcash/gui/account/AccountView.java | 4 +++- .../jcash/gui/deposit/DepositDialog.java | 2 +- .../jcash/gui/deposit/DepositView.java | 1 - .../gui/login/AccountSelectionListener.java | 2 +- .../jcash/gui/login/LoginController.java | 3 +-- src/me/teridax/jcash/gui/login/LoginData.java | 6 ++--- .../jcash/gui/takeoff/TakeoffDialog.java | 2 +- .../jcash/gui/transfer/TransferData.java | 2 +- .../jcash/gui/transfer/TransferDialog.java | 6 ++--- 22 files changed, 93 insertions(+), 34 deletions(-) create mode 100644 src/me/teridax/jcash/banking/BankTest.java rename src/me/teridax/jcash/banking/{ => accounts}/Account.java (81%) rename src/me/teridax/jcash/banking/{ => accounts}/CurrentAccount.java (91%) rename src/me/teridax/jcash/banking/{ => accounts}/Owner.java (96%) rename src/me/teridax/jcash/banking/{ => accounts}/SavingsAccount.java (92%) rename src/me/teridax/jcash/banking/{ => management}/BankingManagementSystem.java (95%) rename src/me/teridax/jcash/banking/{DataClassTests.java => management/BankingManagementSystemTest.java} (83%) rename src/me/teridax/jcash/banking/{ => management}/Profile.java (73%) diff --git a/src/me/teridax/jcash/Main.java b/src/me/teridax/jcash/Main.java index 35d9c15..17282af 100644 --- a/src/me/teridax/jcash/Main.java +++ b/src/me/teridax/jcash/Main.java @@ -32,6 +32,10 @@ public final class Main { getInstance().showLoginScreen(); } + /** + * Get the main singleton instance of this program + * @return the singleton instance of this class + */ public static Main getInstance() { return instance; } diff --git a/src/me/teridax/jcash/banking/Bank.java b/src/me/teridax/jcash/banking/Bank.java index f2e59e4..6f04466 100644 --- a/src/me/teridax/jcash/banking/Bank.java +++ b/src/me/teridax/jcash/banking/Bank.java @@ -1,5 +1,9 @@ package me.teridax.jcash.banking; +import me.teridax.jcash.banking.accounts.Account; +import me.teridax.jcash.banking.accounts.Owner; +import me.teridax.jcash.banking.management.Profile; + import java.util.*; import java.util.regex.Pattern; @@ -23,7 +27,7 @@ public final class Bank { */ private final Map> accounts; - Bank(String blz, String name) { + public Bank(String blz, String name) { this.blz = blz; this.name = name; this.accounts = new HashMap<>(); diff --git a/src/me/teridax/jcash/banking/BankTest.java b/src/me/teridax/jcash/banking/BankTest.java new file mode 100644 index 0000000..7bf5cb3 --- /dev/null +++ b/src/me/teridax/jcash/banking/BankTest.java @@ -0,0 +1,20 @@ +package me.teridax.jcash.banking; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class BankTest { + + @Test + public void testBlzValidation() { + assertEquals(Bank.validateBlz("MA2424"), "MA2424"); + assertEquals(Bank.validateBlz("VR-BANK-567"), "VR-BANK-567"); + assertEquals(Bank.validateBlz("19087"), "19087"); + } + + @Test(expected = IllegalArgumentException.class) + public void testBlzValidationException() { + assertEquals(Bank.validateBlz("MA2.&424"), "MA2.&424"); + } +} diff --git a/src/me/teridax/jcash/banking/Account.java b/src/me/teridax/jcash/banking/accounts/Account.java similarity index 81% rename from src/me/teridax/jcash/banking/Account.java rename to src/me/teridax/jcash/banking/accounts/Account.java index fb02c06..4ea3177 100644 --- a/src/me/teridax/jcash/banking/Account.java +++ b/src/me/teridax/jcash/banking/accounts/Account.java @@ -1,4 +1,4 @@ -package me.teridax.jcash.banking; +package me.teridax.jcash.banking.accounts; import me.teridax.jcash.decode.StringDecoder; @@ -34,7 +34,7 @@ public abstract class Account { * Parses a row of a fixed amount of columns into an account. * This function will attempt to create an instance of two classes which inherit from Account. * @param columns array of 6 strings - * @return either an instance of {@link me.teridax.jcash.banking.SavingsAccount} or an instance of {@link me.teridax.jcash.banking.CurrentAccount} + * @return either an instance of {@link SavingsAccount} or an instance of {@link CurrentAccount} * @throws IllegalArgumentException if the account type cannot be determined or the provided data is invalid * @throws NullPointerException if columns is null */ @@ -55,9 +55,9 @@ public abstract class Account { } else if (type.equals("Girokonto")) { var overdraft = StringDecoder.decodeCurrency(columns[5]); return new CurrentAccount(iban, pin, balance, overdraft); - } else { + } else throw new IllegalArgumentException("Invalid account type: " + type); - } + } catch (IllegalArgumentException | NullPointerException e) { throw new IllegalArgumentException("Account format: ", e); } @@ -80,6 +80,12 @@ public abstract class Account { return Objects.hash(iban); } + /** + * Returns true if the parameter is an instance of class {@link Account} and both their + * ibans are equal. + * @param obj the obj to compare to + * @return true if the parameter is an instance of class {@link Account} and their ibans match + */ @Override public boolean equals(Object obj) { if (obj instanceof Account) @@ -98,7 +104,15 @@ public abstract class Account { return String.format("%s (%s)", iban, getClass().getSimpleName()); } - public void deposit(double amount) { + /** + * Add a non-negative value onto the balance of this account. + * @param amount the amount of value to add + * @throws IllegalArgumentException if amount is negative + */ + public void deposit(double amount) throws IllegalArgumentException { + if (amount < 0) + throw new IllegalArgumentException("amount must be positive"); + this.balance += amount; } diff --git a/src/me/teridax/jcash/banking/CurrentAccount.java b/src/me/teridax/jcash/banking/accounts/CurrentAccount.java similarity index 91% rename from src/me/teridax/jcash/banking/CurrentAccount.java rename to src/me/teridax/jcash/banking/accounts/CurrentAccount.java index 5346226..f655d7a 100644 --- a/src/me/teridax/jcash/banking/CurrentAccount.java +++ b/src/me/teridax/jcash/banking/accounts/CurrentAccount.java @@ -1,4 +1,4 @@ -package me.teridax.jcash.banking; +package me.teridax.jcash.banking.accounts; /** * Immutable currency account storing only overdraft. diff --git a/src/me/teridax/jcash/banking/Owner.java b/src/me/teridax/jcash/banking/accounts/Owner.java similarity index 96% rename from src/me/teridax/jcash/banking/Owner.java rename to src/me/teridax/jcash/banking/accounts/Owner.java index 3822b62..391d8ae 100644 --- a/src/me/teridax/jcash/banking/Owner.java +++ b/src/me/teridax/jcash/banking/accounts/Owner.java @@ -1,4 +1,4 @@ -package me.teridax.jcash.banking; +package me.teridax.jcash.banking.accounts; import me.teridax.jcash.decode.StringDecoder; @@ -86,9 +86,9 @@ public final class Owner { @Override public boolean equals(Object obj) { - if (obj instanceof Owner) { + if (obj instanceof Owner) return this.uid == ((Owner) obj).getUid(); - } + return false; } diff --git a/src/me/teridax/jcash/banking/SavingsAccount.java b/src/me/teridax/jcash/banking/accounts/SavingsAccount.java similarity index 92% rename from src/me/teridax/jcash/banking/SavingsAccount.java rename to src/me/teridax/jcash/banking/accounts/SavingsAccount.java index 6f7beda..4a0801f 100644 --- a/src/me/teridax/jcash/banking/SavingsAccount.java +++ b/src/me/teridax/jcash/banking/accounts/SavingsAccount.java @@ -1,4 +1,4 @@ -package me.teridax.jcash.banking; +package me.teridax.jcash.banking.accounts; /** * Savings account representing a german "Sparkonto". diff --git a/src/me/teridax/jcash/banking/BankingManagementSystem.java b/src/me/teridax/jcash/banking/management/BankingManagementSystem.java similarity index 95% rename from src/me/teridax/jcash/banking/BankingManagementSystem.java rename to src/me/teridax/jcash/banking/management/BankingManagementSystem.java index 2192ec6..57970a3 100644 --- a/src/me/teridax/jcash/banking/BankingManagementSystem.java +++ b/src/me/teridax/jcash/banking/management/BankingManagementSystem.java @@ -1,5 +1,8 @@ -package me.teridax.jcash.banking; +package me.teridax.jcash.banking.management; +import me.teridax.jcash.banking.Bank; +import me.teridax.jcash.banking.accounts.Account; +import me.teridax.jcash.banking.accounts.Owner; import me.teridax.jcash.decode.StringDecoder; import java.io.IOException; diff --git a/src/me/teridax/jcash/banking/DataClassTests.java b/src/me/teridax/jcash/banking/management/BankingManagementSystemTest.java similarity index 83% rename from src/me/teridax/jcash/banking/DataClassTests.java rename to src/me/teridax/jcash/banking/management/BankingManagementSystemTest.java index eed1dfa..c0956de 100644 --- a/src/me/teridax/jcash/banking/DataClassTests.java +++ b/src/me/teridax/jcash/banking/management/BankingManagementSystemTest.java @@ -1,10 +1,10 @@ -package me.teridax.jcash.banking; +package me.teridax.jcash.banking.management; import org.junit.Test; import java.nio.file.Paths; -public class DataClassTests { +public class BankingManagementSystemTest { @Test public void test() { diff --git a/src/me/teridax/jcash/banking/Profile.java b/src/me/teridax/jcash/banking/management/Profile.java similarity index 73% rename from src/me/teridax/jcash/banking/Profile.java rename to src/me/teridax/jcash/banking/management/Profile.java index 3e35ef9..717b169 100644 --- a/src/me/teridax/jcash/banking/Profile.java +++ b/src/me/teridax/jcash/banking/management/Profile.java @@ -1,4 +1,8 @@ -package me.teridax.jcash.banking; +package me.teridax.jcash.banking.management; + +import me.teridax.jcash.banking.Bank; +import me.teridax.jcash.banking.accounts.Account; +import me.teridax.jcash.banking.accounts.Owner; /** * Groups an owner and all of its accounts registered at a specific bank together. @@ -8,9 +12,21 @@ package me.teridax.jcash.banking; */ public class Profile { + /** + * Owner of the primary account and all other accounts registered at a specific bank + */ private final Owner owner; + /** + * The bank that manages every account referenced by this profile + */ private final Bank bank; + /** + * Primary or currently selected account. + */ private Account primaryAccount; + /** + * All other account registered at a specific bank for the specified owner + */ private final Account[] accounts; public Profile(Owner owner, Bank bank, Account account, Account[] accounts) { diff --git a/src/me/teridax/jcash/gui/Loader.java b/src/me/teridax/jcash/gui/Loader.java index b12ef0c..19d5946 100644 --- a/src/me/teridax/jcash/gui/Loader.java +++ b/src/me/teridax/jcash/gui/Loader.java @@ -1,6 +1,6 @@ package me.teridax.jcash.gui; -import me.teridax.jcash.banking.BankingManagementSystem; +import me.teridax.jcash.banking.management.BankingManagementSystem; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; diff --git a/src/me/teridax/jcash/gui/account/AccountController.java b/src/me/teridax/jcash/gui/account/AccountController.java index 07c6f67..28a0306 100644 --- a/src/me/teridax/jcash/gui/account/AccountController.java +++ b/src/me/teridax/jcash/gui/account/AccountController.java @@ -1,8 +1,8 @@ package me.teridax.jcash.gui.account; import me.teridax.jcash.Main; -import me.teridax.jcash.banking.BankingManagementSystem; -import me.teridax.jcash.banking.Profile; +import me.teridax.jcash.banking.management.BankingManagementSystem; +import me.teridax.jcash.banking.management.Profile; import me.teridax.jcash.gui.deposit.DepositDialog; import me.teridax.jcash.gui.takeoff.TakeoffDialog; import me.teridax.jcash.gui.transfer.TransferDialog; diff --git a/src/me/teridax/jcash/gui/account/AccountData.java b/src/me/teridax/jcash/gui/account/AccountData.java index 37e02d3..8a8cde1 100644 --- a/src/me/teridax/jcash/gui/account/AccountData.java +++ b/src/me/teridax/jcash/gui/account/AccountData.java @@ -1,6 +1,6 @@ package me.teridax.jcash.gui.account; -import me.teridax.jcash.banking.BankingManagementSystem; +import me.teridax.jcash.banking.management.BankingManagementSystem; public class AccountData { diff --git a/src/me/teridax/jcash/gui/account/AccountView.java b/src/me/teridax/jcash/gui/account/AccountView.java index e716a2d..455aa95 100644 --- a/src/me/teridax/jcash/gui/account/AccountView.java +++ b/src/me/teridax/jcash/gui/account/AccountView.java @@ -1,6 +1,8 @@ package me.teridax.jcash.gui.account; -import me.teridax.jcash.banking.*; +import me.teridax.jcash.banking.accounts.CurrentAccount; +import me.teridax.jcash.banking.accounts.SavingsAccount; +import me.teridax.jcash.banking.management.Profile; import me.teridax.jcash.decode.StringDecoder; import javax.swing.*; diff --git a/src/me/teridax/jcash/gui/deposit/DepositDialog.java b/src/me/teridax/jcash/gui/deposit/DepositDialog.java index 67ae7ef..dce88a3 100644 --- a/src/me/teridax/jcash/gui/deposit/DepositDialog.java +++ b/src/me/teridax/jcash/gui/deposit/DepositDialog.java @@ -1,6 +1,6 @@ package me.teridax.jcash.gui.deposit; -import me.teridax.jcash.banking.Account; +import me.teridax.jcash.banking.accounts.Account; public class DepositDialog { diff --git a/src/me/teridax/jcash/gui/deposit/DepositView.java b/src/me/teridax/jcash/gui/deposit/DepositView.java index f48cdc0..afba716 100644 --- a/src/me/teridax/jcash/gui/deposit/DepositView.java +++ b/src/me/teridax/jcash/gui/deposit/DepositView.java @@ -1,6 +1,5 @@ package me.teridax.jcash.gui.deposit; -import me.teridax.jcash.banking.Account; import me.teridax.jcash.decode.StringDecoder; import javax.swing.*; diff --git a/src/me/teridax/jcash/gui/login/AccountSelectionListener.java b/src/me/teridax/jcash/gui/login/AccountSelectionListener.java index 5e5de2c..080efe3 100644 --- a/src/me/teridax/jcash/gui/login/AccountSelectionListener.java +++ b/src/me/teridax/jcash/gui/login/AccountSelectionListener.java @@ -1,6 +1,6 @@ package me.teridax.jcash.gui.login; -import me.teridax.jcash.banking.Profile; +import me.teridax.jcash.banking.management.Profile; /** * Listens for changes in a selected account. diff --git a/src/me/teridax/jcash/gui/login/LoginController.java b/src/me/teridax/jcash/gui/login/LoginController.java index 88c1566..1344adb 100644 --- a/src/me/teridax/jcash/gui/login/LoginController.java +++ b/src/me/teridax/jcash/gui/login/LoginController.java @@ -1,8 +1,7 @@ package me.teridax.jcash.gui.login; -import me.teridax.jcash.banking.BankingManagementSystem; +import me.teridax.jcash.banking.management.BankingManagementSystem; -import javax.swing.*; import java.awt.event.ActionEvent; import java.util.Optional; diff --git a/src/me/teridax/jcash/gui/login/LoginData.java b/src/me/teridax/jcash/gui/login/LoginData.java index bb37955..04ae706 100644 --- a/src/me/teridax/jcash/gui/login/LoginData.java +++ b/src/me/teridax/jcash/gui/login/LoginData.java @@ -1,12 +1,12 @@ package me.teridax.jcash.gui.login; -import me.teridax.jcash.banking.BankingManagementSystem; -import me.teridax.jcash.banking.Profile; +import me.teridax.jcash.banking.management.BankingManagementSystem; +import me.teridax.jcash.banking.management.Profile; import java.util.Optional; /** - * Wrapper class for a {@link me.teridax.jcash.banking.BankingManagementSystem} + * Wrapper class for a {@link BankingManagementSystem} */ public class LoginData { diff --git a/src/me/teridax/jcash/gui/takeoff/TakeoffDialog.java b/src/me/teridax/jcash/gui/takeoff/TakeoffDialog.java index 686d14f..5bdc595 100644 --- a/src/me/teridax/jcash/gui/takeoff/TakeoffDialog.java +++ b/src/me/teridax/jcash/gui/takeoff/TakeoffDialog.java @@ -1,6 +1,6 @@ package me.teridax.jcash.gui.takeoff; -import me.teridax.jcash.banking.Account; +import me.teridax.jcash.banking.accounts.Account; public class TakeoffDialog { diff --git a/src/me/teridax/jcash/gui/transfer/TransferData.java b/src/me/teridax/jcash/gui/transfer/TransferData.java index fe2f827..8ddb3e4 100644 --- a/src/me/teridax/jcash/gui/transfer/TransferData.java +++ b/src/me/teridax/jcash/gui/transfer/TransferData.java @@ -1,6 +1,6 @@ package me.teridax.jcash.gui.transfer; -import me.teridax.jcash.banking.BankingManagementSystem; +import me.teridax.jcash.banking.management.BankingManagementSystem; import me.teridax.jcash.decode.StringDecoder; public class TransferData { diff --git a/src/me/teridax/jcash/gui/transfer/TransferDialog.java b/src/me/teridax/jcash/gui/transfer/TransferDialog.java index 5bdedec..818724f 100644 --- a/src/me/teridax/jcash/gui/transfer/TransferDialog.java +++ b/src/me/teridax/jcash/gui/transfer/TransferDialog.java @@ -1,9 +1,7 @@ package me.teridax.jcash.gui.transfer; -import me.teridax.jcash.banking.Account; -import me.teridax.jcash.banking.BankingManagementSystem; - -import javax.swing.*; +import me.teridax.jcash.banking.accounts.Account; +import me.teridax.jcash.banking.management.BankingManagementSystem; import static javax.swing.JOptionPane.ERROR_MESSAGE; import static javax.swing.JOptionPane.showMessageDialog;