package org.ntlab.SproutServer.accounts; import javax.inject.Singleton; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import java.util.ArrayList; public class Accounts { private static Accounts theInstance = null; private ArrayList<Account> accounts = new ArrayList<Account>(); private int userID = 0; public Accounts() { if (theInstance == null) { theInstance = this; } } public static Accounts getInstance() { if (theInstance == null) { theInstance = new Accounts(); } return theInstance; } public void createAccount(int userId){ Account newAccount = new Account(userId, "user"+userId); accounts.add(newAccount); System.out.println(accounts.size()); } public Accounts getAccount() { Account ac = new Account(); this.userID = ac.getUserID(); return new Accounts(); } public boolean checkCreatedUser(int userId) { for (Account account : accounts) { if (account.getUserID() == userId) { return true; } } return false; } public ArrayList<Account> getAccounts() { return accounts; } public void setAccounts(ArrayList<Account> accounts) { this.accounts = accounts; } public String getUserNameById(int userId){ for (Account account: accounts){ if (account.getUserID() == userId) return account.getUserName(); } return "nameNone"; } public int getUserID() { return userID; } public void setUserID(int userId){ this.userID = userId; } }