moved specific backstage logic

This commit is contained in:
Sallah Kokaina 2019-11-01 19:36:04 +01:00
parent 0cb4b53cb4
commit 077ceb820a
5 changed files with 54 additions and 29 deletions

View File

@ -40,4 +40,3 @@
-[x] encapsulate methods -[x] encapsulate methods
-[ ] isolate specific logics -[ ] isolate specific logics
-[x] move specific logic to backstage -[x] move specific logic to backstage
-[x] replace items by specific objects in tests

View File

@ -8,7 +8,6 @@ import com.gildedrose.item.Sulfuras;
class GildedRose { class GildedRose {
Item[] items; Item[] items;
public GildedRose(Item[] items) { public GildedRose(Item[] items) {
this.items = items; this.items = items;
} }
@ -18,48 +17,59 @@ class GildedRose {
final Item item = items[i]; final Item item = items[i];
if (!item.name.equals(Brie.BRIE) && !item.name.equals(Backstage.BACKSTAGE)) { item.updateSellIn();
if (item.quality > 0 && !item.name.equals(Sulfuras.SULFURAS)) {
decreaseQualityByOne(item);
}
}
else {
if (item.quality < 50) {
increaseQuality(item);
}
}
updateSellIn(item); if(item.name.equals(Brie.BRIE)){
updateBrieQuality(item);
if (item.sellIn < 0) { }else if (item.name.equals(Backstage.BACKSTAGE)){
if (item.name.equals(Brie.BRIE)) { updateBackstageQuality(item);
}
else{
if (!item.name.equals(Backstage.BACKSTAGE)) {
if (item.quality > 0 && !item.name.equals(Sulfuras.SULFURAS)) {
item.decreaseQuality();
}
}
else {
if (item.quality < 50) { if (item.quality < 50) {
item.increaseQuality(); item.increaseQuality();
} }
} else { }
if (item.sellIn < 0) {
if (!item.name.equals(Backstage.BACKSTAGE)) { if (!item.name.equals(Backstage.BACKSTAGE)) {
if (!item.name.equals(Sulfuras.SULFURAS) && item.quality > 0) { if (!item.name.equals(Sulfuras.SULFURAS) && item.quality > 0) {
decreaseQualityByOne(item); item.decreaseQuality();
} }
} else { } else {
item.quality = 0; item.quality = 0;
} }
} }
} }
} }
} }
private void decreaseQualityByOne(Item item) { private void updateBackstageQuality(Item item) {
item.decreaseQuality(); if (item.quality < 50) {
} item.increaseQuality();
}
private void increaseQuality(Item item) { if (item.sellIn < 0) {
item.increaseQuality(); item.quality = 0;
}
private void updateSellIn(Item item) {
if (!item.name.equals(Sulfuras.SULFURAS)) {
item.sellIn = item.sellIn - 1;
} }
} }
private void updateBrieQuality(Item item) {
if (item.quality < 50) {
item.increaseQuality();
}
if (item.sellIn < 0) {
if (item.quality < 50) {
item.increaseQuality();
}
}
}
} }

View File

@ -7,4 +7,11 @@ public class Brie extends Item {
public Brie(int sellIn, int quality) { public Brie(int sellIn, int quality) {
super(BRIE, sellIn, quality); super(BRIE, sellIn, quality);
} }
@Override
public void increaseQuality(){
if (this.quality < 50) {
super.increaseQuality();
}
}
} }

View File

@ -26,4 +26,8 @@ public class Item {
public void increaseQuality() { public void increaseQuality() {
this.quality = this.quality + 1; this.quality = this.quality + 1;
} }
public void updateSellIn() {
this.sellIn = this.sellIn - 1;
}
} }

View File

@ -7,4 +7,9 @@ public class Sulfuras extends Item {
public Sulfuras(int sellIn, int quality) { public Sulfuras(int sellIn, int quality) {
super(SULFURAS, sellIn, quality); super(SULFURAS, sellIn, quality);
} }
@Override
public void updateSellIn() {
//NO-OP
}
} }