From e3b775e6ff973b5ce45311c55b770b24cdc8229c Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Tue, 4 Apr 2023 15:39:40 -0700 Subject: [PATCH] refactor: haha eat rocks switch statement --- src/main/java/dev.toad/msg/MessageType.java | 38 ++++++++------------- 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/src/main/java/dev.toad/msg/MessageType.java b/src/main/java/dev.toad/msg/MessageType.java index a762ef0..619f318 100644 --- a/src/main/java/dev.toad/msg/MessageType.java +++ b/src/main/java/dev.toad/msg/MessageType.java @@ -9,32 +9,22 @@ public enum MessageType { private MessageType(int val) {} public String toString() { - switch (this) { - case CON: - return "CON"; - case NON: - return "NON"; - case ACK: - return "ACK"; - case RESET: - return "RESET"; - default: - throw new Error(); - } + return switch (this) { + case CON -> "CON"; + case NON -> "NON"; + case ACK -> "ACK"; + case RESET -> "RESET"; + default -> throw new Error(); + }; } public static MessageType fromString(String s) { - switch (s.toLowerCase().trim()) { - case "con": - return CON; - case "non": - return NON; - case "ack": - return ACK; - case "reset": - return RESET; - default: - throw new Error(); - } + return switch (s.toLowerCase().trim()) { + case "con" -> CON; + case "non" -> NON; + case "ack" -> ACK; + case "reset" -> RESET; + default -> throw new Error(); + }; } }