mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-04 09:11:39 +00:00
lift up condition with AgedBride
This commit is contained in:
parent
3e07becb36
commit
39c548b2d6
@ -10,34 +10,34 @@ class GildedRose {
|
||||
|
||||
public void updateQuality() {
|
||||
for (Item item : items) {
|
||||
if (isAgedBride(item)) {
|
||||
|
||||
if (item.isAgedBride()) {
|
||||
item.increaseQualityByOne();
|
||||
} else if (isBackstagePasses(item)) {
|
||||
item.increaseQualityBackstage();
|
||||
} else {
|
||||
item.decreaseQualityByOne();
|
||||
}
|
||||
|
||||
item.decreaseSellInEachDay();
|
||||
item.decreaseSellInEachDay();
|
||||
|
||||
if (item.sellIn < 0) {
|
||||
if (isAgedBride(item)) {
|
||||
if (item.sellIn < 0) {
|
||||
item.increaseQualityByOne();
|
||||
} else if (isBackstagePasses(item)) {
|
||||
item.quality = 0;
|
||||
}
|
||||
} else {
|
||||
boolean isBackstagePasses = item.isBackstagePasses();
|
||||
if (isBackstagePasses) {
|
||||
item.increaseQualityBackstage();
|
||||
} else {
|
||||
item.decreaseQualityByOne();
|
||||
}
|
||||
|
||||
item.decreaseSellInEachDay();
|
||||
|
||||
if (item.sellIn < 0) {
|
||||
if (isBackstagePasses) {
|
||||
item.quality = 0;
|
||||
} else {
|
||||
item.decreaseQualityByOne();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isBackstagePasses(Item item) {
|
||||
return item.name.equals(Item.BACKSTAGE_PASSES);
|
||||
}
|
||||
|
||||
private static boolean isAgedBride(Item item) {
|
||||
return item.name.equals(Item.AGED_BRIE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,17 +17,29 @@ public class Item {
|
||||
this.quality = quality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBackstagePasses() {
|
||||
return name.equals(BACKSTAGE_PASSES);
|
||||
}
|
||||
|
||||
public boolean isAgedBride() {
|
||||
return name.equals(AGED_BRIE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name + ", " + this.sellIn + ", " + this.quality;
|
||||
}
|
||||
|
||||
void decreaseSellInEachDay() {
|
||||
if (!name.equals(SULFURAS)) {
|
||||
if (isNotSulfuras()) {
|
||||
sellIn--;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNotSulfuras() {
|
||||
return !name.equals(SULFURAS);
|
||||
}
|
||||
|
||||
void increaseQualityByOne() {
|
||||
if (quality < 50) {
|
||||
quality++;
|
||||
@ -46,7 +58,7 @@ public class Item {
|
||||
|
||||
void decreaseQualityByOne() {
|
||||
if (quality > 0) {
|
||||
if (!name.equals(SULFURAS)) {
|
||||
if (isNotSulfuras()) {
|
||||
quality--;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user