From 2ccca35585d313ac1d90ce812e87cb62a1dc6232 Mon Sep 17 00:00:00 2001 From: Nikolaos Grammatikos Date: Fri, 30 Aug 2024 10:29:50 +0100 Subject: [PATCH] Refactor switch statements and simplify typecasting. Refactored multiple switch statements to use the enhanced switch syntax for better readability and simplicity. Simplified typecasting by combining the instanceof check and cast into a single statement. --- src/main/java/org/gestern/gringotts/Util.java | 35 +++++-------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/gestern/gringotts/Util.java b/src/main/java/org/gestern/gringotts/Util.java index 6f13457..138d4d1 100644 --- a/src/main/java/org/gestern/gringotts/Util.java +++ b/src/main/java/org/gestern/gringotts/Util.java @@ -168,11 +168,10 @@ public static Block chestBlock(Sign sign) { Block signBlock = sign.getBlock(); BlockData blockData = signBlock.getBlockData(); - if (!(blockData instanceof WallSign)) { + if (!(blockData instanceof WallSign signData)) { return null; } - WallSign signData = (WallSign) blockData; BlockFace attached = signData.getFacing().getOppositeFace(); // allow either the block sign is attached to or the block below the sign as @@ -197,18 +196,10 @@ public static boolean isValidContainer(Material material) { return false; } - switch (material) { - case CHEST: - case TRAPPED_CHEST: - case DISPENSER: - case FURNACE: - case HOPPER: - case DROPPER: - case BARREL: - return true; - default: - return false; - } + return switch (material) { + case CHEST, TRAPPED_CHEST, DISPENSER, FURNACE, HOPPER, DROPPER, BARREL -> true; + default -> false; + }; } /** @@ -218,18 +209,10 @@ public static boolean isValidContainer(Material material) { * @return whether the given inventory type is valid for Gringotts */ public static boolean isValidInventory(InventoryType inventory) { - - switch (inventory) { - case CHEST: - case DISPENSER: - case FURNACE: - case HOPPER: - case DROPPER: - case BARREL: - return true; - default: - return false; - } + return switch (inventory) { + case CHEST, DISPENSER, FURNACE, HOPPER, DROPPER, BARREL -> true; + default -> false; + }; } /**