mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 16:01:42 +00:00
Update GildedRose.java
refactored code into small and reusable chunks focusing on items
This commit is contained in:
parent
f80413c2fd
commit
63e79e073e
@ -1,62 +1,114 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
class GildedRose {
|
class GildedRose {
|
||||||
Item[] items;
|
Item[] items;
|
||||||
|
|
||||||
public GildedRose(Item[] items) {
|
public static final String AGED_BRIE = "Aged Brie";
|
||||||
this.items = items;
|
public static final String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert";
|
||||||
}
|
public static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
|
||||||
|
public static final String CONJURED = "Conjured";
|
||||||
|
|
||||||
public void updateQuality() {
|
public GildedRose(Item[] items) {
|
||||||
for (int i = 0; i < items.length; i++) {
|
this.items = items;
|
||||||
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")) {
|
public void updateQuality() {
|
||||||
if (items[i].sellIn < 11) {
|
for (Item item : items) {
|
||||||
if (items[i].quality < 50) {
|
updateQuality(item);
|
||||||
items[i].quality = items[i].quality + 1;
|
updateSellIn(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items[i].sellIn < 6) {
|
private void updateQuality(Item item) {
|
||||||
if (items[i].quality < 50) {
|
|
||||||
items[i].quality = items[i].quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
switch (item.name) {
|
||||||
items[i].sellIn = items[i].sellIn - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (items[i].sellIn < 0) {
|
case AGED_BRIE:
|
||||||
if (!items[i].name.equals("Aged Brie")) {
|
updateAgedBrie(item);
|
||||||
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
break;
|
||||||
if (items[i].quality > 0) {
|
case BACKSTAGE_PASSES:
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
updateBackStagePasses(item);
|
||||||
items[i].quality = items[i].quality - 1;
|
break;
|
||||||
}
|
case SULFURAS:
|
||||||
}
|
updateSulfras(item);
|
||||||
} else {
|
break;
|
||||||
items[i].quality = items[i].quality - items[i].quality;
|
case CONJURED:
|
||||||
}
|
updateConjured(item);
|
||||||
} else {
|
break;
|
||||||
if (items[i].quality < 50) {
|
default:
|
||||||
items[i].quality = items[i].quality + 1;
|
updateNormalItem(item);
|
||||||
}
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private void updateAgedBrie(Item item) {
|
||||||
|
increaseQualityByOne(item);
|
||||||
|
if (isItemExpired(item)) {
|
||||||
|
increaseQualityByOne(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBackStagePasses(Item item) {
|
||||||
|
|
||||||
|
if (!isItemExpired(item)) {
|
||||||
|
increaseQualityByOne(item);
|
||||||
|
|
||||||
|
if (item.sellIn < 11) {
|
||||||
|
increaseQualityByOne(item);
|
||||||
|
}
|
||||||
|
if (item.sellIn < 6) {
|
||||||
|
increaseQualityByOne(item);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
item.quality = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSulfras(Item item) {
|
||||||
|
// todo...
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateConjured(Item item) {
|
||||||
|
updateNormalItem(item);
|
||||||
|
updateNormalItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateNormalItem(Item item) {
|
||||||
|
|
||||||
|
decreaseQualityByOne(item);
|
||||||
|
if (isItemExpired(item)) {
|
||||||
|
decreaseQualityByOne(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private void updateSellIn(Item item) {
|
||||||
|
|
||||||
|
if (!item.name.equals(SULFURAS)) {
|
||||||
|
item.sellIn = item.sellIn - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isItemExpired(Item item) {
|
||||||
|
return item.sellIn < 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void decreaseQualityByOne(Item item) {
|
||||||
|
if (item.quality > 0) {
|
||||||
|
item.quality = item.quality - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void increaseQualityByOne(Item item) {
|
||||||
|
if (item.quality < 50) {
|
||||||
|
item.quality = item.quality + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user