Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/main/java/io/github/archipelagomw/APResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.github.archipelagomw;

/**
* Small container class for the outcome of client requests.
* @param <T> The type of the data held
*/
public class APResult<T> {

public static enum ResultCode {
SUCCESS,
DISCONNECTED,
UNAUTHENTICATED,
OTHER_ERROR;
}

private final ResultCode code;
private final T value;

private APResult(ResultCode code) {
this(code, null);
}

private APResult(ResultCode code, T value) {
this.code = code;
this.value = value;
}

public static <T> APResult<T> success() {
return new APResult<>(ResultCode.SUCCESS);
}

public static <T> APResult<T> success(T value) {
return new APResult<>(ResultCode.SUCCESS, value);
}

public static <T> APResult<T> disconnected() {
return new APResult<>(ResultCode.DISCONNECTED);
}

public static <T> APResult<T> unauthenticated() {
return new APResult<>(ResultCode.UNAUTHENTICATED);
}

public static <T> APResult<T> error() {
return new APResult<>(ResultCode.OTHER_ERROR);
}

public ResultCode getCode() {
return code;
}

public T getValue() {
return value;
}
}
Loading