From 58220c23580fce162bc9b279789b0ce3e705305f Mon Sep 17 00:00:00 2001 From: Sallah Kokaina Date: Fri, 1 Nov 2019 19:41:57 +0100 Subject: [PATCH] logic nesting removed --- Java/README.md | 8 ++-- .../main/java/com/gildedrose/GildedRose.java | 44 +++++++++---------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Java/README.md b/Java/README.md index 08d32224..4cf42d11 100644 --- a/Java/README.md +++ b/Java/README.md @@ -24,10 +24,10 @@ ## Technical Issues, with a balanced priority -[x] item names are hardcoded -[x] items are identified by the name in a hardcoded way --[ ] nested logic +-[x] nested logic -[x] long method --[ ] plain logic --[ ] complex operations +-[x] plain logic +-[x] complex operations -[x] Item properties are public -[x] multiple access by index @@ -38,6 +38,6 @@ -[x] extract methods -[x] extract boolean methods -[x] encapsulate methods --[ ] isolate specific logics +-[x] isolate specific logics -[x] move specific logic to backstage -[x] move specific logic of sulfuras diff --git a/Java/src/main/java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java index ce562afb..7e413e13 100644 --- a/Java/src/main/java/com/gildedrose/GildedRose.java +++ b/Java/src/main/java/com/gildedrose/GildedRose.java @@ -14,37 +14,37 @@ class GildedRose { public void updateQuality() { for (int i = 0; i < items.length; i++) { - final Item item = items[i]; - item.updateSellIn(); - if(item.name.equals(Brie.BRIE)){ updateBrieQuality(item); }else if (item.name.equals(Backstage.BACKSTAGE)){ 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) { - if (!item.name.equals(Backstage.BACKSTAGE)) { - if (!item.name.equals(Sulfuras.SULFURAS) && item.quality > 0) { - item.decreaseQuality(); - } - } else { - item.quality = 0; - } + private void updateItemQuality(Item item) { + if (!item.name.equals(Backstage.BACKSTAGE)) { + if (item.quality > 0 ) { + item.decreaseQuality(); + } + } + 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; } } }