Skip to content

Commit

Permalink
Initial refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sandromancuso committed Jan 10, 2012
1 parent 708cdb5 commit 6a50c67
Showing 1 changed file with 68 additions and 93 deletions.
161 changes: 68 additions & 93 deletions src/main/java/org/gildedrose/GildedRose.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.gildedrose;

import java.util.ArrayList;
import java.util.List;



public class GildedRose {

private static List<Item> items = null;
Expand All @@ -12,96 +11,72 @@ public class GildedRose {
* @param args
*/
public static void main(String[] args) {

System.out.println("OMGHAI!");

items = new ArrayList<Item>();
items.add(new Item("+5 Dexterity Vest", 10, 20));
items.add(new Item("Aged Brie", 2, 0));
items.add(new Item("Elixir of the Mongoose", 5, 7));
items.add(new Item("Sulfuras, Hand of Ragnaros", 0, 80));
items.add(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20));
items.add(new Item("Conjured Mana Cake", 3, 6));

updateQuality(items);
}



public static void updateQuality(List<Item> items)
{
for (int i = 0; i < items.size(); i++)
{
if ((!"Aged Brie".equals(items.get(i).getName())) && !"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
{
if (items.get(i).getQuality() > 0)
{
if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
{
items.get(i).setQuality(items.get(i).getQuality() - 1);
}
}
}
else
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);

if ("Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
{
if (items.get(i).getSellIn() < 11)
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);
}
}

if (items.get(i).getSellIn() < 6)
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);
}
}
}
}
}

if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
{
items.get(i).setSellIn(items.get(i).getSellIn() - 1);
}

if (items.get(i).getSellIn() < 0)
{
if (!"Aged Brie".equals(items.get(i).getName()))
{
if (!"Backstage passes to a TAFKAL80ETC concert".equals(items.get(i).getName()))
{
if (items.get(i).getQuality() > 0)
{
if (!"Sulfuras, Hand of Ragnaros".equals(items.get(i).getName()))
{
items.get(i).setQuality(items.get(i).getQuality() - 1);
}
}
}
else
{
items.get(i).setQuality(items.get(i).getQuality() - items.get(i).getQuality());
}
}
else
{
if (items.get(i).getQuality() < 50)
{
items.get(i).setQuality(items.get(i).getQuality() + 1);
}
}
}
}
}

System.out.println("OMGHAI!");

items = new ArrayList<Item>();
items.add(new Item("+5 Dexterity Vest", 10, 20));
items.add(new Item("Aged Brie", 2, 0));
items.add(new Item("Elixir of the Mongoose", 5, 7));
items.add(new Item("Sulfuras, Hand of Ragnaros", 0, 80));
items.add(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20));
items.add(new Item("Conjured Mana Cake", 3, 6));

updateQuality(items);
}

public static void updateQuality(List<Item> items) {
for (Item item : items) {

if (!"Sulfuras, Hand of Ragnaros".equals(item.getName())) {
item.setSellIn(item.getSellIn() - 1);
}

if (qualityCanBeIncreasedFor(item)) {
increaseQuality(item);
}

if (qualityCanBeDecreasedFor(item)) {
item.setQuality(item.getQuality() - 1);
if (item.getSellIn() < 0) {
item.setQuality(item.getQuality() - 1);
}
}

if (item.getSellIn() < 0 && !qualityCanBeDecreasedFor(item)) {
item.setQuality(0);
}

}
}

protected static void increaseQuality(Item item) {
item.setQuality(item.getQuality() + 1);

if ("Backstage passes to a TAFKAL80ETC concert".equals(item.getName())) {
if (item.getSellIn() < 11 && item.getQuality() < 50) {
item.setQuality(item.getQuality() + 1);
}

if (item.getSellIn() < 6 && item.getQuality() < 50) {
item.setQuality(item.getQuality() + 1);
}
}
}

private static boolean qualityCanBeIncreasedFor(Item item) {
return !qualityDecreasesAsItGetsOlder(item) && item.getQuality() < 50;
}

private static boolean qualityCanBeDecreasedFor(Item item) {
return qualityDecreasesAsItGetsOlder(item)
&& item.getQuality() > 0
&& !"Sulfuras, Hand of Ragnaros".equals(item.getName());
}

private static boolean qualityDecreasesAsItGetsOlder(Item item) {
return !"Aged Brie".equals(item.getName())
&& !"Backstage passes to a TAFKAL80ETC concert".equals(item.getName());
}

}

0 comments on commit 6a50c67

Please sign in to comment.