Skip to content

Commit ea954d5

Browse files
authored
Merge pull request #77 from cjmang/main
Various QoL updates
2 parents 80b7941 + 76cf30e commit ea954d5

17 files changed

+453
-108
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package io.github.archipelagomw;
2+
3+
/**
4+
* Small container class for the outcome of client requests.
5+
* @param <T> The type of the data held
6+
*/
7+
public class APResult<T> {
8+
9+
public static enum ResultCode {
10+
SUCCESS,
11+
DISCONNECTED,
12+
UNAUTHENTICATED,
13+
OTHER_ERROR;
14+
}
15+
16+
private final ResultCode code;
17+
private final T value;
18+
19+
private APResult(ResultCode code) {
20+
this(code, null);
21+
}
22+
23+
private APResult(ResultCode code, T value) {
24+
this.code = code;
25+
this.value = value;
26+
}
27+
28+
public static <T> APResult<T> success() {
29+
return new APResult<>(ResultCode.SUCCESS);
30+
}
31+
32+
public static <T> APResult<T> success(T value) {
33+
return new APResult<>(ResultCode.SUCCESS, value);
34+
}
35+
36+
public static <T> APResult<T> disconnected() {
37+
return new APResult<>(ResultCode.DISCONNECTED);
38+
}
39+
40+
public static <T> APResult<T> unauthenticated() {
41+
return new APResult<>(ResultCode.UNAUTHENTICATED);
42+
}
43+
44+
public static <T> APResult<T> error() {
45+
return new APResult<>(ResultCode.OTHER_ERROR);
46+
}
47+
48+
public ResultCode getCode() {
49+
return code;
50+
}
51+
52+
public T getValue() {
53+
return value;
54+
}
55+
}

0 commit comments

Comments
 (0)