Prevent empty or formatted strings from being parsed as a number.
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / engine / ReactionState.java
1 package net.pterodactylus.rhynodge.engine;
2
3 import java.util.Optional;
4
5 import net.pterodactylus.rhynodge.Reaction;
6 import net.pterodactylus.rhynodge.State;
7 import net.pterodactylus.rhynodge.states.StateManager;
8
9 /**
10  * Allows simple access to a {@link Reaction}’s saved states without exposing
11  * the key used to access the state on disk.
12  *
13  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
14  */
15 public class ReactionState {
16
17         private final StateManager stateManager;
18         private final String reactionName;
19
20         public ReactionState(StateManager stateManager, String reactionName) {
21                 this.stateManager = stateManager;
22                 this.reactionName = reactionName;
23         }
24
25         public Optional<State> loadLastState() {
26                 return stateManager.loadLastState(reactionName);
27         }
28
29         public Optional<State> loadLastSuccessfulState() {
30                 return stateManager.loadLastSuccessfulState(reactionName);
31         }
32
33         public void saveState(State state) {
34                 stateManager.saveState(reactionName, state);
35         }
36
37 }