mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Configurations for individual item types
This commit is contained in:
parent
fb969858cb
commit
d1f7a4c85e
38
Java/src/main/java/com/gildedrose/config/ProductFactory.java
Normal file
38
Java/src/main/java/com/gildedrose/config/ProductFactory.java
Normal file
@ -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<ProductType, ItemType> 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;
|
||||
}
|
||||
|
||||
}
|
||||
27
Java/src/main/java/com/gildedrose/enums/ProductType.java
Normal file
27
Java/src/main/java/com/gildedrose/enums/ProductType.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
23
Java/src/main/java/com/gildedrose/types/AgedBrie.java
Normal file
23
Java/src/main/java/com/gildedrose/types/AgedBrie.java
Normal file
@ -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<AgedBrie> {
|
||||
|
||||
public AgedBrie() {
|
||||
super(false, CountType.MINUS, CountType.PLUS);
|
||||
}
|
||||
|
||||
public int getIncrementor(Item item) {
|
||||
return (item.sellIn <= 0) ? 2 : INCREMENTOR;
|
||||
}
|
||||
|
||||
}
|
||||
22
Java/src/main/java/com/gildedrose/types/Backstage.java
Normal file
22
Java/src/main/java/com/gildedrose/types/Backstage.java
Normal file
@ -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<Backstage> {
|
||||
|
||||
public Backstage() {
|
||||
super(true, CountType.MINUS, CountType.PLUS);
|
||||
}
|
||||
|
||||
public boolean isNeutralized(Item item) {
|
||||
return (item.sellIn < 0) ? true : false;
|
||||
}
|
||||
|
||||
}
|
||||
18
Java/src/main/java/com/gildedrose/types/Others.java
Normal file
18
Java/src/main/java/com/gildedrose/types/Others.java
Normal file
@ -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<Others> {
|
||||
|
||||
public Others() {
|
||||
super(false, CountType.MINUS, CountType.MINUS);
|
||||
}
|
||||
|
||||
}
|
||||
17
Java/src/main/java/com/gildedrose/types/Sulfuras.java
Normal file
17
Java/src/main/java/com/gildedrose/types/Sulfuras.java
Normal file
@ -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<Sulfuras> {
|
||||
|
||||
public Sulfuras() {
|
||||
super(true, CountType.NONE, CountType.NONE);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user