-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathTriState.java
More file actions
50 lines (42 loc) · 1.11 KB
/
TriState.java
File metadata and controls
50 lines (42 loc) · 1.11 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package net.modificationstation.stationapi.api.util;
public enum TriState {
@API
TRUE(true),
@API
FALSE(false),
@API
UNSET(null);
TriState(Boolean value) {
this.value = value;
}
@API
public static TriState fromBool(boolean b) {
return b ? TRUE : FALSE;
}
@API
public static TriState fromBoolObj(Boolean b) {
return b == null ? UNSET : fromBool(b);
}
@API
public Boolean getBoolObj() {
return value;
}
/**
* Gets the value of this tri-state.
* If the value is {@link TriState#UNSET} then use the supplied value.
*
* @param value the value to fall back to
* @return the value of the tri-state or the supplied value if {@link TriState#UNSET}.
*/
public boolean orElse(boolean value) {
return this == UNSET ? value : this.getBool();
}
@API
public boolean getBool() {
Boolean b = getBoolObj();
if (b == null)
throw new UnsupportedOperationException("Can't convert " + this + " to boolean!");
return b;
}
private final Boolean value;
}