From 2c22c34721f7fab392bb6f0ed8378adf7d9748f2 Mon Sep 17 00:00:00 2001 From: Bjorn Misseghers Date: Tue, 13 Apr 2021 11:06:37 +0200 Subject: [PATCH] Use the item behaviors to process the updates --- .../main/java/com/gildedrose/GildedRose.java | 74 ++----------------- 1 file changed, 5 insertions(+), 69 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java index d95f23eb..e0a32bae 100644 --- a/Java/src/main/java/com/gildedrose/GildedRose.java +++ b/Java/src/main/java/com/gildedrose/GildedRose.java @@ -1,12 +1,10 @@ package com.gildedrose; -class GildedRose { - 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 com.gildedrose.behavior.ItemBehaviorPicker; +import java.util.Arrays; + +class GildedRose { Item[] items; public GildedRose(Item[] items) { @@ -14,68 +12,6 @@ class GildedRose { } public void updateQuality() { - for (int i = 0; i < items.length; i++) { - 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; + Arrays.stream(items).forEach(item -> ItemBehaviorPicker.forName(item.name).processUpdate(item)); } } \ No newline at end of file