You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
package hs.fulda.de.ci.exam.project;
|
|
|
|
import java.util.Collection;
|
|
import java.util.Map;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
public class AccountRepository {
|
|
Map<String, Account> accountList = new ConcurrentHashMap<String, Account>();
|
|
Map<Account, Person> personalInfo = new ConcurrentHashMap<>();
|
|
|
|
public boolean checkIfAccountAlreadyExist(Account account){
|
|
if(accountList.containsKey(generateKey(account))){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
Account findById(String id){
|
|
Account account = accountList.get(id);
|
|
return account;
|
|
}
|
|
|
|
private String generateKey(Account account) {
|
|
return String.format("%s", account.getId());
|
|
}
|
|
public Collection<Account> findAll() {
|
|
return accountList.values();
|
|
}
|
|
public boolean save(Account account){
|
|
accountList.put(generateKey(account), account);
|
|
return true;
|
|
}
|
|
public void addPersonalDetails(Person person, String id){
|
|
personalInfo.put(accountList.get(id), person);
|
|
}
|
|
|
|
public void delete(Account account) {
|
|
accountList.remove(generateKey(account));
|
|
}
|
|
}
|