mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-17 15:31:27 +00:00
update StorageItem
remove Item item due to item is a field in this class
This commit is contained in:
parent
fa31f828a1
commit
4fa88bab43
@ -9,7 +9,7 @@ class GildedRose {
|
|||||||
|
|
||||||
public void updateStorage() {
|
public void updateStorage() {
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
new StrorageItem(item).dailyUpdateItem(item);
|
new StrorageItem(item).dailyUpdateItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,64 +7,64 @@ public class StrorageItem {
|
|||||||
this.item = item;
|
this.item = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void decreaseQuality(Item item, StrorageItem strorageItem) {
|
public void dailyUpdateItem() {
|
||||||
if (item.quality > 0) {
|
updateQuality();
|
||||||
item.quality--;
|
updateSelling();
|
||||||
|
if (isExpired()) {
|
||||||
|
updateExpired();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void increaseQuality(Item item, StrorageItem strorageItem) {
|
protected void updateQuality() {
|
||||||
if (item.quality < 50) {
|
|
||||||
item.quality++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void updateQuality(Item item, StrorageItem strorageItem) {
|
|
||||||
if (item.name.equals("Aged Brie")) {
|
if (item.name.equals("Aged Brie")) {
|
||||||
increaseQuality(item,strorageItem);
|
increaseQuality();
|
||||||
} else if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
} else if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
increaseQuality(item, strorageItem);
|
increaseQuality();
|
||||||
|
|
||||||
if (item.sellIn < 11) {
|
if (item.sellIn < 11) {
|
||||||
increaseQuality(item, strorageItem);
|
increaseQuality();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.sellIn < 6) {
|
if (item.sellIn < 6) {
|
||||||
increaseQuality(item, strorageItem);
|
increaseQuality();
|
||||||
}
|
}
|
||||||
} else if (item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
} else if (item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
return;
|
return;
|
||||||
} else decreaseQuality(item,strorageItem);
|
} else decreaseQuality();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void updateSelling(Item item, StrorageItem strorageItem) {
|
protected void updateSelling() {
|
||||||
if (item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
item.sellIn--;
|
item.sellIn--;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean isExpired(Item item, StrorageItem strorageItem) {
|
protected boolean isExpired() {
|
||||||
return item.sellIn < 0;
|
return item.sellIn < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void updateExpired(Item item, StrorageItem strorageItem) {
|
protected void updateExpired() {
|
||||||
if (item.name.equals("Aged Brie")) {
|
if (item.name.equals("Aged Brie")) {
|
||||||
increaseQuality(item, strorageItem);
|
increaseQuality();
|
||||||
} else if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
} else if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
item.quality = 0;
|
item.quality = 0;
|
||||||
} else if (item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
} else if (item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
decreaseQuality(item, strorageItem);
|
decreaseQuality();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dailyUpdateItem(Item item) {
|
protected void increaseQuality() {
|
||||||
updateQuality(item, this);
|
if (item.quality < 50) {
|
||||||
updateSelling(item, this);
|
item.quality++;
|
||||||
if (isExpired(item, this)) {
|
}
|
||||||
updateExpired(item, this);
|
}
|
||||||
|
|
||||||
|
protected void decreaseQuality() {
|
||||||
|
if (item.quality > 0) {
|
||||||
|
item.quality--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user