53 lines
1.4 KiB
Java
53 lines
1.4 KiB
Java
package im.rosetta.network.enums;
|
|
|
|
// Auto-generated by RCC (Rosetta Code Compiler). Do not edit manually.
|
|
public enum ResultCode {
|
|
SUCCESS(0),
|
|
ERROR(1),
|
|
INVALID(2),
|
|
USERNAME_TAKEN(3);
|
|
|
|
private final Integer code;
|
|
|
|
ResultCode(Integer code) {
|
|
this.code = code;
|
|
}
|
|
|
|
public Integer getCode() {
|
|
return code;
|
|
}
|
|
|
|
public static ResultCode fromCode(int code) {
|
|
return switch (code) {
|
|
case 0 -> SUCCESS;
|
|
case 1 -> ERROR;
|
|
case 2 -> INVALID;
|
|
case 3 -> USERNAME_TAKEN;
|
|
default -> throw new IllegalArgumentException("Unknown ResultCode code: " + code);
|
|
};
|
|
}
|
|
|
|
public static ResultCode fromCode(int code, int version) {
|
|
ResultCode value = fromCode(code);
|
|
if (!value.isSupportedInVersion(version)) {
|
|
throw new IllegalArgumentException("Unsupported ResultCode code " + code + " for version " + version);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
public boolean isSupportedInVersion(int version) {
|
|
return switch (this) {
|
|
case SUCCESS -> true;
|
|
case ERROR -> true;
|
|
case INVALID -> true;
|
|
case USERNAME_TAKEN -> true;
|
|
};
|
|
}
|
|
|
|
public void requireSupportedInVersion(int version) {
|
|
if (!isSupportedInVersion(version)) {
|
|
throw new IllegalArgumentException("Unsupported ResultCode value " + this + " for version " + version);
|
|
}
|
|
}
|
|
}
|