logic nesting removed

This commit is contained in:
Sallah Kokaina 2019-11-01 19:41:57 +01:00
parent 783a62bb3f
commit 58220c2358
2 changed files with 26 additions and 26 deletions

View File

@ -24,10 +24,10 @@
## Technical Issues, with a balanced priority ## Technical Issues, with a balanced priority
-[x] item names are hardcoded -[x] item names are hardcoded
-[x] items are identified by the name in a hardcoded way -[x] items are identified by the name in a hardcoded way
-[ ] nested logic -[x] nested logic
-[x] long method -[x] long method
-[ ] plain logic -[x] plain logic
-[ ] complex operations -[x] complex operations
-[x] Item properties are public -[x] Item properties are public
-[x] multiple access by index -[x] multiple access by index
@ -38,6 +38,6 @@
-[x] extract methods -[x] extract methods
-[x] extract boolean methods -[x] extract boolean methods
-[x] encapsulate methods -[x] encapsulate methods
-[ ] isolate specific logics -[x] isolate specific logics
-[x] move specific logic to backstage -[x] move specific logic to backstage
-[x] move specific logic of sulfuras -[x] move specific logic of sulfuras

View File

@ -14,37 +14,37 @@ class GildedRose {
public void updateQuality() { public void updateQuality() {
for (int i = 0; i < items.length; i++) { for (int i = 0; i < items.length; i++) {
final Item item = items[i]; final Item item = items[i];
item.updateSellIn(); item.updateSellIn();
if(item.name.equals(Brie.BRIE)){ if(item.name.equals(Brie.BRIE)){
updateBrieQuality(item); updateBrieQuality(item);
}else if (item.name.equals(Backstage.BACKSTAGE)){ }else if (item.name.equals(Backstage.BACKSTAGE)){
updateBackstageQuality(item); updateBackstageQuality(item);
}else if (!item.name.equals(Sulfuras.SULFURAS)){
updateItemQuality(item);
} }
else if (!item.name.equals(Sulfuras.SULFURAS)){ }
if (!item.name.equals(Backstage.BACKSTAGE)) { }
if (item.quality > 0 && !item.name.equals(Sulfuras.SULFURAS)) {
item.decreaseQuality();
}
}
else {
if (item.quality < 50) {
item.increaseQuality();
}
}
if (item.sellIn < 0) { private void updateItemQuality(Item item) {
if (!item.name.equals(Backstage.BACKSTAGE)) { if (!item.name.equals(Backstage.BACKSTAGE)) {
if (!item.name.equals(Sulfuras.SULFURAS) && item.quality > 0) { if (item.quality > 0 ) {
item.decreaseQuality(); item.decreaseQuality();
} }
} else { }
item.quality = 0; else {
} if (item.quality < 50) {
item.increaseQuality();
}
}
if (item.sellIn < 0) {
if (!item.name.equals(Backstage.BACKSTAGE)) {
if ( item.quality > 0) {
item.decreaseQuality();
} }
} else {
item.quality = 0;
} }
} }
} }