-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.java
More file actions
41 lines (32 loc) · 974 Bytes
/
User.java
File metadata and controls
41 lines (32 loc) · 974 Bytes
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
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class User {
private final String userId;
private final String name;
private final Set<String> following; // Set of userIds that this user follows (thread-safe)
public User(String userId, String name) {
this.userId = userId;
this.name = name;
this.following = ConcurrentHashMap.newKeySet(); // Thread-safe set
}
public String getUserId() {
return userId;
}
public String getName() {
return name;
}
public Set<String> getFollowing() {
return following;
}
public void follow(String userId) {
if (!userId.equals(this.userId)) {
following.add(userId);
}
}
public void unfollow(String userId) {
following.remove(userId);
}
public boolean isFollowing(String userId) {
return following.contains(userId);
}
}