mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Create small functions instead of big ones
This commit is contained in:
parent
a273600de7
commit
f0ed10d078
@ -2,6 +2,9 @@ package com.gildedrose;
|
||||
|
||||
class GildedRose {
|
||||
Item[] items;
|
||||
String SULFURA = "Sulfuras, Hand of Ragnaros";
|
||||
String AGED_BRIE = "Aged Brie";
|
||||
String BACKSTAGE = "Backstage passes to a TAFKAL80ETC concert";
|
||||
|
||||
public GildedRose(Item[] items) {
|
||||
this.items = items;
|
||||
@ -26,53 +29,57 @@ class GildedRose {
|
||||
private boolean itemHasExpired(Item item) {
|
||||
boolean condition;
|
||||
if (item.sellIn < 0) {
|
||||
condition=true;
|
||||
condition = true;
|
||||
} else {
|
||||
condition=false;
|
||||
condition = false;
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
public void updateQuality() {
|
||||
String SULFURA = "Sulfuras, Hand of Ragnaros";
|
||||
String AGED_BRIE = "Aged Brie";
|
||||
String BACKSTAGE = "Backstage passes to a TAFKAL80ETC concert";
|
||||
private void decreaseQualityTwice(Item item) {
|
||||
decreaseQuality(item);
|
||||
decreaseQuality(item);
|
||||
}
|
||||
|
||||
private void updateAgedBrieQuaility(Item item) {
|
||||
increaseQuality(item);
|
||||
if (itemHasExpired(item)) {
|
||||
increaseQuality(item);
|
||||
}
|
||||
}
|
||||
|
||||
for (Item item : items) {
|
||||
if (item.name.equals(SULFURA)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
updateNumberOfdayToSellRemaining(item);
|
||||
|
||||
if (item.name.equals(AGED_BRIE)) {
|
||||
increaseQuality(item);
|
||||
} else if (item.name.equals(BACKSTAGE)) {
|
||||
increaseQuality(item);
|
||||
|
||||
if (item.sellIn < 10) {
|
||||
increaseQuality(item);
|
||||
}
|
||||
if (item.sellIn < 5) {
|
||||
increaseQuality(item);
|
||||
}
|
||||
private void updateBackstageQuaility(Item item) {
|
||||
increaseQuality(item);
|
||||
if (item.sellIn < 10) {
|
||||
increaseQuality(item);
|
||||
}
|
||||
if (item.sellIn < 5) {
|
||||
increaseQuality(item);
|
||||
}
|
||||
if (itemHasExpired(item)) {
|
||||
item.quality -= item.quality;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateQualityItem(Item item) {
|
||||
if (item.name.equals(AGED_BRIE)) {
|
||||
updateAgedBrieQuaility(item);
|
||||
} else if (item.name.equals(BACKSTAGE)) {
|
||||
updateBackstageQuaility(item);
|
||||
} else {
|
||||
if (itemHasExpired(item)) {
|
||||
decreaseQualityTwice(item);
|
||||
} else {
|
||||
decreaseQuality(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (itemHasExpired(item)) {
|
||||
if (item.name.equals(AGED_BRIE)) {
|
||||
increaseQuality(item);
|
||||
} else if (item.name.equals(BACKSTAGE)) {
|
||||
item.quality -= item.quality;
|
||||
} else {
|
||||
decreaseQuality(item);
|
||||
}
|
||||
|
||||
}
|
||||
public void updateQuality() {
|
||||
for (Item item : items) {
|
||||
if (item.name.equals(SULFURA)) {continue;}
|
||||
updateNumberOfdayToSellRemaining(item);
|
||||
updateQualityItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user