mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +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 {
|
class GildedRose {
|
||||||
Item[] items;
|
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) {
|
public GildedRose(Item[] items) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
@ -26,53 +29,57 @@ class GildedRose {
|
|||||||
private boolean itemHasExpired(Item item) {
|
private boolean itemHasExpired(Item item) {
|
||||||
boolean condition;
|
boolean condition;
|
||||||
if (item.sellIn < 0) {
|
if (item.sellIn < 0) {
|
||||||
condition=true;
|
condition = true;
|
||||||
} else {
|
} else {
|
||||||
condition=false;
|
condition = false;
|
||||||
}
|
}
|
||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateQuality() {
|
private void decreaseQualityTwice(Item item) {
|
||||||
String SULFURA = "Sulfuras, Hand of Ragnaros";
|
decreaseQuality(item);
|
||||||
String AGED_BRIE = "Aged Brie";
|
decreaseQuality(item);
|
||||||
String BACKSTAGE = "Backstage passes to a TAFKAL80ETC concert";
|
}
|
||||||
|
|
||||||
|
private void updateAgedBrieQuaility(Item item) {
|
||||||
|
increaseQuality(item);
|
||||||
|
if (itemHasExpired(item)) {
|
||||||
|
increaseQuality(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (Item item : items) {
|
private void updateBackstageQuaility(Item item) {
|
||||||
if (item.name.equals(SULFURA)) {
|
increaseQuality(item);
|
||||||
continue;
|
if (item.sellIn < 10) {
|
||||||
}
|
increaseQuality(item);
|
||||||
|
}
|
||||||
updateNumberOfdayToSellRemaining(item);
|
if (item.sellIn < 5) {
|
||||||
|
increaseQuality(item);
|
||||||
if (item.name.equals(AGED_BRIE)) {
|
}
|
||||||
increaseQuality(item);
|
if (itemHasExpired(item)) {
|
||||||
} else if (item.name.equals(BACKSTAGE)) {
|
item.quality -= item.quality;
|
||||||
increaseQuality(item);
|
}
|
||||||
|
}
|
||||||
if (item.sellIn < 10) {
|
|
||||||
increaseQuality(item);
|
|
||||||
}
|
|
||||||
if (item.sellIn < 5) {
|
|
||||||
increaseQuality(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
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 {
|
} else {
|
||||||
decreaseQuality(item);
|
decreaseQuality(item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateQuality() {
|
||||||
if (itemHasExpired(item)) {
|
for (Item item : items) {
|
||||||
if (item.name.equals(AGED_BRIE)) {
|
if (item.name.equals(SULFURA)) {continue;}
|
||||||
increaseQuality(item);
|
updateNumberOfdayToSellRemaining(item);
|
||||||
} else if (item.name.equals(BACKSTAGE)) {
|
updateQualityItem(item);
|
||||||
item.quality -= item.quality;
|
|
||||||
} else {
|
|
||||||
decreaseQuality(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user