added more documentation & restructured banking package

This commit is contained in:
Sven Vogel 2023-07-02 17:45:04 +02:00
parent 134db208d9
commit 8a42fdc38d
22 changed files with 93 additions and 34 deletions

View File

@ -32,6 +32,10 @@ public final class Main {
getInstance().showLoginScreen(); getInstance().showLoginScreen();
} }
/**
* Get the main singleton instance of this program
* @return the singleton instance of this class
*/
public static Main getInstance() { public static Main getInstance() {
return instance; return instance;
} }

View File

@ -1,5 +1,9 @@
package me.teridax.jcash.banking; 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.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -23,7 +27,7 @@ public final class Bank {
*/ */
private final Map<Owner, Set<Account>> accounts; private final Map<Owner, Set<Account>> accounts;
Bank(String blz, String name) { public Bank(String blz, String name) {
this.blz = blz; this.blz = blz;
this.name = name; this.name = name;
this.accounts = new HashMap<>(); this.accounts = new HashMap<>();

View File

@ -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");
}
}

View File

@ -1,4 +1,4 @@
package me.teridax.jcash.banking; package me.teridax.jcash.banking.accounts;
import me.teridax.jcash.decode.StringDecoder; 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. * 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. * This function will attempt to create an instance of two classes which inherit from Account.
* @param columns array of 6 strings * @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 IllegalArgumentException if the account type cannot be determined or the provided data is invalid
* @throws NullPointerException if columns is null * @throws NullPointerException if columns is null
*/ */
@ -55,9 +55,9 @@ public abstract class Account {
} else if (type.equals("Girokonto")) { } else if (type.equals("Girokonto")) {
var overdraft = StringDecoder.decodeCurrency(columns[5]); var overdraft = StringDecoder.decodeCurrency(columns[5]);
return new CurrentAccount(iban, pin, balance, overdraft); return new CurrentAccount(iban, pin, balance, overdraft);
} else { } else
throw new IllegalArgumentException("Invalid account type: " + type); throw new IllegalArgumentException("Invalid account type: " + type);
}
} catch (IllegalArgumentException | NullPointerException e) { } catch (IllegalArgumentException | NullPointerException e) {
throw new IllegalArgumentException("Account format: ", e); throw new IllegalArgumentException("Account format: ", e);
} }
@ -80,6 +80,12 @@ public abstract class Account {
return Objects.hash(iban); 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 @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof Account) if (obj instanceof Account)
@ -98,7 +104,15 @@ public abstract class Account {
return String.format("%s (%s)", iban, getClass().getSimpleName()); 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; this.balance += amount;
} }

View File

@ -1,4 +1,4 @@
package me.teridax.jcash.banking; package me.teridax.jcash.banking.accounts;
/** /**
* Immutable currency account storing only overdraft. * Immutable currency account storing only overdraft.

View File

@ -1,4 +1,4 @@
package me.teridax.jcash.banking; package me.teridax.jcash.banking.accounts;
import me.teridax.jcash.decode.StringDecoder; import me.teridax.jcash.decode.StringDecoder;
@ -86,9 +86,9 @@ public final class Owner {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof Owner) { if (obj instanceof Owner)
return this.uid == ((Owner) obj).getUid(); return this.uid == ((Owner) obj).getUid();
}
return false; return false;
} }

View File

@ -1,4 +1,4 @@
package me.teridax.jcash.banking; package me.teridax.jcash.banking.accounts;
/** /**
* Savings account representing a german "Sparkonto". * Savings account representing a german "Sparkonto".

View File

@ -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 me.teridax.jcash.decode.StringDecoder;
import java.io.IOException; import java.io.IOException;

View File

@ -1,10 +1,10 @@
package me.teridax.jcash.banking; package me.teridax.jcash.banking.management;
import org.junit.Test; import org.junit.Test;
import java.nio.file.Paths; import java.nio.file.Paths;
public class DataClassTests { public class BankingManagementSystemTest {
@Test @Test
public void test() { public void test() {

View File

@ -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. * 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 { public class Profile {
/**
* Owner of the primary account and all other accounts registered at a specific bank
*/
private final Owner owner; private final Owner owner;
/**
* The bank that manages every account referenced by this profile
*/
private final Bank bank; private final Bank bank;
/**
* Primary or currently selected account.
*/
private Account primaryAccount; private Account primaryAccount;
/**
* All other account registered at a specific bank for the specified owner
*/
private final Account[] accounts; private final Account[] accounts;
public Profile(Owner owner, Bank bank, Account account, Account[] accounts) { public Profile(Owner owner, Bank bank, Account account, Account[] accounts) {

View File

@ -1,6 +1,6 @@
package me.teridax.jcash.gui; package me.teridax.jcash.gui;
import me.teridax.jcash.banking.BankingManagementSystem; import me.teridax.jcash.banking.management.BankingManagementSystem;
import javax.swing.*; import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;

View File

@ -1,8 +1,8 @@
package me.teridax.jcash.gui.account; package me.teridax.jcash.gui.account;
import me.teridax.jcash.Main; import me.teridax.jcash.Main;
import me.teridax.jcash.banking.BankingManagementSystem; import me.teridax.jcash.banking.management.BankingManagementSystem;
import me.teridax.jcash.banking.Profile; import me.teridax.jcash.banking.management.Profile;
import me.teridax.jcash.gui.deposit.DepositDialog; import me.teridax.jcash.gui.deposit.DepositDialog;
import me.teridax.jcash.gui.takeoff.TakeoffDialog; import me.teridax.jcash.gui.takeoff.TakeoffDialog;
import me.teridax.jcash.gui.transfer.TransferDialog; import me.teridax.jcash.gui.transfer.TransferDialog;

View File

@ -1,6 +1,6 @@
package me.teridax.jcash.gui.account; package me.teridax.jcash.gui.account;
import me.teridax.jcash.banking.BankingManagementSystem; import me.teridax.jcash.banking.management.BankingManagementSystem;
public class AccountData { public class AccountData {

View File

@ -1,6 +1,8 @@
package me.teridax.jcash.gui.account; 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 me.teridax.jcash.decode.StringDecoder;
import javax.swing.*; import javax.swing.*;

View File

@ -1,6 +1,6 @@
package me.teridax.jcash.gui.deposit; package me.teridax.jcash.gui.deposit;
import me.teridax.jcash.banking.Account; import me.teridax.jcash.banking.accounts.Account;
public class DepositDialog { public class DepositDialog {

View File

@ -1,6 +1,5 @@
package me.teridax.jcash.gui.deposit; package me.teridax.jcash.gui.deposit;
import me.teridax.jcash.banking.Account;
import me.teridax.jcash.decode.StringDecoder; import me.teridax.jcash.decode.StringDecoder;
import javax.swing.*; import javax.swing.*;

View File

@ -1,6 +1,6 @@
package me.teridax.jcash.gui.login; 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. * Listens for changes in a selected account.

View File

@ -1,8 +1,7 @@
package me.teridax.jcash.gui.login; 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.awt.event.ActionEvent;
import java.util.Optional; import java.util.Optional;

View File

@ -1,12 +1,12 @@
package me.teridax.jcash.gui.login; package me.teridax.jcash.gui.login;
import me.teridax.jcash.banking.BankingManagementSystem; import me.teridax.jcash.banking.management.BankingManagementSystem;
import me.teridax.jcash.banking.Profile; import me.teridax.jcash.banking.management.Profile;
import java.util.Optional; import java.util.Optional;
/** /**
* Wrapper class for a {@link me.teridax.jcash.banking.BankingManagementSystem} * Wrapper class for a {@link BankingManagementSystem}
*/ */
public class LoginData { public class LoginData {

View File

@ -1,6 +1,6 @@
package me.teridax.jcash.gui.takeoff; package me.teridax.jcash.gui.takeoff;
import me.teridax.jcash.banking.Account; import me.teridax.jcash.banking.accounts.Account;
public class TakeoffDialog { public class TakeoffDialog {

View File

@ -1,6 +1,6 @@
package me.teridax.jcash.gui.transfer; 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; import me.teridax.jcash.decode.StringDecoder;
public class TransferData { public class TransferData {

View File

@ -1,9 +1,7 @@
package me.teridax.jcash.gui.transfer; package me.teridax.jcash.gui.transfer;
import me.teridax.jcash.banking.Account; import me.teridax.jcash.banking.accounts.Account;
import me.teridax.jcash.banking.BankingManagementSystem; import me.teridax.jcash.banking.management.BankingManagementSystem;
import javax.swing.*;
import static javax.swing.JOptionPane.ERROR_MESSAGE; import static javax.swing.JOptionPane.ERROR_MESSAGE;
import static javax.swing.JOptionPane.showMessageDialog; import static javax.swing.JOptionPane.showMessageDialog;