mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
More streams
This commit is contained in:
parent
eb0e2bad02
commit
36b6e62963
@ -1,6 +1,7 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
class GildedRose {
|
class GildedRose {
|
||||||
Item[] items;
|
Item[] items;
|
||||||
@ -8,28 +9,21 @@ class GildedRose {
|
|||||||
public static String backStagePasses = "Backstage passes to a TAFKAL80ETC concert";
|
public static String backStagePasses = "Backstage passes to a TAFKAL80ETC concert";
|
||||||
public static String sulfuras = "Sulfuras, Hand of Ragnaros";
|
public static String sulfuras = "Sulfuras, Hand of Ragnaros";
|
||||||
public static String agedBrie = "Aged Brie";
|
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.equals(sulfuras)).toArray(Item[]::new);
|
Item[] agingItems = Arrays.stream(items).filter(i -> !i.name.equals(sulfuras)).toArray(Item[]::new);
|
||||||
Item[] bries = Arrays.stream(agingItems).filter(i -> i.name.equals(agedBrie)).toArray(Item[]::new);
|
Stream<Item> bries = Arrays.stream(agingItems).filter(i -> i.name.equals(agedBrie));
|
||||||
Item[] backstagePasses = Arrays.stream(agingItems).filter(i -> i.name.equals(backStagePasses)).toArray(Item[]::new);
|
Stream<Item> backstagePasses = Arrays.stream(agingItems).filter(i -> i.name.equals(backStagePasses));
|
||||||
Item[] otherItems = Arrays.stream(agingItems).filter(i -> !i.name.equals(backStagePasses) && !i.name.equals(agedBrie)).toArray(Item[]::new);
|
Stream<Item> standardItems = Arrays.stream(agingItems).filter(i -> !i.name.equals(backStagePasses) && !i.name.equals(agedBrie));
|
||||||
for (Item item : otherItems) {
|
for (Item item : agingItems) {
|
||||||
item.sellIn = item.sellIn - 1;
|
item.sellIn--;
|
||||||
changeQualityOfStandardItems(item);
|
|
||||||
}
|
|
||||||
for (Item brie : bries) {
|
|
||||||
brie.sellIn = brie.sellIn - 1;
|
|
||||||
changeQualityOfBries(brie);
|
|
||||||
}
|
|
||||||
for (Item item : backstagePasses) {
|
|
||||||
item.sellIn = item.sellIn - 1;
|
|
||||||
changeQualityOfPasses(item);
|
|
||||||
}
|
}
|
||||||
|
bries.forEach(this::changeQualityOfBries);
|
||||||
|
backstagePasses.forEach(this::changeQualityOfPasses);
|
||||||
|
standardItems.forEach(this::changeQualityOfStandardItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeQuality(Item item, int factor) {
|
private void changeQuality(Item item, int factor) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user