54 lines
1.3 KiB
Java
54 lines
1.3 KiB
Java
package me.teridax.jcash.banking;
|
|
|
|
import java.util.*;
|
|
|
|
@SuppressWarnings("unused")
|
|
public final class Bank {
|
|
private final String name;
|
|
private final String blz;
|
|
private final Map<Owner, Set<Account>> accounts;
|
|
|
|
private Bank(String blz, String name) {
|
|
this.blz = blz;
|
|
this.name = name;
|
|
this.accounts = new HashMap<>();
|
|
}
|
|
|
|
public String getBlz() {
|
|
return blz;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (obj instanceof Bank) {
|
|
return Objects.equals(blz, ((Bank) obj).blz);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(blz);
|
|
}
|
|
|
|
public Account[] getAccountsOfOwner(Owner owner) {
|
|
return accounts.get(owner).toArray(Account[]::new);
|
|
}
|
|
|
|
private static String validateBlz(String maybeBlz) {
|
|
var builder = new StringBuilder();
|
|
maybeBlz.trim().chars().filter(ch -> Character.isDigit(ch) || Character.isLetter(ch)).forEach(builder::append);
|
|
var blz = builder.toString();
|
|
|
|
if (blz.isEmpty()) {
|
|
throw new IllegalArgumentException("Bank Blz must only contain letters and digits");
|
|
}
|
|
|
|
return blz;
|
|
}
|
|
}
|