mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-04 09:11:39 +00:00
refactor: improved readability and extract mutations
This commit is contained in:
parent
6564125ba3
commit
58205b5740
@ -9,54 +9,61 @@ class GildedRose {
|
||||
|
||||
public void updateQuality() {
|
||||
for (Item item : items) {
|
||||
if (!item.getName().equals("Aged Brie")
|
||||
&& !item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.quality > 0) {
|
||||
if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.quality = item.quality - 1;
|
||||
}
|
||||
boolean isAgedBrie = item.getName().equals("Aged Brie");
|
||||
boolean isSulfuras = item.getName().equals("Sulfuras, Hand of Ragnaros");
|
||||
boolean passesToTafkalConcert = item.getName().equals("Backstage passes to a TAFKAL80ETC concert");
|
||||
|
||||
if (!isAgedBrie && !passesToTafkalConcert) {
|
||||
if (item.quality > 0 && !isSulfuras) {
|
||||
deductOneFromQuality(item);
|
||||
}
|
||||
} else {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
} else if(item.quality < 50) {
|
||||
addOneToQuality(item);
|
||||
|
||||
if (item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.sellIn < 11) {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
}
|
||||
}
|
||||
if (passesToTafkalConcert) {
|
||||
if (item.sellIn < 11 && item.quality < 50) {
|
||||
addOneToQuality(item);
|
||||
}
|
||||
|
||||
if (item.sellIn < 6) {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
}
|
||||
}
|
||||
if (item.sellIn < 6 && item.quality < 50) {
|
||||
addOneToQuality(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.sellIn = item.sellIn - 1;
|
||||
if (!isSulfuras) {
|
||||
deductSellIn(item);
|
||||
}
|
||||
|
||||
if (item.sellIn < 0) {
|
||||
if (!item.getName().equals("Aged Brie")) {
|
||||
if (!item.getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.quality > 0) {
|
||||
if (!item.getName().equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.quality = item.quality - 1;
|
||||
}
|
||||
if (!isAgedBrie) {
|
||||
if (!passesToTafkalConcert) {
|
||||
if (item.quality > 0 && !isSulfuras) {
|
||||
deductOneFromQuality(item);
|
||||
}
|
||||
} else {
|
||||
item.quality = 0;
|
||||
}
|
||||
} else {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
setQualityToZero(item);
|
||||
}
|
||||
} else if ((item.quality < 50)) {
|
||||
addOneToQuality(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setQualityToZero(Item item) {
|
||||
item.quality = 0;
|
||||
}
|
||||
|
||||
public void deductSellIn(Item item) {
|
||||
item.sellIn--;
|
||||
}
|
||||
|
||||
public void addOneToQuality(Item item) {
|
||||
item.quality++;
|
||||
}
|
||||
|
||||
public void deductOneFromQuality(Item item) {
|
||||
item.quality--;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user