mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Extracted filters
This commit is contained in:
parent
e07bca923b
commit
94f18f669e
@ -6,16 +6,15 @@ import java.util.stream.Stream;
|
|||||||
class GildedRose {
|
class GildedRose {
|
||||||
Item[] items;
|
Item[] items;
|
||||||
|
|
||||||
public static String agedBrie = "Aged Brie";
|
|
||||||
public GildedRose(Item[] items) {
|
public GildedRose(Item[] items) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
Item[] agingItems = Arrays.stream(items).filter(i -> !i.name.toLowerCase().contains("sulfuras")).toArray(Item[]::new);
|
Item[] agingItems = Arrays.stream(items).filter(i -> !isSulfuras(i)).toArray(Item[]::new);
|
||||||
Stream<Item> bries = Arrays.stream(agingItems).filter(i -> i.name.equals(agedBrie));
|
Stream<Item> bries = Arrays.stream(agingItems).filter(this::isBrie);
|
||||||
Stream<Item> backstagePasses = Arrays.stream(agingItems).filter(this::isBackstagePass);
|
Stream<Item> backstagePasses = Arrays.stream(agingItems).filter(this::isBackstagePass);
|
||||||
Stream<Item> standardItems = Arrays.stream(agingItems).filter(i -> !isBackstagePass(i) && !i.name.equals(agedBrie));
|
Stream<Item> standardItems = Arrays.stream(agingItems).filter(i -> !(isBackstagePass(i) || isBrie(i)));
|
||||||
for (Item item : agingItems) {
|
for (Item item : agingItems) {
|
||||||
item.sellIn--;
|
item.sellIn--;
|
||||||
}
|
}
|
||||||
@ -47,5 +46,10 @@ class GildedRose {
|
|||||||
private boolean isBackstagePass(Item i) {
|
private boolean isBackstagePass(Item i) {
|
||||||
return i.name.toLowerCase().contains("backstage");
|
return i.name.toLowerCase().contains("backstage");
|
||||||
}
|
}
|
||||||
|
private boolean isSulfuras(Item i) {
|
||||||
|
return i.name.toLowerCase().contains("sulfuras");
|
||||||
|
}
|
||||||
|
private boolean isBrie(Item i) {
|
||||||
|
return i.name.equals("Aged Brie");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user