mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-20 08:51:08 +00:00
Finish refactor
This commit is contained in:
parent
54ec015566
commit
4421c7066a
@ -1,6 +1,6 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
import static com.gildedrose.Constants.*;
|
import static com.gildedrose.Constants.MAX_QUALITY;
|
||||||
|
|
||||||
public class AgedBrie extends InventoryItem {
|
public class AgedBrie extends InventoryItem {
|
||||||
public AgedBrie(Item item) {
|
public AgedBrie(Item item) {
|
||||||
@ -9,52 +9,10 @@ public class AgedBrie extends InventoryItem {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
void age() {
|
void age() {
|
||||||
if (item.name.equals(AGED_BRIE)
|
if (item.quality < MAX_QUALITY) {
|
||||||
|| item.name.equals(BACKSTAGE)) {
|
item.quality++;
|
||||||
if (item.quality < 50) {
|
|
||||||
item.quality = item.quality + 1;
|
|
||||||
|
|
||||||
if (item.name.equals(BACKSTAGE)) {
|
|
||||||
if (item.sellIn < 11) {
|
|
||||||
if (item.quality < 50) {
|
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.sellIn < 6) {
|
|
||||||
if (item.quality < 50) {
|
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (item.quality > 0) {
|
|
||||||
if (!item.name.equals(SULFURAS)) {
|
|
||||||
item.quality = item.quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!item.name.equals(SULFURAS)) {
|
|
||||||
item.sellIn = item.sellIn - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.sellIn < 0) {
|
|
||||||
if (item.name.equals(AGED_BRIE)) {
|
|
||||||
if (item.quality < 50) {
|
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!item.name.equals(BACKSTAGE)) {
|
|
||||||
if (item.quality > 0) {
|
|
||||||
if (!item.name.equals(SULFURAS)) {
|
|
||||||
item.quality = item.quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
item.quality = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
decreaseSellIn();
|
||||||
|
if (item.sellIn < Constants.SELLIN_DAY && item.quality < MAX_QUALITY) item.quality++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,60 +1,19 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
import static com.gildedrose.Constants.*;
|
|
||||||
|
|
||||||
public class Backstage extends InventoryItem {
|
public class Backstage extends InventoryItem {
|
||||||
|
|
||||||
public Backstage(Item item) {
|
public Backstage(Item item) {
|
||||||
super(item);
|
super(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void age() {
|
void age() {
|
||||||
if (item.name.equals(AGED_BRIE)
|
if (item.quality < Constants.MAX_QUALITY) {
|
||||||
|| item.name.equals(BACKSTAGE)) {
|
item.quality = item.quality + 1;
|
||||||
if (item.quality < 50) {
|
if (item.sellIn < 11 && item.quality < Constants.MAX_QUALITY) item.quality++;
|
||||||
item.quality = item.quality + 1;
|
if (item.sellIn < 6 && item.quality < Constants.MAX_QUALITY) item.quality++;
|
||||||
|
|
||||||
if (item.name.equals(BACKSTAGE)) {
|
|
||||||
if (item.sellIn < 11) {
|
|
||||||
if (item.quality < 50) {
|
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.sellIn < 6) {
|
|
||||||
if (item.quality < 50) {
|
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (item.quality > 0) {
|
|
||||||
if (!item.name.equals(SULFURAS)) {
|
|
||||||
item.quality = item.quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!item.name.equals(SULFURAS)) {
|
|
||||||
item.sellIn = item.sellIn - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.sellIn < 0) {
|
|
||||||
if (item.name.equals(AGED_BRIE)) {
|
|
||||||
if (item.quality < 50) {
|
|
||||||
item.quality = item.quality + 1;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!item.name.equals(BACKSTAGE)) {
|
|
||||||
if (item.quality > 0) {
|
|
||||||
if (!item.name.equals(SULFURAS)) {
|
|
||||||
item.quality = item.quality - 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
item.quality = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
decreaseSellIn();
|
||||||
|
if (item.sellIn < Constants.SELLIN_DAY) item.quality = Constants.MIN_QUALITY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,10 @@ public final class Constants {
|
|||||||
public static final String BACKSTAGE = "Backstage passes to a TAFKAL80ETC concert";
|
public static final String BACKSTAGE = "Backstage passes to a TAFKAL80ETC concert";
|
||||||
public static final String AGED_BRIE = "Aged Brie";
|
public static final String AGED_BRIE = "Aged Brie";
|
||||||
public static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
|
public static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
|
||||||
|
public static final int MAX_QUALITY = 50;
|
||||||
|
public static final int MIN_QUALITY = 0;
|
||||||
|
public static final int SELLIN_DAY = 0;
|
||||||
|
|
||||||
private Constants() {
|
private Constants() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,10 +23,10 @@ public class InventoryItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void decreaseSellIn() {
|
protected void decreaseSellIn() {
|
||||||
item.sellIn = item.sellIn - 1;
|
item.sellIn--;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void decreaseQuality() {
|
protected void decreaseQuality() {
|
||||||
if (item.quality > 0) item.quality = item.quality - 1;
|
if (item.quality > 0) item.quality--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user