forked from CS2113-AY1819S1-F10-3/main
-
Notifications
You must be signed in to change notification settings - Fork 0
/
State.java
47 lines (36 loc) · 1.42 KB
/
State.java
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
package seedu.addressbook.data.PoliceOfficers;
import seedu.addressbook.data.exception.IllegalValueException;
/**
* Represents a Patrol resource's current state in EX-SI-53.
* Guarantees: only 2 possible states; is valid as declared in {@link #isValidState(String)}
*/
public class State {
public static final String EXAMPLE_STATE = "free";
public static final String MESSAGE_STATE_CONSTRAINTS = "Patrol resource can either be 'free' or 'engaged'";
public static final String FREE = "free";
public static final String ENGAGED = "engaged";
public static final String DEFAULT_CASE = "none";
public String currentState;
public State(String state) throws IllegalValueException{
state = state.trim();
if (!isValidState(state)){
throw new IllegalValueException(MESSAGE_STATE_CONSTRAINTS);
}
this.currentState = state;
}
public boolean isValidState(String test) {return test == FREE || test == ENGAGED;}
@Override
public String toString() {
return currentState;
}
@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof PatrolID // instanceof handles nulls
&& this.currentState.equals(((State) other).currentState)); // state check
}
@Override
public int hashCode() {
return currentState.hashCode();
}
}