From b1df8d7753b5bee8ac0aca4dd343506deb05e818 Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Wed, 9 Oct 2024 23:41:44 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20findUpdateLogic=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EC=97=90=EC=84=9C=20contains()=EC=9D=98=20?= =?UTF-8?q?=EB=B0=98=EB=B3=B5=EB=90=9C=20=EC=BD=94=EB=93=9C=EB=A5=BC=20?= =?UTF-8?q?=EC=97=86=EC=95=A0=EA=B8=B0=20=EC=9C=84=ED=95=B4=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EC=97=90=20=ED=8F=AC=ED=95=A8=EB=90=9C=20item?= =?UTF-8?q?=EC=9D=98=20=EC=A2=85=EB=A5=98=EB=A5=BC=20=EB=A7=A4=ED=95=91?= =?UTF-8?q?=ED=95=B4=EC=A3=BC=EB=8A=94=20itemMap=EA=B3=BC=20=EB=B0=98?= =?UTF-8?q?=EB=B3=B5=EB=AC=B8=EC=9D=84=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=97=AC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../updateLogic/UpdateLogicFactory.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java index 535e3c1..894f353 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java @@ -7,9 +7,12 @@ public class UpdateLogicFactory { private final Map updateLogicMap; + private final Map itemMap; public UpdateLogicFactory() { updateLogicMap = new HashMap<>(); + itemMap = Map.ofEntries(Map.entry("Aged Brie", BRIE), Map.entry("Backstage passes", PASS), + Map.entry("Conjured", CONJURED), Map.entry("Sulfuras", SULFURAS)); updateLogicMap.put(BRIE, new BrieUpdateLogic()); updateLogicMap.put(PASS, new PassesUpdateLogic()); @@ -19,15 +22,11 @@ public UpdateLogicFactory() { } public UpdateLogic findUpdateLogic(String name) { - if (name.contains("Aged Brie")) { - return updateLogicMap.get(BRIE); - } else if (name.contains("Backstage passes")) { - return updateLogicMap.get(PASS); - } else if (name.contains("Conjured")) { - return updateLogicMap.get(CONJURED); - } else if (name.contains("Sulfuras")) { - return updateLogicMap.get(SULFURAS); - } else - return updateLogicMap.get(ELSE); + for (String key : itemMap.keySet()) { + if (name.contains(key)) { + return updateLogicMap.get(itemMap.get(key)); + } + } + return updateLogicMap.get(ELSE); } }