Skip to content

Commit 80973a9

Browse files
Ran spotlessApply
1 parent 1da78bf commit 80973a9

File tree

11 files changed

+39
-102
lines changed

11 files changed

+39
-102
lines changed

lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/AccountOwner.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,17 @@
33
import java.util.Set;
44
import java.util.UUID;
55

6-
76
public interface AccountOwner {
8-
9-
7+
108
UUID getId();
11-
12-
9+
1310
String getName();
14-
15-
11+
1612
void addAccount(CheckingAccount account);
17-
18-
13+
1914
void addSavingsAccount(SavingAccount account);
20-
21-
15+
2216
Set<CheckingAccount> getAccounts();
23-
24-
17+
2518
Set<SavingAccount> getSavingsAccounts();
26-
}
19+
}

lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/BankAtm.java

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
package com.codedifferently.lesson17.bank;
22

3+
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
34
import java.util.HashMap;
45
import java.util.Map;
56
import java.util.Set;
67
import java.util.UUID;
78

8-
import com.codedifferently.lesson17.bank.exceptions.AccountNotFoundException;
9-
10-
119
public class BankAtm {
1210

1311
private final Map<UUID, AccountOwner> accountOwnerById = new HashMap<>();
1412
private final Map<String, CheckingAccount> accountByNumber = new HashMap<>();
1513
private final Map<String, SavingAccount> savingsAccountByNumber = new HashMap<>();
16-
14+
1715
public void addAccount(CheckingAccount account) {
1816
accountByNumber.put(account.getAccountNumber(), account);
1917
account
@@ -25,7 +23,6 @@ public void addAccount(CheckingAccount account) {
2523
});
2624
}
2725

28-
2926
public void addAccount(SavingAccount account) {
3027
savingsAccountByNumber.put(account.getAccountNumber(), account);
3128
account
@@ -37,58 +34,51 @@ public void addAccount(SavingAccount account) {
3734
});
3835
}
3936

40-
4137
public Set<CheckingAccount> findAccountsByCustomerId(UUID customerId) {
4238
return accountOwnerById.containsKey(customerId)
4339
? accountOwnerById.get(customerId).getAccounts()
4440
: Set.of();
4541
}
4642

47-
4843
public void depositFunds(String accountNumber, double amount) {
49-
44+
5045
CheckingAccount checkingAccount = accountByNumber.get(accountNumber);
5146
if (checkingAccount != null) {
5247
checkingAccount.deposit(amount);
5348
return;
5449
}
55-
56-
50+
5751
SavingAccount savingsAccount = savingsAccountByNumber.get(accountNumber);
5852
if (savingsAccount != null) {
5953
savingsAccount.deposit(amount);
6054
return;
6155
}
62-
56+
6357
throw new AccountNotFoundException("Account not found");
6458
}
6559

66-
6760
public void depositFunds(String accountNumber, Check check) {
6861
CheckingAccount account = getAccountOrThrow(accountNumber);
6962
check.depositFunds(account);
7063
}
7164

72-
7365
public void withdrawFunds(String accountNumber, double amount) {
74-
66+
7567
CheckingAccount checkingAccount = accountByNumber.get(accountNumber);
7668
if (checkingAccount != null) {
7769
checkingAccount.withdraw(amount);
7870
return;
7971
}
80-
81-
72+
8273
SavingAccount savingsAccount = savingsAccountByNumber.get(accountNumber);
8374
if (savingsAccount != null) {
8475
savingsAccount.withdraw(amount);
8576
return;
8677
}
87-
78+
8879
throw new AccountNotFoundException("Account not found");
8980
}
9081

91-
9282
private CheckingAccount getAccountOrThrow(String accountNumber) {
9383
CheckingAccount account = accountByNumber.get(accountNumber);
9484
if (account == null) {

lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/Business.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.Set;
55
import java.util.UUID;
66

7-
87
public class Business implements AccountOwner {
98

109
private final UUID id;
@@ -13,54 +12,45 @@ public class Business implements AccountOwner {
1312
private final Set<CheckingAccount> accounts = new HashSet<>();
1413
private final Set<SavingAccount> savingsAccounts = new HashSet<>();
1514

16-
1715
public Business(UUID id, String businessName, String taxId) {
1816
this.id = id;
1917
this.businessName = businessName;
2018
this.taxId = taxId;
2119
}
2220

23-
2421
@Override
2522
public UUID getId() {
2623
return id;
2724
}
2825

29-
3026
@Override
3127
public String getName() {
3228
return businessName;
3329
}
3430

35-
3631
public String getBusinessName() {
3732
return businessName;
3833
}
3934

40-
4135
public String getTaxId() {
4236
return taxId;
4337
}
4438

45-
4639
@Override
4740
public void addAccount(CheckingAccount account) {
4841
accounts.add(account);
4942
}
5043

51-
5244
@Override
5345
public void addSavingsAccount(SavingAccount account) {
5446
savingsAccounts.add(account);
5547
}
5648

57-
5849
@Override
5950
public Set<CheckingAccount> getAccounts() {
6051
return accounts;
6152
}
6253

63-
6454
@Override
6555
public Set<SavingAccount> getSavingsAccounts() {
6656
return savingsAccounts;
@@ -81,6 +71,15 @@ public boolean equals(Object obj) {
8171

8272
@Override
8373
public String toString() {
84-
return "Business{" + "id=" + id + ", businessName='" + businessName + '\'' + ", taxId='" + taxId + '\'' + '}';
74+
return "Business{"
75+
+ "id="
76+
+ id
77+
+ ", businessName='"
78+
+ businessName
79+
+ '\''
80+
+ ", taxId='"
81+
+ taxId
82+
+ '\''
83+
+ '}';
8584
}
86-
}
85+
}

lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/BusinessCheckingAccount.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22

33
import java.util.Set;
44

5-
65
public class BusinessCheckingAccount extends CheckingAccount {
76

8-
9-
public BusinessCheckingAccount(String accountNumber, Set<AccountOwner> owners, double initialBalance) {
7+
public BusinessCheckingAccount(
8+
String accountNumber, Set<AccountOwner> owners, double initialBalance) {
109
super(accountNumber, owners, initialBalance);
1110
validateBusinessOwnership(owners);
1211
}
1312

14-
1513
private void validateBusinessOwnership(Set<AccountOwner> owners) {
16-
boolean hasBusiness = owners.stream()
17-
.anyMatch(owner -> owner instanceof Business);
18-
14+
boolean hasBusiness = owners.stream().anyMatch(owner -> owner instanceof Business);
15+
1916
if (!hasBusiness) {
20-
throw new IllegalArgumentException("Business checking account must have at least one business owner");
17+
throw new IllegalArgumentException(
18+
"Business checking account must have at least one business owner");
2119
}
2220
}
2321

@@ -33,4 +31,4 @@ public String toString() {
3331
+ !isClosed()
3432
+ '}';
3533
}
36-
}
34+
}

lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/Check.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
import com.codedifferently.lesson17.bank.exceptions.CheckVoidedException;
44

5-
65
public class Check {
76

87
private final String checkNumber;
98
private final double amount;
109
private final CheckingAccount account;
1110
private boolean isVoided = false;
1211

13-
1412
public Check(String checkNumber, double amount, CheckingAccount account) {
1513
if (amount <= 0) {
1614
throw new IllegalArgumentException("Check amount must be positive");
@@ -20,32 +18,26 @@ public Check(String checkNumber, double amount, CheckingAccount account) {
2018
this.account = account;
2119
}
2220

23-
2421
public String getCheckNumber() {
2522
return checkNumber;
2623
}
2724

28-
2925
public double getAmount() {
3026
return amount;
3127
}
3228

33-
3429
public CheckingAccount getAccount() {
3530
return account;
3631
}
3732

38-
3933
public boolean getIsVoided() {
4034
return isVoided;
4135
}
4236

43-
4437
public void voidCheck() {
4538
isVoided = true;
4639
}
4740

48-
4941
public void depositFunds(CheckingAccount toAccount) {
5042
if (isVoided) {
5143
throw new CheckVoidedException("Check is voided");

lesson_17/bank/bank_app/src/main/java/com/codedifferently/lesson17/bank/CheckingAccount.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.codedifferently.lesson17.bank;
22

3-
import java.util.Set;
4-
53
import com.codedifferently.lesson17.bank.exceptions.InsufficientFundsException;
6-
4+
import java.util.Set;
75

86
public class CheckingAccount {
97

@@ -12,7 +10,6 @@ public class CheckingAccount {
1210
private double balance;
1311
private boolean isActive;
1412

15-
1613
public CheckingAccount(String accountNumber, Set<AccountOwner> owners, double initialBalance) {
1714
this.accountNumber = accountNumber;
1815
this.owners = owners;
@@ -29,12 +26,10 @@ public String getAccountNumber() {
2926
return accountNumber;
3027
}
3128

32-
3329
public Set<AccountOwner> getOwners() {
3430
return owners;
3531
}
3632

37-
3833
public void deposit(double amount) throws IllegalStateException {
3934
if (isClosed()) {
4035
throw new IllegalStateException("Cannot deposit to a closed account");
@@ -45,7 +40,6 @@ public void deposit(double amount) throws IllegalStateException {
4540
balance += amount;
4641
}
4742

48-
4943
public void withdraw(double amount) throws InsufficientFundsException {
5044
if (isClosed()) {
5145
throw new IllegalStateException("Cannot withdraw from a closed account");
@@ -59,20 +53,17 @@ public void withdraw(double amount) throws InsufficientFundsException {
5953
balance -= amount;
6054
}
6155

62-
6356
public double getBalance() {
6457
return balance;
6558
}
6659

67-
6860
public void closeAccount() throws IllegalStateException {
6961
if (balance > 0) {
7062
throw new IllegalStateException("Cannot close account with a positive balance");
7163
}
7264
isActive = false;
7365
}
7466

75-
7667
public boolean isClosed() {
7768
return !isActive;
7869
}

0 commit comments

Comments
 (0)