From 1e838456794fcc1bc628a690227c4645a9e4c472 Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Sun, 22 Sep 2024 20:20:05 +0900 Subject: [PATCH 01/16] =?UTF-8?q?[FEAT]=20UpdateLogic=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/gildedrose/GildedRose.java | 57 +++---------------- .../updateLogic/BrieUpdateLogic.java | 15 +++++ .../updateLogic/ConjuredUpdateLogic.java | 15 +++++ .../updateLogic/ElseUpdateLogic.java | 15 +++++ .../updateLogic/PassesUpdateLogic.java | 23 ++++++++ .../updateLogic/SulfurasUpdateLogic.java | 10 ++++ .../gildedrose/updateLogic/UpdateLogic.java | 7 +++ .../gildedrose/updateLogic/UpdateLogics.java | 30 ++++++++++ .../java/com/gildedrose/GildedRoseTest.java | 17 ------ 9 files changed, 123 insertions(+), 66 deletions(-) create mode 100644 Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java create mode 100644 Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java create mode 100644 Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java create mode 100644 Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java create mode 100644 Java/src/main/java/com/gildedrose/updateLogic/SulfurasUpdateLogic.java create mode 100644 Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java create mode 100644 Java/src/main/java/com/gildedrose/updateLogic/UpdateLogics.java delete mode 100644 Java/src/test/java/com/gildedrose/GildedRoseTest.java diff --git a/Java/src/main/java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java index 87a3b92..65d7d9f 100644 --- a/Java/src/main/java/com/gildedrose/GildedRose.java +++ b/Java/src/main/java/com/gildedrose/GildedRose.java @@ -1,62 +1,21 @@ package com.gildedrose; +import com.gildedrose.updateLogic.UpdateLogic; +import com.gildedrose.updateLogic.UpdateLogics; + class GildedRose { Item[] items; + UpdateLogics updateLogics; public GildedRose(Item[] items) { this.items = items; + this.updateLogics = new UpdateLogics(); } public void updateQuality() { - for (int i = 0; i < items.length; i++) { - if (!items[i].name.equals("Aged Brie") - && !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { - if (items[i].quality > 0) { - if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { - items[i].quality = items[i].quality - 1; - } - } - } else { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; - - if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { - if (items[i].sellIn < 11) { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; - } - } - - if (items[i].sellIn < 6) { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; - } - } - } - } - } - - if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { - items[i].sellIn = items[i].sellIn - 1; - } - - if (items[i].sellIn < 0) { - if (!items[i].name.equals("Aged Brie")) { - if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { - if (items[i].quality > 0) { - if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { - items[i].quality = items[i].quality - 1; - } - } - } else { - items[i].quality = items[i].quality - items[i].quality; - } - } else { - if (items[i].quality < 50) { - items[i].quality = items[i].quality + 1; - } - } - } + for (Item item : items){ + UpdateLogic updateLogic = updateLogics.findUpdateLogic(item.name); + updateLogic.update(item); } } } diff --git a/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java new file mode 100644 index 0000000..2d7fdbd --- /dev/null +++ b/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java @@ -0,0 +1,15 @@ +package com.gildedrose.updateLogic; + +import com.gildedrose.Item; + +public class BrieUpdateLogic implements UpdateLogic { + @Override + public void update(Item item) { + item.sellIn -= 1; + item.quality = item.quality < 50 ? item.quality + 1 : 50; + + if (item.sellIn < 0) { + item.quality = item.quality < 50 ? item.quality + 1 : 50; + } + } +} diff --git a/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java new file mode 100644 index 0000000..4382984 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java @@ -0,0 +1,15 @@ +package com.gildedrose.updateLogic; + +import com.gildedrose.Item; + +public class ConjuredUpdateLogic implements UpdateLogic { + @Override + public void update(Item item) { + item.sellIn -= 1; + item.quality = item.quality >= 2 ? item.quality - 2 : 0; + + if (item.sellIn < 0) { + item.quality = item.quality > 0 ? item.quality - 2 : 0; + } + } +} diff --git a/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java new file mode 100644 index 0000000..a514833 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java @@ -0,0 +1,15 @@ +package com.gildedrose.updateLogic; + +import com.gildedrose.Item; + +public class ElseUpdateLogic implements UpdateLogic { + @Override + public void update(Item item) { + item.sellIn -= 1; + item.quality = item.quality > 0 ? item.quality - 1 : 0; + + if (item.sellIn < 0) { + item.quality = item.quality > 0 ? item.quality - 1 : 0; + } + } +} diff --git a/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java new file mode 100644 index 0000000..debbe27 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java @@ -0,0 +1,23 @@ +package com.gildedrose.updateLogic; + +import com.gildedrose.Item; + +public class PassesUpdateLogic implements UpdateLogic { + @Override + public void update(Item item) { + item.sellIn -= 1; + item.quality = item.quality < 50 ? item.quality + 1 : 50; + + if (item.sellIn <= 10) { + item.quality = item.quality < 50 ? item.quality + 1 : 50; + } + + if (item.sellIn <= 5) { + item.quality = item.quality < 50 ? item.quality + 1 : 50; + } + + if (item.sellIn < 0) { + item.quality = 0; + } + } +} diff --git a/Java/src/main/java/com/gildedrose/updateLogic/SulfurasUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/SulfurasUpdateLogic.java new file mode 100644 index 0000000..5db66e0 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/updateLogic/SulfurasUpdateLogic.java @@ -0,0 +1,10 @@ +package com.gildedrose.updateLogic; + +import com.gildedrose.Item; + +public class SulfurasUpdateLogic implements UpdateLogic { + @Override + public void update(Item item) { + + } +} diff --git a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java new file mode 100644 index 0000000..2a6e9bf --- /dev/null +++ b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java @@ -0,0 +1,7 @@ +package com.gildedrose.updateLogic; + +import com.gildedrose.Item; + +public interface UpdateLogic { + public void update(Item item); +} diff --git a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogics.java b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogics.java new file mode 100644 index 0000000..df146b8 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogics.java @@ -0,0 +1,30 @@ +package com.gildedrose.updateLogic; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class UpdateLogics { + private final Map updateLogicMap; + private final List filters = Arrays.asList("Aged Brie", "Backstage passes", "Conjured", "Sulfuras"); + + public UpdateLogics() { + updateLogicMap = new HashMap<>(); + + updateLogicMap.put("Aged Brie", new BrieUpdateLogic()); + updateLogicMap.put("Backstage passes", new PassesUpdateLogic()); + updateLogicMap.put("Conjured", new ConjuredUpdateLogic()); + updateLogicMap.put("Sulfuras", new SulfurasUpdateLogic()); + updateLogicMap.put(null, new ElseUpdateLogic()); + } + + public UpdateLogic findUpdateLogic(String name) { + for (String filter : filters) { + if (name.contains(filter)) { + return updateLogicMap.get(filter); + } + } + return updateLogicMap.get(null); + } +} diff --git a/Java/src/test/java/com/gildedrose/GildedRoseTest.java b/Java/src/test/java/com/gildedrose/GildedRoseTest.java deleted file mode 100644 index 8ae29ee..0000000 --- a/Java/src/test/java/com/gildedrose/GildedRoseTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.gildedrose; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class GildedRoseTest { - - @Test - void foo() { - Item[] items = new Item[] { new Item("foo", 0, 0) }; - GildedRose app = new GildedRose(items); - app.updateQuality(); - assertEquals("fixme", app.items[0].name); - } - -} From 98b165eab472431a6254d82ffa2d7fbf84fc6e3d Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Sun, 22 Sep 2024 20:32:33 +0900 Subject: [PATCH 02/16] =?UTF-8?q?[TEST]=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gildedrose/TexttestFixture.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Java/src/test/java/com/gildedrose/TexttestFixture.java b/Java/src/test/java/com/gildedrose/TexttestFixture.java index d059c88..d4a66c8 100644 --- a/Java/src/test/java/com/gildedrose/TexttestFixture.java +++ b/Java/src/test/java/com/gildedrose/TexttestFixture.java @@ -5,16 +5,17 @@ public static void main(String[] args) { System.out.println("OMGHAI!"); Item[] items = new Item[] { - new Item("+5 Dexterity Vest", 10, 20), // - new Item("Aged Brie", 2, 0), // - new Item("Elixir of the Mongoose", 5, 7), // - new Item("Sulfuras, Hand of Ragnaros", 0, 80), // - new Item("Sulfuras, Hand of Ragnaros", -1, 80), - new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), - new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), - new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), - // this conjured item does not work properly yet - new Item("Conjured Mana Cake", 3, 6) }; + new Item("+5 Dexterity Vest", 10, 20), // + new Item("Aged Brie", 2, 0), // + new Item("Elixir of the Mongoose", 5, 7), // + new Item("Sulfuras, Hand of Ragnaros", 0, 80), // + new Item("Sulfuras, Hand of Ragnaros", -1, 80), + new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), + new Item("Backstage passes to a TAFKAL80ETC concert", 11, 40), + new Item("Backstage passes to a TAFKAL80ETC concert", 6, 40), + new Item("Backstage passes to a TAFKAL80ETC concert", 0, 40), + // this conjured item does not work properly yet + new Item("Conjured Mana Cake", 3, 6)}; GildedRose app = new GildedRose(items); From 6ab9c93edbcf6e18186bc3b71b6ce0159e3faf23 Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Sat, 5 Oct 2024 20:15:08 +0900 Subject: [PATCH 03/16] =?UTF-8?q?refactor:=20UpdateLogic=EC=97=90=20decrea?= =?UTF-8?q?seSellIn=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=ED=95=98=EC=97=AC=20=EC=A4=91=EB=B3=B5=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EB=8C=80=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gildedrose/updateLogic/BrieUpdateLogic.java | 5 +++-- .../com/gildedrose/updateLogic/ConjuredUpdateLogic.java | 5 +++-- .../java/com/gildedrose/updateLogic/ElseUpdateLogic.java | 5 +++-- .../com/gildedrose/updateLogic/PassesUpdateLogic.java | 5 +++-- .../com/gildedrose/updateLogic/SulfurasUpdateLogic.java | 2 +- .../main/java/com/gildedrose/updateLogic/UpdateLogic.java | 8 ++++++-- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java index 2d7fdbd..7ac2482 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java @@ -2,10 +2,11 @@ import com.gildedrose.Item; -public class BrieUpdateLogic implements UpdateLogic { +public class BrieUpdateLogic extends UpdateLogic { @Override public void update(Item item) { - item.sellIn -= 1; + decreaseSellIn(item); + item.quality = item.quality < 50 ? item.quality + 1 : 50; if (item.sellIn < 0) { diff --git a/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java index 4382984..b799fda 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java @@ -2,10 +2,11 @@ import com.gildedrose.Item; -public class ConjuredUpdateLogic implements UpdateLogic { +public class ConjuredUpdateLogic extends UpdateLogic { @Override public void update(Item item) { - item.sellIn -= 1; + decreaseSellIn(item); + item.quality = item.quality >= 2 ? item.quality - 2 : 0; if (item.sellIn < 0) { diff --git a/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java index a514833..d041477 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java @@ -2,10 +2,11 @@ import com.gildedrose.Item; -public class ElseUpdateLogic implements UpdateLogic { +public class ElseUpdateLogic extends UpdateLogic { @Override public void update(Item item) { - item.sellIn -= 1; + decreaseSellIn(item); + item.quality = item.quality > 0 ? item.quality - 1 : 0; if (item.sellIn < 0) { diff --git a/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java index debbe27..5a99109 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java @@ -2,10 +2,11 @@ import com.gildedrose.Item; -public class PassesUpdateLogic implements UpdateLogic { +public class PassesUpdateLogic extends UpdateLogic { @Override public void update(Item item) { - item.sellIn -= 1; + decreaseSellIn(item); + item.quality = item.quality < 50 ? item.quality + 1 : 50; if (item.sellIn <= 10) { diff --git a/Java/src/main/java/com/gildedrose/updateLogic/SulfurasUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/SulfurasUpdateLogic.java index 5db66e0..e17e393 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/SulfurasUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/SulfurasUpdateLogic.java @@ -2,7 +2,7 @@ import com.gildedrose.Item; -public class SulfurasUpdateLogic implements UpdateLogic { +public class SulfurasUpdateLogic extends UpdateLogic { @Override public void update(Item item) { diff --git a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java index 2a6e9bf..956743d 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java @@ -2,6 +2,10 @@ import com.gildedrose.Item; -public interface UpdateLogic { - public void update(Item item); +public abstract class UpdateLogic { + protected void decreaseSellIn(Item item) { + item.sellIn -= 1; + } + + public abstract void update(Item item); } From ca7ae3407353253607ebfcd7d5c9dbf9cc676e26 Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Sat, 5 Oct 2024 20:46:09 +0900 Subject: [PATCH 04/16] =?UTF-8?q?refactor:=20UpdateLogic=EC=97=90=EC=84=9C?= =?UTF-8?q?=20=EA=B3=A0=EC=A0=95=20=EB=B3=80=EC=88=98=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EB=B0=8F=20=EC=A6=9D=EA=B0=80,=20=EA=B0=90=EC=86=8C=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gildedrose/updateLogic/UpdateLogic.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java index 956743d..0abc8bf 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java @@ -3,9 +3,25 @@ import com.gildedrose.Item; public abstract class UpdateLogic { + public static final int MAX_QUALITY = 50; + public static final int MIN_QUALITY = 0; + public static final int DOWN_MULTIPLE = 2; + protected void decreaseSellIn(Item item) { item.sellIn -= 1; } + protected void decreaseQuality(Item item, int downAmount) { + if (item.sellIn < 0) { + item.quality = Math.max(item.quality - downAmount * DOWN_MULTIPLE, MIN_QUALITY); + } else { + item.quality = Math.max(item.quality - downAmount, MIN_QUALITY); + } + } + + protected void increaseQuality(Item item) { + item.quality = Math.min(item.quality + 1, MAX_QUALITY); + } + public abstract void update(Item item); } From d78530cce2fc86575826a78947c8eb2f2fc4a762 Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Sat, 5 Oct 2024 21:05:02 +0900 Subject: [PATCH 05/16] =?UTF-8?q?refactor:=20UpdateLogic=EC=9D=98=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EC=9E=90=EC=8B=9D=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../updateLogic/BrieUpdateLogic.java | 6 +++--- .../updateLogic/ConjuredUpdateLogic.java | 8 ++------ .../updateLogic/ElseUpdateLogic.java | 6 +----- .../updateLogic/PassesUpdateLogic.java | 19 ++++++++----------- .../gildedrose/updateLogic/UpdateLogic.java | 14 +++++++++----- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java index 7ac2482..302dba3 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java @@ -6,11 +6,11 @@ public class BrieUpdateLogic extends UpdateLogic { @Override public void update(Item item) { decreaseSellIn(item); - - item.quality = item.quality < 50 ? item.quality + 1 : 50; if (item.sellIn < 0) { - item.quality = item.quality < 50 ? item.quality + 1 : 50; + increaseQuality(item, 2); + } else { + increaseQuality(item, 1); } } } diff --git a/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java index b799fda..7e57e97 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java @@ -6,11 +6,7 @@ public class ConjuredUpdateLogic extends UpdateLogic { @Override public void update(Item item) { decreaseSellIn(item); - - item.quality = item.quality >= 2 ? item.quality - 2 : 0; - - if (item.sellIn < 0) { - item.quality = item.quality > 0 ? item.quality - 2 : 0; - } + + decreaseQuality(item, 2); } } diff --git a/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java index d041477..cc52910 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java @@ -6,11 +6,7 @@ public class ElseUpdateLogic extends UpdateLogic { @Override public void update(Item item) { decreaseSellIn(item); - - item.quality = item.quality > 0 ? item.quality - 1 : 0; - if (item.sellIn < 0) { - item.quality = item.quality > 0 ? item.quality - 1 : 0; - } + decreaseQuality(item, 1); } } diff --git a/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java index 5a99109..b9a3e94 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java @@ -6,19 +6,16 @@ public class PassesUpdateLogic extends UpdateLogic { @Override public void update(Item item) { decreaseSellIn(item); - - item.quality = item.quality < 50 ? item.quality + 1 : 50; - - if (item.sellIn <= 10) { - item.quality = item.quality < 50 ? item.quality + 1 : 50; - } - - if (item.sellIn <= 5) { - item.quality = item.quality < 50 ? item.quality + 1 : 50; - } if (item.sellIn < 0) { - item.quality = 0; + resetQuality(item); + } else if (item.sellIn <= 5) { + increaseQuality(item, 3); + } else if (item.sellIn <= 10) { + increaseQuality(item, 2); + } else { + increaseQuality(item, 1); } + } } diff --git a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java index 0abc8bf..9fc0477 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java @@ -11,16 +11,20 @@ protected void decreaseSellIn(Item item) { item.sellIn -= 1; } - protected void decreaseQuality(Item item, int downAmount) { + protected void decreaseQuality(Item item, int decreaseAmount) { if (item.sellIn < 0) { - item.quality = Math.max(item.quality - downAmount * DOWN_MULTIPLE, MIN_QUALITY); + item.quality = Math.max(item.quality - decreaseAmount * DOWN_MULTIPLE, MIN_QUALITY); } else { - item.quality = Math.max(item.quality - downAmount, MIN_QUALITY); + item.quality = Math.max(item.quality - decreaseAmount, MIN_QUALITY); } } - protected void increaseQuality(Item item) { - item.quality = Math.min(item.quality + 1, MAX_QUALITY); + protected void increaseQuality(Item item, int increaseAmount) { + item.quality = Math.min(item.quality + increaseAmount, MAX_QUALITY); + } + + protected void resetQuality(Item item) { + item.quality = 0; } public abstract void update(Item item); From f2504b01be99e78ca732f0754eb564278f351d00 Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Sat, 5 Oct 2024 21:11:47 +0900 Subject: [PATCH 06/16] =?UTF-8?q?style:=20UpdateLogics=EB=A5=BC=20UpdateLo?= =?UTF-8?q?gicFactory=EB=A1=9C=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Java/src/main/java/com/gildedrose/GildedRose.java | 8 ++++---- .../{UpdateLogics.java => UpdateLogicFactory.java} | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) rename Java/src/main/java/com/gildedrose/updateLogic/{UpdateLogics.java => UpdateLogicFactory.java} (93%) diff --git a/Java/src/main/java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java index 65d7d9f..801daf3 100644 --- a/Java/src/main/java/com/gildedrose/GildedRose.java +++ b/Java/src/main/java/com/gildedrose/GildedRose.java @@ -1,19 +1,19 @@ package com.gildedrose; import com.gildedrose.updateLogic.UpdateLogic; -import com.gildedrose.updateLogic.UpdateLogics; +import com.gildedrose.updateLogic.UpdateLogicFactory; class GildedRose { Item[] items; - UpdateLogics updateLogics; + UpdateLogicFactory updateLogics; public GildedRose(Item[] items) { this.items = items; - this.updateLogics = new UpdateLogics(); + this.updateLogics = new UpdateLogicFactory(); } public void updateQuality() { - for (Item item : items){ + for (Item item : items) { UpdateLogic updateLogic = updateLogics.findUpdateLogic(item.name); updateLogic.update(item); } diff --git a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogics.java b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java similarity index 93% rename from Java/src/main/java/com/gildedrose/updateLogic/UpdateLogics.java rename to Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java index df146b8..0c24df7 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogics.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java @@ -5,11 +5,11 @@ import java.util.List; import java.util.Map; -public class UpdateLogics { +public class UpdateLogicFactory { private final Map updateLogicMap; private final List filters = Arrays.asList("Aged Brie", "Backstage passes", "Conjured", "Sulfuras"); - public UpdateLogics() { + public UpdateLogicFactory() { updateLogicMap = new HashMap<>(); updateLogicMap.put("Aged Brie", new BrieUpdateLogic()); From efdebf4eec4603adaaf756a497ff9c592f37a6d5 Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Sat, 5 Oct 2024 21:23:14 +0900 Subject: [PATCH 07/16] =?UTF-8?q?feat:=20=EC=95=84=EC=9D=B4=ED=85=9C?= =?UTF-8?q?=EC=9D=98=20=EC=A2=85=EB=A5=98=EB=A5=BC=20=EA=B5=AC=EB=B6=84?= =?UTF-8?q?=ED=95=98=EB=8A=94=20ItemCategory=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/gildedrose/updateLogic/ItemCategory.java | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java diff --git a/Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java b/Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java new file mode 100644 index 0000000..a6f40d8 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java @@ -0,0 +1,5 @@ +package com.gildedrose.updateLogic; + +public enum ItemCategory { + BRIE, PASS, CONJURED, SULFURAS, ELSE +} From a242d08299f3dc8df501e4ece007cd542551b571 Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Sat, 5 Oct 2024 22:02:25 +0900 Subject: [PATCH 08/16] =?UTF-8?q?refactor:=20UpdateLogicFactory=EC=97=90?= =?UTF-8?q?=EC=84=9C=20Enum=20=EC=82=AC=EC=9A=A9=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=8C=80=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../updateLogic/UpdateLogicFactory.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java index 0c24df7..535e3c1 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java @@ -1,30 +1,33 @@ package com.gildedrose.updateLogic; -import java.util.Arrays; +import static com.gildedrose.updateLogic.ItemCategory.*; + import java.util.HashMap; -import java.util.List; import java.util.Map; public class UpdateLogicFactory { - private final Map updateLogicMap; - private final List filters = Arrays.asList("Aged Brie", "Backstage passes", "Conjured", "Sulfuras"); + private final Map updateLogicMap; public UpdateLogicFactory() { updateLogicMap = new HashMap<>(); - updateLogicMap.put("Aged Brie", new BrieUpdateLogic()); - updateLogicMap.put("Backstage passes", new PassesUpdateLogic()); - updateLogicMap.put("Conjured", new ConjuredUpdateLogic()); - updateLogicMap.put("Sulfuras", new SulfurasUpdateLogic()); - updateLogicMap.put(null, new ElseUpdateLogic()); + updateLogicMap.put(BRIE, new BrieUpdateLogic()); + updateLogicMap.put(PASS, new PassesUpdateLogic()); + updateLogicMap.put(CONJURED, new ConjuredUpdateLogic()); + updateLogicMap.put(SULFURAS, new SulfurasUpdateLogic()); + updateLogicMap.put(ELSE, new ElseUpdateLogic()); } public UpdateLogic findUpdateLogic(String name) { - for (String filter : filters) { - if (name.contains(filter)) { - return updateLogicMap.get(filter); - } - } - return updateLogicMap.get(null); + 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); } } From b1df8d7753b5bee8ac0aca4dd343506deb05e818 Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Wed, 9 Oct 2024 23:41:44 +0900 Subject: [PATCH 09/16] =?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); } } From 328220d2080a1dd46f9354479a0c399829cd00e0 Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Thu, 10 Oct 2024 23:46:06 +0900 Subject: [PATCH 10/16] =?UTF-8?q?refactor:=20=EC=83=81=EC=88=98=20?= =?UTF-8?q?=EC=A0=91=EA=B7=BC=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/gildedrose/updateLogic/UpdateLogic.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java index 9fc0477..4ffd88d 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java @@ -3,9 +3,9 @@ import com.gildedrose.Item; public abstract class UpdateLogic { - public static final int MAX_QUALITY = 50; - public static final int MIN_QUALITY = 0; - public static final int DOWN_MULTIPLE = 2; + private static final int MAX_QUALITY = 50; + private static final int MIN_QUALITY = 0; + private static final int DOWN_MULTIPLE = 2; protected void decreaseSellIn(Item item) { item.sellIn -= 1; From ec060c15698e70486a3e8807814ace90d17bda9d Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Wed, 30 Oct 2024 20:51:42 +0900 Subject: [PATCH 11/16] =?UTF-8?q?feat:=20=EC=A0=9C=EC=95=BD=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EB=B0=8F=20=EB=A7=A4=EC=A7=81=EB=84=98=EB=B2=84?= =?UTF-8?q?=EB=A5=BC=20=EC=83=81=EC=88=98=ED=99=94=ED=95=9C=20Constraints?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/gildedrose/Constraints.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Java/src/main/java/com/gildedrose/Constraints.java diff --git a/Java/src/main/java/com/gildedrose/Constraints.java b/Java/src/main/java/com/gildedrose/Constraints.java new file mode 100644 index 0000000..6570a57 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/Constraints.java @@ -0,0 +1,25 @@ +package com.gildedrose; + +public enum Constraints { + QUALITY_MAXIMUM(50), + QUALITY_MINIMUM(0), + QUALITY_OF_SULFURAS(80), + QUALITY_DECREASE_NORMAL(1), + QUALITY_DECREASE_CONJURED(2), + QUALITY_DECREASE_MULTIPLE(2), + QUALITY_INCREASE_BRIE(1), + QUALITY_INCREASE_MULTIPLE(2), + QUALITY_INCREASE_PASSES_V2(2), + QUALITY_INCREASE_PASSES_V3(3), + MULTIPLE_DECREASE_START_DAY(0); + + private final int value; + + Constraints(int value) { + this.value = value; + } + + public int value() { + return value; + } +} From 66cc6362650421c2155c9102a4cdead7c293402a Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Wed, 30 Oct 2024 20:54:54 +0900 Subject: [PATCH 12/16] rename: ElseUpdateLogic -> NormalUpdateLogic --- .../{ElseUpdateLogic.java => NormalUpdateLogic.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename Java/src/main/java/com/gildedrose/updateLogic/{ElseUpdateLogic.java => NormalUpdateLogic.java} (78%) diff --git a/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/NormalUpdateLogic.java similarity index 78% rename from Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java rename to Java/src/main/java/com/gildedrose/updateLogic/NormalUpdateLogic.java index cc52910..0aee3a3 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/ElseUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/NormalUpdateLogic.java @@ -2,7 +2,7 @@ import com.gildedrose.Item; -public class ElseUpdateLogic extends UpdateLogic { +public class NormalUpdateLogic extends UpdateLogic { @Override public void update(Item item) { decreaseSellIn(item); From 5da05c98bb8b202e4b57c5307e1b71dcad39f08f Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Wed, 30 Oct 2024 21:35:07 +0900 Subject: [PATCH 13/16] =?UTF-8?q?refactor:=20Constraints=EC=97=90=20?= =?UTF-8?q?=EB=94=B0=EB=A5=B8=20UpdateLogic=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/gildedrose/Constraints.java | 7 +------ .../gildedrose/updateLogic/BrieUpdateLogic.java | 9 ++++++--- .../updateLogic/ConjuredUpdateLogic.java | 12 ++++++++++-- .../gildedrose/updateLogic/NormalUpdateLogic.java | 9 ++++++++- .../gildedrose/updateLogic/PassesUpdateLogic.java | 10 +++++++--- .../com/gildedrose/updateLogic/UpdateLogic.java | 15 +++++---------- 6 files changed, 37 insertions(+), 25 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/Constraints.java b/Java/src/main/java/com/gildedrose/Constraints.java index 6570a57..7002744 100644 --- a/Java/src/main/java/com/gildedrose/Constraints.java +++ b/Java/src/main/java/com/gildedrose/Constraints.java @@ -4,14 +4,9 @@ public enum Constraints { QUALITY_MAXIMUM(50), QUALITY_MINIMUM(0), QUALITY_OF_SULFURAS(80), - QUALITY_DECREASE_NORMAL(1), - QUALITY_DECREASE_CONJURED(2), QUALITY_DECREASE_MULTIPLE(2), - QUALITY_INCREASE_BRIE(1), QUALITY_INCREASE_MULTIPLE(2), - QUALITY_INCREASE_PASSES_V2(2), - QUALITY_INCREASE_PASSES_V3(3), - MULTIPLE_DECREASE_START_DAY(0); + MULTIPLE_START_DAY(0); private final int value; diff --git a/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java index 302dba3..af6fc36 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/BrieUpdateLogic.java @@ -1,16 +1,19 @@ package com.gildedrose.updateLogic; +import com.gildedrose.Constraints; import com.gildedrose.Item; public class BrieUpdateLogic extends UpdateLogic { + private static final int QUALITY_INCREASE_BRIE = 1; + @Override public void update(Item item) { decreaseSellIn(item); - if (item.sellIn < 0) { - increaseQuality(item, 2); + if (item.sellIn < Constraints.MULTIPLE_START_DAY.value()) { + increaseQuality(item, QUALITY_INCREASE_BRIE * Constraints.QUALITY_INCREASE_MULTIPLE.value()); } else { - increaseQuality(item, 1); + increaseQuality(item, QUALITY_INCREASE_BRIE); } } } diff --git a/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java index 7e57e97..86a1e2a 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/ConjuredUpdateLogic.java @@ -1,12 +1,20 @@ package com.gildedrose.updateLogic; +import com.gildedrose.Constraints; import com.gildedrose.Item; public class ConjuredUpdateLogic extends UpdateLogic { + private static final int QUALITY_DECREASE_CONJURED = 2; + @Override public void update(Item item) { decreaseSellIn(item); - - decreaseQuality(item, 2); + + if (item.sellIn < Constraints.MULTIPLE_START_DAY.value()) { + decreaseQuality(item, QUALITY_DECREASE_CONJURED * Constraints.QUALITY_DECREASE_MULTIPLE.value()); + } else { + decreaseQuality(item, QUALITY_DECREASE_CONJURED); + } + } } diff --git a/Java/src/main/java/com/gildedrose/updateLogic/NormalUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/NormalUpdateLogic.java index 0aee3a3..bbf850b 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/NormalUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/NormalUpdateLogic.java @@ -1,12 +1,19 @@ package com.gildedrose.updateLogic; +import com.gildedrose.Constraints; import com.gildedrose.Item; public class NormalUpdateLogic extends UpdateLogic { + private static final int QUALITY_DECREASE_NORMAL = 1; + @Override public void update(Item item) { decreaseSellIn(item); - decreaseQuality(item, 1); + if (item.sellIn < 0) { + decreaseQuality(item, QUALITY_DECREASE_NORMAL * Constraints.QUALITY_DECREASE_MULTIPLE.value()); + } else { + decreaseQuality(item, QUALITY_DECREASE_NORMAL); + } } } diff --git a/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java index b9a3e94..043aa71 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/PassesUpdateLogic.java @@ -3,6 +3,10 @@ import com.gildedrose.Item; public class PassesUpdateLogic extends UpdateLogic { + private static final int QUALITY_INCREASE_PASSES_V1 = 1; + private static final int QUALITY_INCREASE_PASSES_V2 = 2; + private static final int QUALITY_INCREASE_PASSES_V3 = 3; + @Override public void update(Item item) { decreaseSellIn(item); @@ -10,11 +14,11 @@ public void update(Item item) { if (item.sellIn < 0) { resetQuality(item); } else if (item.sellIn <= 5) { - increaseQuality(item, 3); + increaseQuality(item, QUALITY_INCREASE_PASSES_V3); } else if (item.sellIn <= 10) { - increaseQuality(item, 2); + increaseQuality(item, QUALITY_INCREASE_PASSES_V2); } else { - increaseQuality(item, 1); + increaseQuality(item, QUALITY_INCREASE_PASSES_V1); } } diff --git a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java index 4ffd88d..baad208 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogic.java @@ -1,30 +1,25 @@ package com.gildedrose.updateLogic; +import static com.gildedrose.Constraints.*; + import com.gildedrose.Item; public abstract class UpdateLogic { - private static final int MAX_QUALITY = 50; - private static final int MIN_QUALITY = 0; - private static final int DOWN_MULTIPLE = 2; protected void decreaseSellIn(Item item) { item.sellIn -= 1; } protected void decreaseQuality(Item item, int decreaseAmount) { - if (item.sellIn < 0) { - item.quality = Math.max(item.quality - decreaseAmount * DOWN_MULTIPLE, MIN_QUALITY); - } else { - item.quality = Math.max(item.quality - decreaseAmount, MIN_QUALITY); - } + item.quality = Math.max(item.quality - decreaseAmount, QUALITY_MINIMUM.value()); } protected void increaseQuality(Item item, int increaseAmount) { - item.quality = Math.min(item.quality + increaseAmount, MAX_QUALITY); + item.quality = Math.min(item.quality + increaseAmount, QUALITY_MAXIMUM.value()); } protected void resetQuality(Item item) { - item.quality = 0; + item.quality = QUALITY_MINIMUM.value(); } public abstract void update(Item item); From bd94f0819ef531fe6dad5145be8618c12a8d942e Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Wed, 30 Oct 2024 21:41:57 +0900 Subject: [PATCH 14/16] =?UTF-8?q?refactor:=20ItemCategory=EC=9D=98=20value?= =?UTF-8?q?=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gildedrose/updateLogic/ItemCategory.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java b/Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java index a6f40d8..4e4a70e 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java @@ -1,5 +1,18 @@ package com.gildedrose.updateLogic; public enum ItemCategory { - BRIE, PASS, CONJURED, SULFURAS, ELSE + BRIE("Aged Brie"), + PASS("Backstage passes to a "), + CONJURED("Conjured "), + SULFURAS("Sulfuras"); + + private final String value; + + ItemCategory(String value) { + this.value = value; + } + + public String value() { + return value; + } } From e4c2671a0af6bb8530f8dcdf910420a8c3538c50 Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Wed, 30 Oct 2024 22:05:59 +0900 Subject: [PATCH 15/16] =?UTF-8?q?refactor:=20UpdateLogicFactory=EC=97=90?= =?UTF-8?q?=EC=84=9C=20itemMap=20=EC=A0=9C=EA=B1=B0=20=EB=B0=8F=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../updateLogic/UpdateLogicFactory.java | 17 +++++++---------- 1 file changed, 7 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 894f353..05ccd15 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/UpdateLogicFactory.java @@ -2,31 +2,28 @@ import static com.gildedrose.updateLogic.ItemCategory.*; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; 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()); updateLogicMap.put(CONJURED, new ConjuredUpdateLogic()); updateLogicMap.put(SULFURAS, new SulfurasUpdateLogic()); - updateLogicMap.put(ELSE, new ElseUpdateLogic()); + updateLogicMap.put(NORMAL, new NormalUpdateLogic()); } public UpdateLogic findUpdateLogic(String name) { - for (String key : itemMap.keySet()) { - if (name.contains(key)) { - return updateLogicMap.get(itemMap.get(key)); - } - } - return updateLogicMap.get(ELSE); + ItemCategory itemCategory = Arrays.stream(ItemCategory.values()) + .filter(category -> name.contains(category.value())) + .findFirst() + .orElse(NORMAL); + return updateLogicMap.get(itemCategory); } } From f9d34904145b551480957bae8793260de4965a8c Mon Sep 17 00:00:00 2001 From: Yeongchan Kim Date: Wed, 30 Oct 2024 22:11:43 +0900 Subject: [PATCH 16/16] =?UTF-8?q?refactor:=20ItemCategory=EC=97=90?= =?UTF-8?q?=EC=84=9C=20NORMAL=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/gildedrose/updateLogic/ItemCategory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java b/Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java index 4e4a70e..e03a08b 100644 --- a/Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java +++ b/Java/src/main/java/com/gildedrose/updateLogic/ItemCategory.java @@ -4,7 +4,8 @@ public enum ItemCategory { BRIE("Aged Brie"), PASS("Backstage passes to a "), CONJURED("Conjured "), - SULFURAS("Sulfuras"); + SULFURAS("Sulfuras"), + NORMAL("THIS_IS_NORMAL!!"); private final String value;