-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserList.java
126 lines (118 loc) · 3.27 KB
/
UserList.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import java.util.ArrayList;
import java.util.UUID;
/**
* @author Andrew Chisolm, Bryan Munoz, Matt Olson, Daniel Ruiz, Jaden Arnold
* List of all Users
*/
public class UserList {
private ArrayList<User> users;
private ArrayList<Camper> campers;
private ArrayList<Counselor> counselors;
private ArrayList<Director> directors;
private static UserList userList;
/**
* The list of users
*/
private UserList() {
users = DataReader.getAllUsers();
campers = DataReader.getAllCampers();
counselors = DataReader.getAllCounselors();
directors = DataReader.getAllDirectors();
}
/**
* Makes a new userlist if one is not there
* @return a new UserList
*/
public static UserList getInstance() {
if (userList == null) {
userList = new UserList();
}
return userList;
}
/**
* Adds a user to camper nad Users then saves
* @param camper The name of the camper
*/
public void addUser(Camper camper) {
users.add(camper);
campers.add(camper);
DataWriter.saveAllUsers();
}
/**
* Adds a user to counselor and users
* @param counselor The name of the counselor
*/
public void addUser(Counselor counselor) {
users.add(counselor);
counselors.add(counselor);
DataWriter.saveAllUsers();
}
/**
* Adds a user to diectors and users
* @param director The name of the director
*/
public void addUser(Director director) {
users.add(director);
directors.add(director);
DataWriter.saveAllUsers();
}
/**
* Accessor for User ArrayList
* @return users
*/
public ArrayList<User> getUsers() {
return users;
}
public ArrayList<Camper> getCampers() {
return campers;
}
public ArrayList<Counselor> getCounselors() {
return counselors;
}
public ArrayList<Director> getDirectors() {
return directors;
}
/**
* Searches for a user by name
* @param firstName user's first name
* @param lastName user's last name
* @return the user; null if not found
*/
public User getUserByName(String firstName, String lastName) {
for(User user : users) {
if(user.getFullName().strip().equalsIgnoreCase(firstName + " " + lastName)) {
return user;
}
}
return null;
}
/**
* Searches for a user by UUID
* @param id UUID
* @return the user; null if not found
*/
public User getUserByUUID(UUID id) {
for(User user : users) {
if(user.getId().equals(id)) {
return user;
}
}
return null;
}
/**
* Removes a user from the list
* @param firstName user's first name
* @param lastName user's last name
*/
public void removeUser(String firstName, String lastName) {
for(User user : users) {
if(user.getFullName().strip().equalsIgnoreCase(firstName + " " + lastName)) {
users.remove(user);
campers.remove(user);
counselors.remove(user);
directors.remove(user);
}
}
DataWriter.saveAllUsers();
}
}