mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
refactoring for reusable variables and methods
This commit is contained in:
parent
380e476f42
commit
b387593ed4
@ -2,61 +2,81 @@ package com.gildedrose;
|
|||||||
|
|
||||||
class GildedRose {
|
class GildedRose {
|
||||||
Item[] items;
|
Item[] items;
|
||||||
|
private String brie = "Aged Brie";
|
||||||
|
private String backstagePass = "Backstage passes to a TAFKAL80ETC concert";
|
||||||
|
private String sulfuras = "Sulfuras, Hand of Ragnaros";
|
||||||
|
|
||||||
public GildedRose(Item[] items) {
|
public GildedRose(Item[] items) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
for (int i = 0; i < items.length; i++) {
|
//for (int i = 0; i < items.length; i++) {
|
||||||
if (!items[i].name.equals("Aged Brie")
|
for (Item item : items){ //switching to for each for better readability and simplicity
|
||||||
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (!item.name.equals(brie)
|
||||||
if (items[i].quality > 0) {
|
&& !item.name.equals(backstagePass)) {
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (qualityGreaterThanZero(item)){
|
||||||
items[i].quality = items[i].quality - 1;
|
if (!item.name.equals(sulfuras)) {
|
||||||
|
decreaseQuality(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (items[i].quality < 50) {
|
if(qualityLessThanFifty(item)){
|
||||||
items[i].quality = items[i].quality + 1;
|
increaseQuality(item);
|
||||||
|
|
||||||
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (item.name.equals(backstagePass)) {
|
||||||
if (items[i].sellIn < 11) {
|
if (checkSellIn(item, 11) && qualityLessThanFifty(item)){
|
||||||
if (items[i].quality < 50) {
|
increaseQuality(item);
|
||||||
items[i].quality = items[i].quality + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (checkSellIn(item, 6) && qualityLessThanFifty(item)){
|
||||||
if (items[i].sellIn < 6) {
|
increaseQuality(item);
|
||||||
if (items[i].quality < 50) {
|
|
||||||
items[i].quality = items[i].quality + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
if (!item.name.equals(sulfuras)) {
|
||||||
items[i].sellIn = items[i].sellIn - 1;
|
decreaseSellIn(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (items[i].sellIn < 0) {
|
if (checkSellIn(item, 0)){
|
||||||
if (!items[i].name.equals("Aged Brie")) {
|
if (!item.name.equals(brie)) {
|
||||||
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
if (!item.name.equals(backstagePass) && qualityGreaterThanZero(item) && !item.name.equals(sulfuras)) {
|
||||||
if (items[i].quality > 0) {
|
decreaseQuality(item);
|
||||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
|
||||||
items[i].quality = items[i].quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
items[i].quality = items[i].quality - items[i].quality;
|
item.quality = item.quality - item.quality;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (items[i].quality < 50) {
|
if(qualityLessThanFifty(item)){
|
||||||
items[i].quality = items[i].quality + 1;
|
increaseQuality(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Adding methods for repeatable usage
|
||||||
|
private boolean qualityGreaterThanZero(Item item){
|
||||||
|
return item.quality > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean qualityLessThanFifty(Item item){
|
||||||
|
return item.quality < 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int increaseQuality(Item item){
|
||||||
|
return item.quality++;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int decreaseQuality(Item item){
|
||||||
|
return item.quality--;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkSellIn (Item item, int numCheck){
|
||||||
|
return item.sellIn < numCheck;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int decreaseSellIn (Item item){
|
||||||
|
return item.sellIn--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user