mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
refactor GlidedRose
This commit is contained in:
parent
b3a0463bba
commit
53cdb7d893
@ -8,55 +8,64 @@ class GildedRose {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (Item item : items) {
|
||||||
if (!items[i].name.equals("Aged Brie")
|
updateItemQuality(item);
|
||||||
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
updateItemSellIn(item);
|
||||||
if (items[i].quality > 0) {
|
handleExpiredItem(item);
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
}
|
||||||
items[i].quality = items[i].quality - 1;
|
}
|
||||||
}
|
|
||||||
}
|
private void updateItemQuality(Item item) {
|
||||||
|
if (isSpecialItem(item)) {
|
||||||
|
increaseQuality(item);
|
||||||
|
if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
|
handleBackstagePasses(item);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
decreaseQuality(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateItemSellIn(Item item) {
|
||||||
|
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
|
item.sellIn--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleExpiredItem(Item item) {
|
||||||
|
if (item.sellIn < 0) {
|
||||||
|
if (item.name.equals("Aged Brie")) {
|
||||||
|
increaseQuality(item);
|
||||||
|
} else if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
|
item.quality = 0;
|
||||||
} else {
|
} else {
|
||||||
if (items[i].quality < 50) {
|
decreaseQuality(item);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSpecialItem(Item item) {
|
||||||
|
return item.name.equals("Aged Brie") || item.name.equals("Backstage passes to a TAFKAL80ETC concert");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void increaseQuality(Item item) {
|
||||||
|
if (item.quality < 50) {
|
||||||
|
item.quality++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void decreaseQuality(Item item) {
|
||||||
|
if (item.quality > 0 && !item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
|
item.quality--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleBackstagePasses(Item item) {
|
||||||
|
if (item.sellIn < 11) {
|
||||||
|
increaseQuality(item);
|
||||||
|
}
|
||||||
|
if (item.sellIn < 6) {
|
||||||
|
increaseQuality(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user