mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-20 00:41:07 +00:00
Use the item behaviors to process the updates
This commit is contained in:
parent
5f60697105
commit
2c22c34721
@ -1,12 +1,10 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
class GildedRose {
|
import com.gildedrose.behavior.ItemBehaviorPicker;
|
||||||
public static final String ITEM_AGED_BRIE = "Aged Brie";
|
|
||||||
public static final String ITEM_SULFURAS_HAND_OF_RAGNAROS = "Sulfuras, Hand of Ragnaros";
|
|
||||||
public static final String ITEM_BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert";
|
|
||||||
public static final int MAX_QUALITY_LEVEL = 50;
|
|
||||||
public static final int MIN_QUALITY_LEVEL = 0;
|
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
class GildedRose {
|
||||||
Item[] items;
|
Item[] items;
|
||||||
|
|
||||||
public GildedRose(Item[] items) {
|
public GildedRose(Item[] items) {
|
||||||
@ -14,68 +12,6 @@ class GildedRose {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
for (int i = 0; i < items.length; i++) {
|
Arrays.stream(items).forEach(item -> ItemBehaviorPicker.forName(item.name).processUpdate(item));
|
||||||
final Item currentItem = items[i];
|
|
||||||
if (!currentItem.name.equals(ITEM_AGED_BRIE)
|
|
||||||
&& !currentItem.name.equals(ITEM_BACKSTAGE_PASSES)) {
|
|
||||||
if (currentItem.quality > MIN_QUALITY_LEVEL) {
|
|
||||||
if (!currentItem.name.equals(ITEM_SULFURAS_HAND_OF_RAGNAROS)) {
|
|
||||||
decreaseQuality(currentItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (currentItem.quality < MAX_QUALITY_LEVEL) {
|
|
||||||
increaseQuality(currentItem);
|
|
||||||
|
|
||||||
if (currentItem.name.equals(ITEM_BACKSTAGE_PASSES)) {
|
|
||||||
if (currentItem.sellIn < 11) {
|
|
||||||
if (currentItem.quality < MAX_QUALITY_LEVEL) {
|
|
||||||
increaseQuality(currentItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentItem.sellIn < 6) {
|
|
||||||
if (currentItem.quality < MAX_QUALITY_LEVEL) {
|
|
||||||
increaseQuality(currentItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!currentItem.name.equals(ITEM_SULFURAS_HAND_OF_RAGNAROS)) {
|
|
||||||
decreaseSellIn(currentItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentItem.sellIn < 0) {
|
|
||||||
if (!currentItem.name.equals(ITEM_AGED_BRIE)) {
|
|
||||||
if (!currentItem.name.equals(ITEM_BACKSTAGE_PASSES)) {
|
|
||||||
if (currentItem.quality > MIN_QUALITY_LEVEL) {
|
|
||||||
if (!currentItem.name.equals(ITEM_SULFURAS_HAND_OF_RAGNAROS)) {
|
|
||||||
decreaseQuality(currentItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
currentItem.quality = 0;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (currentItem.quality < MAX_QUALITY_LEVEL) {
|
|
||||||
increaseQuality(currentItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void decreaseQuality(Item item) {
|
|
||||||
item.quality = item.quality - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void increaseQuality(Item item) {
|
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void decreaseSellIn(Item item) {
|
|
||||||
item.sellIn = item.sellIn - 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user