mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
refactor: adding a guard clause for Sulfuras item to avoid to check later on
This commit is contained in:
parent
6154339c39
commit
e326caf567
@ -9,6 +9,12 @@ class GildedRose {
|
|||||||
|
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
|
|
||||||
|
// to avoid to have to check it later on
|
||||||
|
if (items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// first if defnie what should decrease and what should increase
|
// first if defnie what should decrease and what should increase
|
||||||
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert") |
|
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert") |
|
||||||
items[i].name.equals("Aged Brie")) {
|
items[i].name.equals("Aged Brie")) {
|
||||||
@ -25,44 +31,32 @@ class GildedRose {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (items[i].quality > 0 & !items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
updateNormalAndConjuredItem(items[i]);
|
||||||
items[i].quality = items[i].quality - 1;
|
|
||||||
|
|
||||||
if (items[i].name.equals("Conjured Mana Cake") & items[i].quality > 0) {
|
|
||||||
items[i].quality = items[i].quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { // continue
|
items[i].sellIn = items[i].sellIn - 1;
|
||||||
items[i].sellIn = items[i].sellIn - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (items[i].sellIn < 0) {
|
if (items[i].sellIn < 0) {
|
||||||
if (items[i].name.equals("Aged Brie")) {
|
|
||||||
|
|
||||||
|
if (items[i].name.equals("Aged Brie")) {
|
||||||
if (items[i].quality < 50) {
|
if (items[i].quality < 50) {
|
||||||
items[i].quality = items[i].quality + 1;
|
items[i].quality = items[i].quality + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (items[i].name.equals("+5 Dexterity Vest") | items[i].name.equals("Elixir of the Mongoose") |
|
if (items[i].name.equals("+5 Dexterity Vest") | items[i].name.equals("Elixir of the Mongoose") |
|
||||||
items[i].name.equals("Conjured Mana Cake")) {
|
items[i].name.equals("Conjured Mana Cake")) {
|
||||||
updateItem(items[i]);
|
updateNormalAndConjuredItem(items[i]);
|
||||||
}
|
}
|
||||||
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||||
items[i].quality = items[i].quality - items[i].quality;
|
items[i].quality = items[i].quality - items[i].quality;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateItem(Item item) {
|
public void updateNormalAndConjuredItem(Item item) {
|
||||||
if (item.quality > 0 & !item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (item.quality > 0) {
|
||||||
item.quality = item.quality - 1;
|
item.quality = item.quality - 1;
|
||||||
|
|
||||||
if (item.name.equals("Conjured Mana Cake") && item.quality > 0) {
|
if (item.name.equals("Conjured Mana Cake") && item.quality > 0) {
|
||||||
item.quality = item.quality - 1;
|
item.quality = item.quality - 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user