Skip to content

Commit 90584d5

Browse files
Document and improve speed
Memory reference checks instead of .equals because it's gonna be 100% safe
1 parent 0b7bdc8 commit 90584d5

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed
Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package me.flame.menus.menu;
22

33
import lombok.NonNull;
4+
import org.jetbrains.annotations.Contract;
5+
import org.jetbrains.annotations.NotNull;
46

5-
public class Result {
7+
@SuppressWarnings({ "unused", "StringEquality" })
8+
public final class Result {
69
public String result;
710
private static final String DENIED = "denied";
811
private static final String ALLOWED = "allowed";
@@ -14,29 +17,45 @@ private Result(String result) {
1417
public boolean equals(Object o) {
1518
if (!(o instanceof Result)) return false;
1619
Result r = (Result) o;
17-
return result.equals(r.result);
20+
return result == r.result;
1821
}
1922

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)
2030
public static Result denied() {
2131
return new Result(DENIED);
2232
}
2333

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)
2441
public static Result allowed() {
2542
return new Result(ALLOWED);
2643
}
2744

45+
/**
46+
* Sets the result of the operation.
47+
*
48+
* @param r the result to be set
49+
*/
2850
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-
"\nResult = " + result +
34-
"\nFix: Change the result to 'allowed' or 'denied'"
35-
);
36-
this.result = result;
51+
this.result = r.result;
3752
}
3853

3954
public boolean isDenied() {
40-
return result.equals(DENIED);
55+
return result == DENIED;
56+
}
57+
58+
public boolean isAllowed() {
59+
return result == ALLOWED;
4160
}
4261
}

0 commit comments

Comments
 (0)