Newer
Older
CactusServer / src / main / java / cactusServer / models / Accounts.java
package cactusServer.models;

import javax.inject.Singleton;

import cactusServer.entities.Account;

import java.util.ArrayList;

@Singleton
public class Accounts {
	private static Accounts theInstance = null;
	private static ArrayList<Account> accounts = new ArrayList<Account>();

	public Accounts() {
		if (theInstance == null) {
			theInstance = this;
		}
	}

	public static Accounts getInstance() {
		if (theInstance == null) {
			theInstance = new Accounts();
		}
		return theInstance;
	}

	public static Account createAcount(String userID,String userName,String userPass) {
		System.out.println(userName);

		Account newAccount = new Account(userID, userName,userPass);
		accounts.add(newAccount);

		System.out.println(userID);

		return newAccount;
	}

	public static ArrayList<Account> getAccountList() {
		return accounts;
	}

	public static Account getAccount(String userID) {
		Account editAccount = null;
		for(int i=0;i<accounts.size();i++) {
			if(accounts.get(i).getId() == userID) {
				editAccount = accounts.get(i);
				break;
			}
		}
		return editAccount;
	}
	
	public String deleteAccount(int userID) {
		accounts.remove(userID);
		return "complated remove account";
	}

	public ArrayList<Account> getAccounts() {
		return accounts;
	}

}