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() {
|
public void updateQuality() {
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
if (isAgedBride(item)) {
|
|
||||||
|
if (item.isAgedBride()) {
|
||||||
item.increaseQualityByOne();
|
item.increaseQualityByOne();
|
||||||
} else if (isBackstagePasses(item)) {
|
|
||||||
item.increaseQualityBackstage();
|
|
||||||
} else {
|
|
||||||
item.decreaseQualityByOne();
|
|
||||||
}
|
|
||||||
|
|
||||||
item.decreaseSellInEachDay();
|
item.decreaseSellInEachDay();
|
||||||
|
|
||||||
if (item.sellIn < 0) {
|
if (item.sellIn < 0) {
|
||||||
if (isAgedBride(item)) {
|
|
||||||
item.increaseQualityByOne();
|
item.increaseQualityByOne();
|
||||||
} else if (isBackstagePasses(item)) {
|
}
|
||||||
item.quality = 0;
|
} else {
|
||||||
|
boolean isBackstagePasses = item.isBackstagePasses();
|
||||||
|
if (isBackstagePasses) {
|
||||||
|
item.increaseQualityBackstage();
|
||||||
} else {
|
} else {
|
||||||
item.decreaseQualityByOne();
|
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;
|
this.quality = quality;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public boolean isBackstagePasses() {
|
||||||
|
return name.equals(BACKSTAGE_PASSES);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAgedBride() {
|
||||||
|
return name.equals(AGED_BRIE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name + ", " + this.sellIn + ", " + this.quality;
|
return this.name + ", " + this.sellIn + ", " + this.quality;
|
||||||
}
|
}
|
||||||
|
|
||||||
void decreaseSellInEachDay() {
|
void decreaseSellInEachDay() {
|
||||||
if (!name.equals(SULFURAS)) {
|
if (isNotSulfuras()) {
|
||||||
sellIn--;
|
sellIn--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isNotSulfuras() {
|
||||||
|
return !name.equals(SULFURAS);
|
||||||
|
}
|
||||||
|
|
||||||
void increaseQualityByOne() {
|
void increaseQualityByOne() {
|
||||||
if (quality < 50) {
|
if (quality < 50) {
|
||||||
quality++;
|
quality++;
|
||||||
@ -46,7 +58,7 @@ public class Item {
|
|||||||
|
|
||||||
void decreaseQualityByOne() {
|
void decreaseQualityByOne() {
|
||||||
if (quality > 0) {
|
if (quality > 0) {
|
||||||
if (!name.equals(SULFURAS)) {
|
if (isNotSulfuras()) {
|
||||||
quality--;
|
quality--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user