-
Notifications
You must be signed in to change notification settings - Fork 18
/
TemperaturePredicate.java
53 lines (46 loc) · 1.18 KB
/
TemperaturePredicate.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
48
49
50
51
52
53
package knightminer.inspirations.library.recipe.cauldron.util;
import javax.annotation.Nullable;
import java.util.Locale;
import java.util.function.Predicate;
/**
* Predicate to check cauldron boiling state
*/
public enum TemperaturePredicate implements Predicate<Boolean> {
ANY,
HOT,
COLD;
private final String name = name().toLowerCase(Locale.US);
/**
* Checks if this matches the given boiling predicate
* @param boiling Boiling type to match
* @return True if this type matches the given boiling state
*/
public boolean test(boolean boiling) {
return this == ANY || this == (boiling ? HOT : COLD);
}
@Override
public boolean test(Boolean bool) {
return test(bool == Boolean.TRUE);
}
/**
* Gets the name of this type
* @return Type name
*/
public String getName() {
return name;
}
/**
* Gets a predicate for the given name
* @param name Name to check
* @return Value, or null if missing
*/
@Nullable
public static TemperaturePredicate byName(String name) {
for (TemperaturePredicate boiling : values()) {
if (boiling.getName().equals(name)) {
return boiling;
}
}
return null;
}
}