Skip to content

Commit fbf6b6f

Browse files
committed
refactoring, add OpenGame to UserStatus
1 parent 5c068e1 commit fbf6b6f

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

src/main/java/com/bernd/model/UserStatus.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,62 @@
22

33
public record UserStatus(
44
String room,
5-
long lastSeen) {
5+
long lastSeen,
6+
OpenGame openGame) {
67

8+
// max interval between heartbeats
79
private static final long USER_TIMEOUT = 45 * 1000;
810

911
public static UserStatus create(String room) {
10-
return new UserStatus(room, System.currentTimeMillis());
12+
return new UserStatus(
13+
room,
14+
System.currentTimeMillis(),
15+
null);
1116
}
1217

1318
public UserStatus touch() {
14-
return new UserStatus(room, System.currentTimeMillis());
19+
return toBuilder().lastSeen(System.currentTimeMillis()).build();
1520
}
1621

1722
public boolean isActive(long current) {
1823
return current < lastSeen + USER_TIMEOUT;
1924
}
25+
26+
public Builder toBuilder() {
27+
return new Builder(room, lastSeen, openGame);
28+
}
29+
30+
public static final class Builder {
31+
private String room;
32+
private long lastSeen;
33+
private OpenGame openGame;
34+
35+
private Builder(
36+
String room,
37+
long lastSeen,
38+
OpenGame openGame) {
39+
this.room = room;
40+
this.lastSeen = lastSeen;
41+
this.openGame = openGame;
42+
}
43+
44+
public Builder room(String room) {
45+
this.room = room;
46+
return this;
47+
}
48+
49+
public Builder lastSeen(long lastSeen) {
50+
this.lastSeen = lastSeen;
51+
return this;
52+
}
53+
54+
public Builder openGame(OpenGame openGame) {
55+
this.openGame = openGame;
56+
return this;
57+
}
58+
59+
public UserStatus build() {
60+
return new UserStatus(room, lastSeen, openGame);
61+
}
62+
}
2063
}

0 commit comments

Comments
 (0)