-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserDatabaseThread.java
More file actions
70 lines (67 loc) · 2.54 KB
/
Copy pathUserDatabaseThread.java
File metadata and controls
70 lines (67 loc) · 2.54 KB
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
/**
* Team Project -- Message
*
* This file handles the threads for the User Database
*
* @author Alan Yi
*
* @version November 1, 2024
*
*/
public class UserDatabaseThread extends Thread {
private Action action;
private String[] values;
private UserDatabase userDB;
public UserDatabaseThread(UserDatabase userDB, Action action, String[] values) {
this.userDB = userDB;
this.action = action;
this.values = values;
}
@Override
public void run() {
try {
switch (action) {
case CREATE_USER:
byte[] byteArray = values[4].getBytes();
this.userDB.createUser(values[0], values[1], values[2], values[3], byteArray);
break;
case VERIFY_LOGIN:
boolean login = this.userDB.verifyLogin(values[0], values[1]);
break;
case CHANGE_USERNAME:
User userToModify = UserDatabase.getUser(values[0]);
this.userDB.changeUsername(userToModify, values[1]);
break;
case SEARCH:
UserDatabase.getUser(this.values[0]);
break;
case ADD_FRIEND:
User user = UserDatabase.getUser(this.values[0]);
User otherUser = UserDatabase.getUser(this.values[1]);
UserDatabase.addFriend(user,otherUser);
break;
case REMOVE_FRIEND:
User user2 = UserDatabase.getUser(this.values[0]);
User otherUser2 = UserDatabase.getUser(this.values[1]);
UserDatabase.removeFriend(user2, otherUser2);
break;
case BLOCK:
User user3 = UserDatabase.getUser(this.values[0]);
User otherUser3 = UserDatabase.getUser(this.values[1]);
UserDatabase.blockUser(user3, otherUser3);
break;
case UNBLOCK:
User user4 = UserDatabase.getUser(this.values[0]);
User otherUser4 = UserDatabase.getUser(this.values[1]);
UserDatabase.unblockUser(user4, otherUser4);
break;
default:
break;
}
} catch (IndexOutOfBoundsException e) {
System.out.println("OUT OF BOUNDS, CHECK PARAMETERS");
} catch (Exception e) {
e.printStackTrace();
}
}
}