diff --git a/Java/src/main/java/com/gildedrose/config/ProductFactory.java b/Java/src/main/java/com/gildedrose/config/ProductFactory.java new file mode 100644 index 00000000..9df197f8 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/config/ProductFactory.java @@ -0,0 +1,38 @@ +package com.gildedrose.config; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +import com.gildedrose.enums.ProductType; +import com.gildedrose.generic.ItemType; +import com.gildedrose.types.AgedBrie; +import com.gildedrose.types.Backstage; +import com.gildedrose.types.Others; +import com.gildedrose.types.Sulfuras; + +/*** + * ProductFactory defines the instance of each items based on description of the item + * @author VIJAY G + * + */ +public class ProductFactory { + + @SuppressWarnings("rawtypes") + private static Map productMap = new HashMap<>(); + static { + productMap.put(ProductType.AGED_BRIE, new AgedBrie()); + productMap.put(ProductType.SULFURAS, new Sulfuras()); + productMap.put(ProductType.BACKSTAGE_PASSES, new Backstage()); + } + + @SuppressWarnings("rawtypes") + public static ItemType get(ProductType productType) { + ItemType itemType = productMap.get(productType); + if(Objects.isNull(itemType)) { + return new Others(); + } + return itemType; + } + +} diff --git a/Java/src/main/java/com/gildedrose/enums/ProductType.java b/Java/src/main/java/com/gildedrose/enums/ProductType.java new file mode 100644 index 00000000..833f9e9e --- /dev/null +++ b/Java/src/main/java/com/gildedrose/enums/ProductType.java @@ -0,0 +1,27 @@ +package com.gildedrose.enums; + +/*** + * ProductType describes the type of Items + * @author VIJAY G + * + */ +public enum ProductType { + + AGED_BRIE("Aged Brie"), + BACKSTAGE_PASSES("Backstage passes to a TAFKAL80ETC concert"), + SULFURAS("Sulfuras, Hand of Ragnaros"); + + private final String productName; + + private ProductType(String productName) { + this.productName = productName; + } + + public static ProductType getEnumByString(String code){ + for(ProductType e : ProductType.values()){ + if(e.productName.equals(code)) return e.valueOf(e.name()); + } + return null; + } + +} diff --git a/Java/src/main/java/com/gildedrose/types/AgedBrie.java b/Java/src/main/java/com/gildedrose/types/AgedBrie.java new file mode 100644 index 00000000..b1112474 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/types/AgedBrie.java @@ -0,0 +1,23 @@ +package com.gildedrose.types; + +import com.gildedrose.Item; +import com.gildedrose.enums.CountType; +import com.gildedrose.generic.ItemType; + +/*** + * "Aged Brie" actually increases in Quality the older it gets + * the Quality of an item is never more than 50 + * @author VIJAY G + * + */ +public class AgedBrie extends ItemType { + + public AgedBrie() { + super(false, CountType.MINUS, CountType.PLUS); + } + + public int getIncrementor(Item item) { + return (item.sellIn <= 0) ? 2 : INCREMENTOR; + } + +} diff --git a/Java/src/main/java/com/gildedrose/types/Backstage.java b/Java/src/main/java/com/gildedrose/types/Backstage.java new file mode 100644 index 00000000..a3c8229f --- /dev/null +++ b/Java/src/main/java/com/gildedrose/types/Backstage.java @@ -0,0 +1,22 @@ +package com.gildedrose.types; + +import com.gildedrose.Item; +import com.gildedrose.enums.CountType; +import com.gildedrose.generic.ItemType; + +/*** + * "Backstage passes", like aged brie, increases in Quality as its SellIn value approaches; + * @author VIJAY G + * + */ +public class Backstage extends ItemType { + + public Backstage() { + super(true, CountType.MINUS, CountType.PLUS); + } + + public boolean isNeutralized(Item item) { + return (item.sellIn < 0) ? true : false; + } + +} diff --git a/Java/src/main/java/com/gildedrose/types/Others.java b/Java/src/main/java/com/gildedrose/types/Others.java new file mode 100644 index 00000000..bf3d4c25 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/types/Others.java @@ -0,0 +1,18 @@ +package com.gildedrose.types; + +import com.gildedrose.enums.CountType; +import com.gildedrose.generic.ItemType; + +/*** + * Once the sell by date has passed, Quality degrades twice as fast + * The Quality of an item is never negative + * @author VIJAY G + * + */ +public class Others extends ItemType { + + public Others() { + super(false, CountType.MINUS, CountType.MINUS); + } + +} diff --git a/Java/src/main/java/com/gildedrose/types/Sulfuras.java b/Java/src/main/java/com/gildedrose/types/Sulfuras.java new file mode 100644 index 00000000..b484c121 --- /dev/null +++ b/Java/src/main/java/com/gildedrose/types/Sulfuras.java @@ -0,0 +1,17 @@ +package com.gildedrose.types; + +import com.gildedrose.enums.CountType; +import com.gildedrose.generic.ItemType; + +/*** + * "Sulfuras", being a legendary item, never has to be sold or decreases in Quality + * @author VIJAY G + * + */ +public class Sulfuras extends ItemType { + + public Sulfuras() { + super(true, CountType.NONE, CountType.NONE); + } + +}