From f0ed10d078f4badab0b736be4af6d410072414d9 Mon Sep 17 00:00:00 2001 From: brianblessou Date: Sun, 12 May 2019 15:43:20 +0200 Subject: [PATCH] Create small functions instead of big ones --- .../main/java/com/gildedrose/GildedRose.java | 77 ++++++++++--------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/Java/src/main/java/com/gildedrose/GildedRose.java b/Java/src/main/java/com/gildedrose/GildedRose.java index 8291199a..b18565a4 100644 --- a/Java/src/main/java/com/gildedrose/GildedRose.java +++ b/Java/src/main/java/com/gildedrose/GildedRose.java @@ -2,6 +2,9 @@ package com.gildedrose; class GildedRose { Item[] items; + String SULFURA = "Sulfuras, Hand of Ragnaros"; + String AGED_BRIE = "Aged Brie"; + String BACKSTAGE = "Backstage passes to a TAFKAL80ETC concert"; public GildedRose(Item[] items) { this.items = items; @@ -26,53 +29,57 @@ class GildedRose { private boolean itemHasExpired(Item item) { boolean condition; if (item.sellIn < 0) { - condition=true; + condition = true; } else { - condition=false; + condition = false; } return condition; } - public void updateQuality() { - String SULFURA = "Sulfuras, Hand of Ragnaros"; - String AGED_BRIE = "Aged Brie"; - String BACKSTAGE = "Backstage passes to a TAFKAL80ETC concert"; + private void decreaseQualityTwice(Item item) { + decreaseQuality(item); + decreaseQuality(item); + } + private void updateAgedBrieQuaility(Item item) { + increaseQuality(item); + if (itemHasExpired(item)) { + increaseQuality(item); + } + } - for (Item item : items) { - if (item.name.equals(SULFURA)) { - continue; - } - - updateNumberOfdayToSellRemaining(item); - - if (item.name.equals(AGED_BRIE)) { - increaseQuality(item); - } else if (item.name.equals(BACKSTAGE)) { - increaseQuality(item); - - if (item.sellIn < 10) { - increaseQuality(item); - } - if (item.sellIn < 5) { - increaseQuality(item); - } + private void updateBackstageQuaility(Item item) { + increaseQuality(item); + if (item.sellIn < 10) { + increaseQuality(item); + } + if (item.sellIn < 5) { + increaseQuality(item); + } + if (itemHasExpired(item)) { + item.quality -= item.quality; + } + } + private void updateQualityItem(Item item) { + if (item.name.equals(AGED_BRIE)) { + updateAgedBrieQuaility(item); + } else if (item.name.equals(BACKSTAGE)) { + updateBackstageQuaility(item); + } else { + if (itemHasExpired(item)) { + decreaseQualityTwice(item); } else { decreaseQuality(item); } + } + } - - if (itemHasExpired(item)) { - if (item.name.equals(AGED_BRIE)) { - increaseQuality(item); - } else if (item.name.equals(BACKSTAGE)) { - item.quality -= item.quality; - } else { - decreaseQuality(item); - } - - } + public void updateQuality() { + for (Item item : items) { + if (item.name.equals(SULFURA)) {continue;} + updateNumberOfdayToSellRemaining(item); + updateQualityItem(item); } } }