refactor: haha eat rocks switch statement

This commit is contained in:
Orion Kindel 2023-04-04 15:39:40 -07:00
parent 36f708b514
commit e3b775e6ff
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719

View File

@ -9,32 +9,22 @@ public enum MessageType {
private MessageType(int val) {} private MessageType(int val) {}
public String toString() { public String toString() {
switch (this) { return switch (this) {
case CON: case CON -> "CON";
return "CON"; case NON -> "NON";
case NON: case ACK -> "ACK";
return "NON"; case RESET -> "RESET";
case ACK: default -> throw new Error();
return "ACK"; };
case RESET:
return "RESET";
default:
throw new Error();
}
} }
public static MessageType fromString(String s) { public static MessageType fromString(String s) {
switch (s.toLowerCase().trim()) { return switch (s.toLowerCase().trim()) {
case "con": case "con" -> CON;
return CON; case "non" -> NON;
case "non": case "ack" -> ACK;
return NON; case "reset" -> RESET;
case "ack": default -> throw new Error();
return ACK; };
case "reset":
return RESET;
default:
throw new Error();
}
} }
} }