| |
---|
| | import com.fasterxml.jackson.annotation.JsonProperty; |
---|
| | import org.ntlab.amaryllis.server.entities.Account; |
---|
| | |
---|
| | import java.util.ArrayList; |
---|
| | import java.util.HashMap; |
---|
| | |
---|
| | public class Accounts { |
---|
| | private static Accounts theInstance = null; |
---|
| | private ArrayList<Account> accounts = new ArrayList<Account>(); |
---|
| | private HashMap<String,Account> accountHashMap=new HashMap<>(); |
---|
| | |
---|
| | public static Accounts getInstance() { |
---|
| | if (theInstance == null) { |
---|
| | theInstance = new Accounts(); |
---|
| |
---|
| | if (a.getUid().equals(uid)) return a; |
---|
| | } |
---|
| | return null; |
---|
| | } |
---|
| | public Account getAccountByName(String name){ |
---|
| | for (Account a : accounts) { |
---|
| | if (a.getName().equals(name)) return a; |
---|
| | } |
---|
| | return null; |
---|
| | |
---|
| | } |
---|
| | |
---|
| | public boolean isRegisteredName(String name) { |
---|
| | boolean response; |
---|
| | |
---|
| | for (Account a : accounts) { |
---|
| | if (a.getName().equals(name)) return true; |
---|
| | } |
---|
| | return false; |
---|
| |
---|
| | } |
---|
| | |
---|
| | public void addAccount(Account account) { |
---|
| | accounts.add(account); |
---|
| | |
---|
| | accountHashMap.put(account.getUid(),account); |
---|
| | } |
---|
| | |
---|
| | public Account createAccount(String name, String password) { |
---|
| | Account newAccount = new Account(name, password); |
---|
| |
---|
| | return newAccount; |
---|
| | } |
---|
| | |
---|
| | public void removeAccount(String uid) { |
---|
| | |
---|
| | int index=0; |
---|
| | for(Account a:accounts){ |
---|
| | if(a.getUid().equals(uid))accounts.remove(index); |
---|
| | index++; |
---|
| | } |
---|
| | accountHashMap.remove(uid); |
---|
| | } |
---|
| | |
---|
| | |
---|
| | } |
---|
| | |