mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-04 17:21:38 +00:00
72 lines
2.1 KiB
Java
72 lines
2.1 KiB
Java
package com.gildedrose;
|
|
|
|
class GildedRose {
|
|
private static String AGED_BRIE = "Aged Brie";
|
|
private static String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert";
|
|
private static String SULFURAS = "Sulfuras, Hand of Ragnaros";
|
|
Item[] items;
|
|
|
|
public GildedRose(Item[] items) {
|
|
this.items = items;
|
|
}
|
|
|
|
public void updateQuality() {
|
|
for (int i = 0; i < items.length; i++) {
|
|
if (items[i].name.equals(AGED_BRIE)) {
|
|
incrementQualityByOne(i);
|
|
} else if (items[i].name.equals(BACKSTAGE_PASSES)) {
|
|
if (items[i].sellIn < 6) {
|
|
increaseQualityByThree(i);
|
|
} else if (items[i].sellIn < 11) {
|
|
increaseQualityByTwo(i);
|
|
} else {
|
|
incrementQualityByOne(i);
|
|
}
|
|
} else {
|
|
decreaseQualityByOne(i);
|
|
}
|
|
|
|
if (!items[i].name.equals(SULFURAS)) {
|
|
items[i].sellIn = items[i].sellIn - 1;
|
|
}
|
|
|
|
if (items[i].sellIn < 0) {
|
|
if (items[i].name.equals(AGED_BRIE)) {
|
|
incrementQualityByOne(i);
|
|
} else {
|
|
if (items[i].name.equals(BACKSTAGE_PASSES)) {
|
|
items[i].quality = 0;
|
|
} else {
|
|
decreaseQualityByOne(i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void increaseQualityByThree(int i) {
|
|
increaseQualityByTwo(i);
|
|
incrementQualityByOne(i);
|
|
}
|
|
|
|
private void increaseQualityByTwo(int i) {
|
|
incrementQualityByOne(i);
|
|
incrementQualityByOne(i);
|
|
}
|
|
|
|
private void decreaseQualityByOne(int i) {
|
|
if (items[i].quality > 0) {
|
|
if (!items[i].name.equals(SULFURAS)) {
|
|
items[i].quality = items[i].quality - 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void incrementQualityByOne(int i) {
|
|
if (items[i].quality < 50) {
|
|
items[i].quality = items[i].quality + 1;
|
|
}
|
|
}
|
|
|
|
}
|