forked from aws-samples/eb-java-scorekeep
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateFactory.java
More file actions
29 lines (24 loc) · 1.04 KB
/
StateFactory.java
File metadata and controls
29 lines (24 loc) · 1.04 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
package scorekeep;
import java.util.*;
import java.security.SecureRandom;
import java.math.BigInteger;
import java.lang.Exception;
public class StateFactory {
private SecureRandom random = new SecureRandom();
private final HashMap<String, State> allStates = new HashMap<String, State>(1);
private StateModel model = new StateModel();
public StateFactory(){
}
public State newState(String sessionId, String gameId, String stateText, Set<String> turn) throws SessionNotFoundException, GameNotFoundException {
String id = new BigInteger(40, random).toString(32).toUpperCase();
State state = new State(id, sessionId, gameId, stateText, turn);
model.saveState(state);
return state;
}
public State getState(String sessionId, String gameId, String stateId) throws SessionNotFoundException, StateNotFoundException {
return model.loadState(stateId);
}
public List<State> getStates(String sessionId, String gameId) throws SessionNotFoundException, GameNotFoundException {
return model.loadStates(sessionId, gameId);
}
}