1
1
package me .flame .menus .menu ;
2
2
3
3
import lombok .NonNull ;
4
+ import org .jetbrains .annotations .Contract ;
5
+ import org .jetbrains .annotations .NotNull ;
4
6
5
- public class Result {
7
+ @ SuppressWarnings ({ "unused" , "StringEquality" })
8
+ public final class Result {
6
9
public String result ;
7
10
private static final String DENIED = "denied" ;
8
11
private static final String ALLOWED = "allowed" ;
@@ -14,29 +17,45 @@ private Result(String result) {
14
17
public boolean equals (Object o ) {
15
18
if (!(o instanceof Result )) return false ;
16
19
Result r = (Result ) o ;
17
- return result . equals ( r .result ) ;
20
+ return result == r .result ;
18
21
}
19
22
23
+ /**
24
+ * Generates a new Result object with the value DENIED.
25
+ *
26
+ * @return A new Result object with the value DENIED.
27
+ */
28
+ @ NotNull
29
+ @ Contract (value = " -> new" , pure = true )
20
30
public static Result denied () {
21
31
return new Result (DENIED );
22
32
}
23
33
34
+ /**
35
+ * Generates a new Result object with the value ALLOWED.
36
+ *
37
+ * @return A new Result object with the value ALLOWED.
38
+ */
39
+ @ NotNull
40
+ @ Contract (value = " -> new" , pure = true )
24
41
public static Result allowed () {
25
42
return new Result (ALLOWED );
26
43
}
27
44
45
+ /**
46
+ * Sets the result of the operation.
47
+ *
48
+ * @param r the result to be set
49
+ */
28
50
public void set (@ NonNull Result r ) {
29
- String result = r .result ;
30
- if (!result .equals (DENIED ) && !result .equals (ALLOWED ))
31
- throw new IllegalArgumentException (
32
- "Must be 'allowed' or 'denied'" +
33
- "\n Result = " + result +
34
- "\n Fix: Change the result to 'allowed' or 'denied'"
35
- );
36
- this .result = result ;
51
+ this .result = r .result ;
37
52
}
38
53
39
54
public boolean isDenied () {
40
- return result .equals (DENIED );
55
+ return result == DENIED ;
56
+ }
57
+
58
+ public boolean isAllowed () {
59
+ return result == ALLOWED ;
41
60
}
42
61
}
0 commit comments