mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-14 22:21:20 +00:00
refactorings
This commit is contained in:
parent
56f0c5d5f8
commit
a2b84d2659
BIN
Java/.DS_Store
vendored
Normal file
BIN
Java/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
Java/src/.DS_Store
vendored
Normal file
BIN
Java/src/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
Java/src/main/.DS_Store
vendored
Normal file
BIN
Java/src/main/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
Java/src/main/java/.DS_Store
vendored
Normal file
BIN
Java/src/main/java/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
Java/src/main/java/com/.DS_Store
vendored
Normal file
BIN
Java/src/main/java/com/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
Java/src/main/java/com/gildedrose/.DS_Store
vendored
Normal file
BIN
Java/src/main/java/com/gildedrose/.DS_Store
vendored
Normal file
Binary file not shown.
@ -1,62 +1,43 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import com.gildedrose.item.Item;
|
||||
import com.gildedrose.item.ItemFactory;
|
||||
|
||||
class GildedRose {
|
||||
|
||||
private static final int LOWEST_QUALITY_LEVEL_POSSIBLE = 0;
|
||||
private static final int HIGHEST_QUALITY_LEVEL_POSSIBLE = 50;
|
||||
private final ItemFactory itemFactory;
|
||||
Item[] items;
|
||||
|
||||
public GildedRose(Item[] items) {
|
||||
this.itemFactory = new ItemFactory();
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public void updateQuality() {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (!items[i].name.equals("Aged Brie")
|
||||
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].quality > 0) {
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].quality = items[i].quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
|
||||
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].sellIn < 11) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 6) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].sellIn = items[i].sellIn - 1;
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 0) {
|
||||
if (!items[i].name.equals("Aged Brie")) {
|
||||
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].quality > 0) {
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].quality = items[i].quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
items[i].quality = items[i].quality - items[i].quality;
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
}
|
||||
}
|
||||
customizeItems();
|
||||
for (Item item : items) {
|
||||
item.updateYourState();
|
||||
if (hasReachedLowestQualityLimit(item.quality)) {
|
||||
item.quality = LOWEST_QUALITY_LEVEL_POSSIBLE;
|
||||
} else if (hasReachedHighestQualityLimit(item.quality)) {
|
||||
item.quality = HIGHEST_QUALITY_LEVEL_POSSIBLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void customizeItems() {
|
||||
for (Item item : items) {
|
||||
items = new Item[]{itemFactory.createItem(item.name, item.sellIn, item.quality)};
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasReachedLowestQualityLimit(int itemQuality) {
|
||||
return itemQuality < LOWEST_QUALITY_LEVEL_POSSIBLE;
|
||||
}
|
||||
|
||||
private boolean hasReachedHighestQualityLimit(int itemQuality) {
|
||||
return itemQuality > HIGHEST_QUALITY_LEVEL_POSSIBLE;
|
||||
}
|
||||
}
|
||||
13
Java/src/main/java/com/gildedrose/item/AgedBrie.java
Normal file
13
Java/src/main/java/com/gildedrose/item/AgedBrie.java
Normal file
@ -0,0 +1,13 @@
|
||||
package com.gildedrose.item;
|
||||
|
||||
public class AgedBrie extends Item {
|
||||
|
||||
public AgedBrie(String name, int sellIn, int quality) {
|
||||
super(name, sellIn, quality);
|
||||
}
|
||||
|
||||
public void updateYourState() {
|
||||
sellIn -= 1;
|
||||
quality += 1;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.gildedrose.item;
|
||||
|
||||
public class BackstagePassesItem extends Item {
|
||||
|
||||
public BackstagePassesItem(String name, int sellIn, int quality) {
|
||||
super(name, sellIn, quality);
|
||||
}
|
||||
|
||||
public void updateYourState() {
|
||||
sellIn -= 1;
|
||||
if (sellIn >= 11) {
|
||||
quality += 1;
|
||||
} else if (sellIn > 5) {
|
||||
quality += 2;
|
||||
} else if (sellIn > 0) {
|
||||
quality += 3;
|
||||
} else {
|
||||
quality = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.gildedrose;
|
||||
package com.gildedrose.item;
|
||||
|
||||
public class Item {
|
||||
|
||||
@ -14,8 +14,11 @@ public class Item {
|
||||
this.quality = quality;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name + ", " + this.sellIn + ", " + this.quality;
|
||||
}
|
||||
|
||||
public void updateYourState() {
|
||||
}
|
||||
}
|
||||
16
Java/src/main/java/com/gildedrose/item/ItemFactory.java
Normal file
16
Java/src/main/java/com/gildedrose/item/ItemFactory.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.gildedrose.item;
|
||||
|
||||
public class ItemFactory {
|
||||
|
||||
public Item createItem(String itemName, int sellIn, int quality) {
|
||||
if (itemName.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
return new Sulfuras(itemName, sellIn, quality);
|
||||
} else if (itemName.equals("Aged Brie")) {
|
||||
return new AgedBrie(itemName, sellIn, quality);
|
||||
} else if (itemName.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
return new BackstagePassesItem(itemName, sellIn, quality);
|
||||
} else {
|
||||
return new StandardItem(itemName, sellIn, quality);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Java/src/main/java/com/gildedrose/item/StandardItem.java
Normal file
17
Java/src/main/java/com/gildedrose/item/StandardItem.java
Normal file
@ -0,0 +1,17 @@
|
||||
package com.gildedrose.item;
|
||||
|
||||
public class StandardItem extends Item {
|
||||
|
||||
public StandardItem(String name, int sellIn, int quality) {
|
||||
super(name, sellIn, quality);
|
||||
}
|
||||
|
||||
public void updateYourState() {
|
||||
sellIn -= 1;
|
||||
if (sellIn > 0) {
|
||||
quality -= 1;
|
||||
} else {
|
||||
quality -= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Java/src/main/java/com/gildedrose/item/Sulfuras.java
Normal file
11
Java/src/main/java/com/gildedrose/item/Sulfuras.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.gildedrose.item;
|
||||
|
||||
public class Sulfuras extends Item {
|
||||
|
||||
public Sulfuras(String name, int sellIn, int quality) {
|
||||
super(name, sellIn, quality);
|
||||
}
|
||||
|
||||
public void updateYourState() {
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import com.gildedrose.item.Item;
|
||||
|
||||
public class TexttestFixture {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("OMGHAI!");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user