package account;
import java.util.ArrayList;
public class AccountManager {
private ArrayList<Account> accountList = new ArrayList<Account>();
private static AccountManager theInstance;
private AccountManager() {
}
public static AccountManager getInstance() {
if(theInstance == null) {
theInstance = new AccountManager();
}
return theInstance;
}
//アカウント登録
public boolean registration(String name, String pass, String sId) {
Account account;
for (int i=0; i<accountList.size(); i++) {
account = accountList.get(i);
String getname = account.getName();
//nameの重複確認
if (name.equals(getname)) {
//nameが重複している場合、falseを返す
return false;
}
}
//nameが重複していない(登録されていない)場合、登録する
account = new Account();
account.setName(name);
account.setPass(pass);
account.setsId(sId);
accountList.add(account);
//trueを返す
return true;
}
//アカウントログイン
public int login(String name, String pass, String sId) {
Account account = new Account();
for (int i=0; i<accountList.size(); i++) {
account = accountList.get(i);
String getname = account.getName();
//nameが登録されているか確認
if (name.equals(getname)) {
//登録されていた場合、passを取得する
String getpass = account.getPass();
//passが合っているか確認
if (pass.equals(getpass)) {
//name,passともにあっていた場合、0を返す
account.setsId(sId);
return 0;
} else {
//nameは合っているがpassが間違っていた場合、1を返す
return 1;
}
}
}
//nameがなかった場合、2を返す
return 2;
}
//sIdでアカウントを探す
public Account getAccount(String sId) {
Account account = new Account();
String getsid;
for (int i=0; i<accountList.size(); i++) {
account = accountList.get(i);
getsid = account.getsId();
//一致するsIdを探す
if (sId.equals(getsid)) {
//一致した場合、accountを返す
return account;
}
}
return null;
}
}