From 81594ed2da2d9a3419252976d407c6105e05db8f Mon Sep 17 00:00:00 2001 From: seoyoung0121 <88281319+seoyoung0121@users.noreply.github.com> Date: Thu, 26 Sep 2024 13:40:36 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 0 -> 6148 bytes .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/jpa-buddy.xml | 6 + .idea/misc.xml | 3 + .idea/networking1~2.iml | 4 +- .idea/uiDesigner.xml | 124 ++++++++++++++++++ .../main/java/com/gildedrose/GildedRose.java | 106 ++++++++------- .../com/gildedrose/rules/AgedBrieLogic.java | 18 +++ .../rules/BackStagePassesLogic.java | 28 ++++ .../com/gildedrose/rules/CommonLogic.java | 21 +++ .../com/gildedrose/rules/ConjuredLogic.java | 21 +++ .../main/java/com/gildedrose/rules/Logic.java | 5 + .../com/gildedrose/rules/LogicFactory.java | 29 ++++ .../com/gildedrose/rules/SulfurasLogic.java | 9 ++ 14 files changed, 328 insertions(+), 51 deletions(-) create mode 100644 .DS_Store create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/jpa-buddy.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java create mode 100644 Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java create mode 100644 Java/src/main/java/com/gildedrose/rules/CommonLogic.java create mode 100644 Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java create mode 100644 Java/src/main/java/com/gildedrose/rules/Logic.java create mode 100644 Java/src/main/java/com/gildedrose/rules/LogicFactory.java create mode 100644 Java/src/main/java/com/gildedrose/rules/SulfurasLogic.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ee253ab11df706284b28fee9c5d2bd2a677eaf74 GIT binary patch literal 6148 zcmeHKJ5Iwu5S_J+WCTU%DE9BpMJ=3TKSAvGf?{**g}w$SzRv9?RKqa@y3Z zPNf9?ssjA(5;~w6E$BRWe^L4B=jtZU%Vkp{mKJ+YH&^4^qcC56n_tbn-$s0mR@wsZ zf+{+rX~0a$eVFyR4__YE++Kg(e6aUd1pG8+{)A3wN|&G5qxqem^SPhj9@pHPUZ1%y zAMnNnwiXiwL;+FY*A>9bW=nT0$|?$o0;0f10scN{IAi9pwP-#aSj-Usm>_Hn*L;@X z9_=u5*jhverfe(FwkmhTP_`X$?dmdztwq~T${jwGV^;2jq6|Cs*QT6QW>HpAKokfS zi0$ow=l}87=l`%t?nD7m;9n`Al6;bn@JMd9b{>vrt%etHHm++eZd!0*Mlou66z{{0 ZA+GrXm^o}MA_9{?0!9W|M1dbw;2oD1WpV%j literal 0 HcmV?d00001 diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..9a295ca --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/jpa-buddy.xml b/.idea/jpa-buddy.xml new file mode 100644 index 0000000..966d5f5 --- /dev/null +++ b/.idea/jpa-buddy.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index e6be3f1..8210f62 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,4 +3,7 @@ + + \ No newline at end of file diff --git a/.idea/networking1~2.iml b/.idea/networking1~2.iml index d6ebd48..4877163 100644 --- a/.idea/networking1~2.iml +++ b/.idea/networking1~2.iml @@ -2,7 +2,9 @@ - + + + diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java/src/main/java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java index 87a3b92..d0e6411 100644 --- a/Java/src/main/java/com/gildedrose/GildedRose.java +++ b/Java/src/main/java/com/gildedrose/GildedRose.java @@ -1,62 +1,68 @@ package com.gildedrose; +import com.gildedrose.Item; +import com.gildedrose.rules.LogicFactory; class GildedRose { Item[] items; + LogicFactory logicFactory; public GildedRose(Item[] items) { this.items = items; + this.logicFactory=new LogicFactory(); } 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) { + logicFactory.getLogic(item).update(item); + } + // 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; + // } + // } + // } + // } } } diff --git a/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java b/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java new file mode 100644 index 0000000..74f5d38 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java @@ -0,0 +1,18 @@ +package com.gildedrose.rules; + +import com.gildedrose.Item; + +public class AgedBrieLogic implements Logic{ + @Override + public void update(Item item) { + item.sellIn--; + if(item.quality<50){ + item.quality++; + } + + if(item.sellIn<0){ + item.quality++; + + } + } +} diff --git a/Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java b/Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java new file mode 100644 index 0000000..c05c21a --- /dev/null +++ b/Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java @@ -0,0 +1,28 @@ +package com.gildedrose.rules; + +import com.gildedrose.Item; + +public class BackStagePassesLogic implements Logic{ + @Override + public void update(Item item) { + if (item.quality < 50) { + item.quality++; + } + if (item.sellIn < 11) { + if (item.quality < 50) { + item.quality++; + } + } + if (item.sellIn < 6) { + if (item.quality < 50) { + item.quality++; + } + } + + item.sellIn--; + + if(item.sellIn < 0) { + item.quality=0; + } + } +} diff --git a/Java/src/main/java/com/gildedrose/rules/CommonLogic.java b/Java/src/main/java/com/gildedrose/rules/CommonLogic.java new file mode 100644 index 0000000..d840d0b --- /dev/null +++ b/Java/src/main/java/com/gildedrose/rules/CommonLogic.java @@ -0,0 +1,21 @@ +package com.gildedrose.rules; + +import com.gildedrose.Item; + +public class CommonLogic implements Logic{ + @Override + public void update(Item item) { + item.sellIn--; + + if (item.sellIn < 0) { + item.quality -= 2; + + } else { + item.quality--; + } + + if (item.quality < 0) { + item.quality = 0; + } + } +} diff --git a/Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java b/Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java new file mode 100644 index 0000000..534ffd3 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java @@ -0,0 +1,21 @@ +package com.gildedrose.rules; + +import com.gildedrose.Item; + +public class ConjuredLogic implements Logic{ + @Override + public void update(Item item) { + item.sellIn--; + + if (item.sellIn < 0) { + item.quality -= 4; + + } else { + item.quality-=2; + } + + if (item.quality < 0) { + item.quality = 0; + } + } +} diff --git a/Java/src/main/java/com/gildedrose/rules/Logic.java b/Java/src/main/java/com/gildedrose/rules/Logic.java new file mode 100644 index 0000000..94b5b33 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/rules/Logic.java @@ -0,0 +1,5 @@ +package com.gildedrose.rules; +import com.gildedrose.Item; +public interface Logic { + public void update(Item item); +} diff --git a/Java/src/main/java/com/gildedrose/rules/LogicFactory.java b/Java/src/main/java/com/gildedrose/rules/LogicFactory.java new file mode 100644 index 0000000..8f9c689 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/rules/LogicFactory.java @@ -0,0 +1,29 @@ +package com.gildedrose.rules; + +import java.util.HashMap; + +import com.gildedrose.Item; + +public class LogicFactory { + public static HashMap logics=new HashMap(); + + public LogicFactory(){ + logics.put("Common", new CommonLogic()); + logics.put("Aged Brie", new AgedBrieLogic()); + logics.put("Backstage passes to a TAFKAL80ETC concert", new BackStagePassesLogic()); + logics.put("Sulfuras, Hand of Ragnaros", new SulfurasLogic()); + logics.put("Conjured", new ConjuredLogic()); + } + + public Logic getLogic(Item item){ + if(logics.containsKey(item.name)){ + return logics.get(item.name); + } else if (item.name.contains("Conjured")) { + return logics.get("Conjured"); + } + else{ + return logics.get("Common"); + } + } + +} diff --git a/Java/src/main/java/com/gildedrose/rules/SulfurasLogic.java b/Java/src/main/java/com/gildedrose/rules/SulfurasLogic.java new file mode 100644 index 0000000..544046d --- /dev/null +++ b/Java/src/main/java/com/gildedrose/rules/SulfurasLogic.java @@ -0,0 +1,9 @@ +package com.gildedrose.rules; + +import com.gildedrose.Item; + +public class SulfurasLogic implements Logic{ + @Override + public void update(Item item) { + } +} From ded4489880d1ce517a5ffe249e8d9b20315f1359 Mon Sep 17 00:00:00 2001 From: seoyoung0121 <88281319+seoyoung0121@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:24:39 +0900 Subject: [PATCH 2/7] =?UTF-8?q?refactor:=20Logic=20=EC=B6=94=EC=83=81=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD,=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=BD=94=EB=93=9C=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=A1=9C=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gildedrose/rules/AgedBrieLogic.java | 14 +++++------- .../rules/BackStagePassesLogic.java | 22 ++++++++----------- .../com/gildedrose/rules/CommonLogic.java | 16 +++++--------- .../com/gildedrose/rules/ConjuredLogic.java | 16 +++++--------- .../main/java/com/gildedrose/rules/Logic.java | 21 ++++++++++++++++-- .../com/gildedrose/rules/SulfurasLogic.java | 2 +- 6 files changed, 46 insertions(+), 45 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java b/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java index 74f5d38..3ab9998 100644 --- a/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java +++ b/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java @@ -2,17 +2,13 @@ import com.gildedrose.Item; -public class AgedBrieLogic implements Logic{ +public class AgedBrieLogic extends Logic{ @Override public void update(Item item) { - item.sellIn--; - if(item.quality<50){ - item.quality++; - } - - if(item.sellIn<0){ - item.quality++; - + decreaseSellIn(item); + increaseQuality(1, item); + if(!checkValid(item)){ + increaseQuality(1, item); } } } diff --git a/Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java b/Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java index c05c21a..d424020 100644 --- a/Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java +++ b/Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java @@ -2,26 +2,22 @@ import com.gildedrose.Item; -public class BackStagePassesLogic implements Logic{ +public class BackStagePassesLogic extends Logic{ @Override public void update(Item item) { - if (item.quality < 50) { - item.quality++; + if (item.sellIn <= 5) { + increaseQuality(3, item); } - if (item.sellIn < 11) { - if (item.quality < 50) { - item.quality++; - } + else if (item.sellIn <= 10) { + increaseQuality(2, item); } - if (item.sellIn < 6) { - if (item.quality < 50) { - item.quality++; - } + else{ + increaseQuality(1, item); } - item.sellIn--; + decreaseSellIn(item); - if(item.sellIn < 0) { + if(!checkValid(item)) { item.quality=0; } } diff --git a/Java/src/main/java/com/gildedrose/rules/CommonLogic.java b/Java/src/main/java/com/gildedrose/rules/CommonLogic.java index d840d0b..e2cccb0 100644 --- a/Java/src/main/java/com/gildedrose/rules/CommonLogic.java +++ b/Java/src/main/java/com/gildedrose/rules/CommonLogic.java @@ -2,20 +2,16 @@ import com.gildedrose.Item; -public class CommonLogic implements Logic{ +public class CommonLogic extends Logic{ @Override public void update(Item item) { - item.sellIn--; + decreaseSellIn(item); - if (item.sellIn < 0) { - item.quality -= 2; - - } else { - item.quality--; + if (!checkValid(item)) { + decreaseQuality(2, item); } - - if (item.quality < 0) { - item.quality = 0; + else { + decreaseQuality(1, item); } } } diff --git a/Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java b/Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java index 534ffd3..8e1934f 100644 --- a/Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java +++ b/Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java @@ -2,20 +2,16 @@ import com.gildedrose.Item; -public class ConjuredLogic implements Logic{ +public class ConjuredLogic extends Logic{ @Override public void update(Item item) { - item.sellIn--; + decreaseSellIn(item); - if (item.sellIn < 0) { - item.quality -= 4; - - } else { - item.quality-=2; + if (!checkValid(item)) { + decreaseQuality(4, item); } - - if (item.quality < 0) { - item.quality = 0; + else { + decreaseQuality(2, item); } } } diff --git a/Java/src/main/java/com/gildedrose/rules/Logic.java b/Java/src/main/java/com/gildedrose/rules/Logic.java index 94b5b33..109ee5f 100644 --- a/Java/src/main/java/com/gildedrose/rules/Logic.java +++ b/Java/src/main/java/com/gildedrose/rules/Logic.java @@ -1,5 +1,22 @@ package com.gildedrose.rules; import com.gildedrose.Item; -public interface Logic { - public void update(Item item); +public abstract class Logic { + public abstract void update(Item item); + + protected void decreaseSellIn(Item item){ + item.sellIn=item.sellIn-1; + } + + protected void decreaseQuality(int amount, Item item){ + item.quality=Math.max(item.quality-amount, 0); + } + + protected void increaseQuality(int amount, Item item){ + item.quality=Math.min(item.quality+amount, 50); + } + + protected boolean checkValid(Item item){ + return item.sellIn >= 0; + } + } diff --git a/Java/src/main/java/com/gildedrose/rules/SulfurasLogic.java b/Java/src/main/java/com/gildedrose/rules/SulfurasLogic.java index 544046d..6bf1a3b 100644 --- a/Java/src/main/java/com/gildedrose/rules/SulfurasLogic.java +++ b/Java/src/main/java/com/gildedrose/rules/SulfurasLogic.java @@ -2,7 +2,7 @@ import com.gildedrose.Item; -public class SulfurasLogic implements Logic{ +public class SulfurasLogic extends Logic { @Override public void update(Item item) { } From badcbfa94fd45463689331582851b4d15dbef8a0 Mon Sep 17 00:00:00 2001 From: seoyoung0121 <88281319+seoyoung0121@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:35:31 +0900 Subject: [PATCH 3/7] =?UTF-8?q?refactor:=20=EB=A7=A4=EC=A7=81=EB=84=98?= =?UTF-8?q?=EB=B2=84=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Java/src/main/java/com/gildedrose/rules/Logic.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/rules/Logic.java b/Java/src/main/java/com/gildedrose/rules/Logic.java index 109ee5f..b61e1ac 100644 --- a/Java/src/main/java/com/gildedrose/rules/Logic.java +++ b/Java/src/main/java/com/gildedrose/rules/Logic.java @@ -1,6 +1,8 @@ package com.gildedrose.rules; import com.gildedrose.Item; public abstract class Logic { + private static final int QUALITY_MAX=50; + private static final int QUALITY_MIN=0; public abstract void update(Item item); protected void decreaseSellIn(Item item){ @@ -8,11 +10,11 @@ protected void decreaseSellIn(Item item){ } protected void decreaseQuality(int amount, Item item){ - item.quality=Math.max(item.quality-amount, 0); + item.quality=Math.max(item.quality-amount, QUALITY_MIN); } protected void increaseQuality(int amount, Item item){ - item.quality=Math.min(item.quality+amount, 50); + item.quality=Math.min(item.quality+amount, QUALITY_MAX); } protected boolean checkValid(Item item){ From 9ae1925d336f0c6070686ef01d8ea3842b2e9f53 Mon Sep 17 00:00:00 2001 From: seoyoung0121 <88281319+seoyoung0121@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:40:28 +0900 Subject: [PATCH 4/7] =?UTF-8?q?refactor:=20map=20=EC=A2=85=EB=A5=98=20?= =?UTF-8?q?=EB=B0=94=EB=80=94=EA=B2=83=20=EB=8C=80=EB=B9=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Java/src/main/java/com/gildedrose/rules/LogicFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Java/src/main/java/com/gildedrose/rules/LogicFactory.java b/Java/src/main/java/com/gildedrose/rules/LogicFactory.java index 8f9c689..c9297e1 100644 --- a/Java/src/main/java/com/gildedrose/rules/LogicFactory.java +++ b/Java/src/main/java/com/gildedrose/rules/LogicFactory.java @@ -1,11 +1,12 @@ package com.gildedrose.rules; import java.util.HashMap; +import java.util.Map; import com.gildedrose.Item; public class LogicFactory { - public static HashMap logics=new HashMap(); + public static Map logics=new HashMap(); public LogicFactory(){ logics.put("Common", new CommonLogic()); From 3b11d16d96e0be4fcd1c5557b8dd70eabcfb50bf Mon Sep 17 00:00:00 2001 From: seoyoung0121 <88281319+seoyoung0121@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:47:41 +0900 Subject: [PATCH 5/7] =?UTF-8?q?refactor:=20=ED=82=A4=EC=99=80=20=EC=99=84?= =?UTF-8?q?=EC=A0=84=ED=9E=88=20=EA=B0=99=EC=9D=80=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=EC=9D=B4=20=EC=95=84=EB=8B=88=EB=8D=94=EB=9D=BC=EB=8F=84=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=A0=81=EC=9A=A9=ED=95=B4=EC=A4=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gildedrose/rules/LogicFactory.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/rules/LogicFactory.java b/Java/src/main/java/com/gildedrose/rules/LogicFactory.java index c9297e1..b42e576 100644 --- a/Java/src/main/java/com/gildedrose/rules/LogicFactory.java +++ b/Java/src/main/java/com/gildedrose/rules/LogicFactory.java @@ -11,20 +11,18 @@ public class LogicFactory { public LogicFactory(){ logics.put("Common", new CommonLogic()); logics.put("Aged Brie", new AgedBrieLogic()); - logics.put("Backstage passes to a TAFKAL80ETC concert", new BackStagePassesLogic()); + logics.put("Backstage passes to", new BackStagePassesLogic()); logics.put("Sulfuras, Hand of Ragnaros", new SulfurasLogic()); logics.put("Conjured", new ConjuredLogic()); } public Logic getLogic(Item item){ - if(logics.containsKey(item.name)){ - return logics.get(item.name); - } else if (item.name.contains("Conjured")) { - return logics.get("Conjured"); - } - else{ - return logics.get("Common"); + for ( String key : logics.keySet() ) { + if (item.name.contains(key)) { + return logics.get(key); + } } + return logics.get("Common"); } } From 5cdbeb34d5867b680b85134e410931722f7ea0be Mon Sep 17 00:00:00 2001 From: seoyoung0121 <88281319+seoyoung0121@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:54:36 +0900 Subject: [PATCH 6/7] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=ED=8F=AC?= =?UTF-8?q?=EB=A7=B7=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gildedrose/rules/AgedBrieLogic.java | 4 ++-- .../rules/BackStagePassesLogic.java | 12 ++++------ .../com/gildedrose/rules/CommonLogic.java | 5 ++-- .../com/gildedrose/rules/ConjuredLogic.java | 5 ++-- .../main/java/com/gildedrose/rules/Logic.java | 23 +++++++++++-------- .../com/gildedrose/rules/LogicFactory.java | 8 +++---- 6 files changed, 28 insertions(+), 29 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java b/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java index 3ab9998..a04e624 100644 --- a/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java +++ b/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java @@ -2,12 +2,12 @@ import com.gildedrose.Item; -public class AgedBrieLogic extends Logic{ +public class AgedBrieLogic extends Logic { @Override public void update(Item item) { decreaseSellIn(item); increaseQuality(1, item); - if(!checkValid(item)){ + if (!checkValid(item)) { increaseQuality(1, item); } } diff --git a/Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java b/Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java index d424020..01c18d6 100644 --- a/Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java +++ b/Java/src/main/java/com/gildedrose/rules/BackStagePassesLogic.java @@ -2,23 +2,21 @@ import com.gildedrose.Item; -public class BackStagePassesLogic extends Logic{ +public class BackStagePassesLogic extends Logic { @Override public void update(Item item) { if (item.sellIn <= 5) { increaseQuality(3, item); - } - else if (item.sellIn <= 10) { + } else if (item.sellIn <= 10) { increaseQuality(2, item); - } - else{ + } else { increaseQuality(1, item); } decreaseSellIn(item); - if(!checkValid(item)) { - item.quality=0; + if (!checkValid(item)) { + item.quality = 0; } } } diff --git a/Java/src/main/java/com/gildedrose/rules/CommonLogic.java b/Java/src/main/java/com/gildedrose/rules/CommonLogic.java index e2cccb0..8221003 100644 --- a/Java/src/main/java/com/gildedrose/rules/CommonLogic.java +++ b/Java/src/main/java/com/gildedrose/rules/CommonLogic.java @@ -2,15 +2,14 @@ import com.gildedrose.Item; -public class CommonLogic extends Logic{ +public class CommonLogic extends Logic { @Override public void update(Item item) { decreaseSellIn(item); if (!checkValid(item)) { decreaseQuality(2, item); - } - else { + } else { decreaseQuality(1, item); } } diff --git a/Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java b/Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java index 8e1934f..278d766 100644 --- a/Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java +++ b/Java/src/main/java/com/gildedrose/rules/ConjuredLogic.java @@ -2,15 +2,14 @@ import com.gildedrose.Item; -public class ConjuredLogic extends Logic{ +public class ConjuredLogic extends Logic { @Override public void update(Item item) { decreaseSellIn(item); if (!checkValid(item)) { decreaseQuality(4, item); - } - else { + } else { decreaseQuality(2, item); } } diff --git a/Java/src/main/java/com/gildedrose/rules/Logic.java b/Java/src/main/java/com/gildedrose/rules/Logic.java index b61e1ac..e2b6ebe 100644 --- a/Java/src/main/java/com/gildedrose/rules/Logic.java +++ b/Java/src/main/java/com/gildedrose/rules/Logic.java @@ -1,24 +1,27 @@ package com.gildedrose.rules; + import com.gildedrose.Item; + public abstract class Logic { - private static final int QUALITY_MAX=50; - private static final int QUALITY_MIN=0; + private static final int QUALITY_MAX = 50; + private static final int QUALITY_MIN = 0; + public abstract void update(Item item); - protected void decreaseSellIn(Item item){ - item.sellIn=item.sellIn-1; + protected void decreaseSellIn(Item item) { + item.sellIn = item.sellIn - 1; } - protected void decreaseQuality(int amount, Item item){ - item.quality=Math.max(item.quality-amount, QUALITY_MIN); + protected void decreaseQuality(int amount, Item item) { + item.quality = Math.max(item.quality - amount, QUALITY_MIN); } - protected void increaseQuality(int amount, Item item){ - item.quality=Math.min(item.quality+amount, QUALITY_MAX); + protected void increaseQuality(int amount, Item item) { + item.quality = Math.min(item.quality + amount, QUALITY_MAX); } - protected boolean checkValid(Item item){ - return item.sellIn >= 0; + protected boolean checkValid(Item item) { + return item.sellIn >= 0; } } diff --git a/Java/src/main/java/com/gildedrose/rules/LogicFactory.java b/Java/src/main/java/com/gildedrose/rules/LogicFactory.java index b42e576..64564bf 100644 --- a/Java/src/main/java/com/gildedrose/rules/LogicFactory.java +++ b/Java/src/main/java/com/gildedrose/rules/LogicFactory.java @@ -6,9 +6,9 @@ import com.gildedrose.Item; public class LogicFactory { - public static Map logics=new HashMap(); + public static Map logics = new HashMap(); - public LogicFactory(){ + public LogicFactory() { logics.put("Common", new CommonLogic()); logics.put("Aged Brie", new AgedBrieLogic()); logics.put("Backstage passes to", new BackStagePassesLogic()); @@ -16,8 +16,8 @@ public LogicFactory(){ logics.put("Conjured", new ConjuredLogic()); } - public Logic getLogic(Item item){ - for ( String key : logics.keySet() ) { + public Logic getLogic(Item item) { + for (String key : logics.keySet()) { if (item.name.contains(key)) { return logics.get(key); } From 9c2c98e0a2e2d2be350031fd92d612de4556e297 Mon Sep 17 00:00:00 2001 From: seoyoung0121 <88281319+seoyoung0121@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:03:34 +0900 Subject: [PATCH 7/7] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=ED=8F=AC?= =?UTF-8?q?=EB=A7=B7=ED=8C=85,=20=EC=A3=BC=EC=84=9D=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EB=B0=8F=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/gildedrose/GildedRose.java | 58 ++----------------- Java/src/main/java/com/gildedrose/Item.java | 4 +- .../com/gildedrose/rules/AgedBrieLogic.java | 1 + .../main/java/com/gildedrose/rules/Logic.java | 3 +- .../com/gildedrose/rules/LogicFactory.java | 3 +- 5 files changed, 10 insertions(+), 59 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java index d0e6411..80d517e 100644 --- a/Java/src/main/java/com/gildedrose/GildedRose.java +++ b/Java/src/main/java/com/gildedrose/GildedRose.java @@ -1,4 +1,5 @@ package com.gildedrose; + import com.gildedrose.Item; import com.gildedrose.rules.LogicFactory; @@ -8,61 +9,12 @@ class GildedRose { public GildedRose(Item[] items) { this.items = items; - this.logicFactory=new LogicFactory(); + this.logicFactory = new LogicFactory(); } public void updateQuality() { - for (Item item : items) { - logicFactory.getLogic(item).update(item); - } - // 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) { + logicFactory.getLogic(item).update(item); //아이템에 맞는 로직을 찾아 quality와 sellIn 업데이트 + } } } diff --git a/Java/src/main/java/com/gildedrose/Item.java b/Java/src/main/java/com/gildedrose/Item.java index 465729e..19634c6 100644 --- a/Java/src/main/java/com/gildedrose/Item.java +++ b/Java/src/main/java/com/gildedrose/Item.java @@ -14,8 +14,8 @@ public Item(String name, int sellIn, int quality) { this.quality = quality; } - @Override - public String toString() { + @Override + public String toString() { return this.name + ", " + this.sellIn + ", " + this.quality; } } diff --git a/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java b/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java index a04e624..62ebf3e 100644 --- a/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java +++ b/Java/src/main/java/com/gildedrose/rules/AgedBrieLogic.java @@ -6,6 +6,7 @@ public class AgedBrieLogic extends Logic { @Override public void update(Item item) { decreaseSellIn(item); + increaseQuality(1, item); if (!checkValid(item)) { increaseQuality(1, item); diff --git a/Java/src/main/java/com/gildedrose/rules/Logic.java b/Java/src/main/java/com/gildedrose/rules/Logic.java index e2b6ebe..73a1fc1 100644 --- a/Java/src/main/java/com/gildedrose/rules/Logic.java +++ b/Java/src/main/java/com/gildedrose/rules/Logic.java @@ -20,8 +20,7 @@ protected void increaseQuality(int amount, Item item) { item.quality = Math.min(item.quality + amount, QUALITY_MAX); } - protected boolean checkValid(Item item) { + protected boolean checkValid(Item item) { //기한이 지났는 지 검사 return item.sellIn >= 0; } - } diff --git a/Java/src/main/java/com/gildedrose/rules/LogicFactory.java b/Java/src/main/java/com/gildedrose/rules/LogicFactory.java index 64564bf..00ddf4c 100644 --- a/Java/src/main/java/com/gildedrose/rules/LogicFactory.java +++ b/Java/src/main/java/com/gildedrose/rules/LogicFactory.java @@ -17,12 +17,11 @@ public LogicFactory() { } public Logic getLogic(Item item) { - for (String key : logics.keySet()) { + for (String key : logics.keySet()) { //logics의 키에 있는 값을 이름에서 포함하는 지 검사하여 맞는 로직 선택 if (item.name.contains(key)) { return logics.get(key); } } return logics.get("Common"); } - }