mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Add missing javadoc
This commit is contained in:
parent
cc53ad07e0
commit
a0d2f6fc70
@ -33,5 +33,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@ -1,8 +1,10 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
import com.sun.xml.internal.rngom.parse.host.Base;
|
|
||||||
|
|
||||||
public abstract class BaseItem implements ItemInterface {
|
/**
|
||||||
|
* Common functions used by all items (inside the package com.gildedrose.items)
|
||||||
|
*/
|
||||||
|
public abstract class BaseItem {
|
||||||
public Item item;
|
public Item item;
|
||||||
public static final int MAX_QUAILITY_FOR_AN_ITEM = 50;
|
public static final int MAX_QUAILITY_FOR_AN_ITEM = 50;
|
||||||
|
|
||||||
@ -12,6 +14,11 @@ public abstract class BaseItem implements ItemInterface {
|
|||||||
this.item=item;
|
this.item=item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if item is expired
|
||||||
|
*
|
||||||
|
* @return true, false
|
||||||
|
*/
|
||||||
protected boolean itemHasExpired() {
|
protected boolean itemHasExpired() {
|
||||||
boolean condition;
|
boolean condition;
|
||||||
if (item.sellIn < 0) {
|
if (item.sellIn < 0) {
|
||||||
@ -22,26 +29,43 @@ public abstract class BaseItem implements ItemInterface {
|
|||||||
return condition;
|
return condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Increase quality for each item
|
||||||
|
*
|
||||||
|
* @param factor, number to increase quality
|
||||||
|
*/
|
||||||
protected void increaseQualityBy(int factor) {
|
protected void increaseQualityBy(int factor) {
|
||||||
item.quality += factor;
|
item.quality += factor;
|
||||||
qualityOfAnItemIsNotMoreThan(MAX_QUAILITY_FOR_AN_ITEM);
|
qualityOfAnItemIsNotMoreThan(MAX_QUAILITY_FOR_AN_ITEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decrease quality for each item
|
||||||
|
*
|
||||||
|
* @param factor, number to decrease quality
|
||||||
|
*/
|
||||||
protected void decreaseQualityBy(int factor) {
|
protected void decreaseQualityBy(int factor) {
|
||||||
item.quality -= factor;
|
item.quality -= factor;
|
||||||
qualityOfAnItemIsNeverNegative();
|
qualityOfAnItemIsNeverNegative();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quality can never be increased above a limit
|
||||||
|
*
|
||||||
|
* @param limit, max item quality
|
||||||
|
*/
|
||||||
private void qualityOfAnItemIsNotMoreThan(int limit) {
|
private void qualityOfAnItemIsNotMoreThan(int limit) {
|
||||||
if (item.quality > limit) {
|
if (item.quality > limit) {
|
||||||
item.quality = limit;
|
item.quality = limit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quality can never be negative
|
||||||
|
*/
|
||||||
private void qualityOfAnItemIsNeverNegative() {
|
private void qualityOfAnItemIsNeverNegative() {
|
||||||
if (item.quality < 0) {
|
if (item.quality < 0) {
|
||||||
item.quality = 0;
|
item.quality = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
import com.sun.xml.internal.rngom.parse.host.Base;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class which update quality for all items
|
* Class which update quality for all items
|
||||||
*/
|
*/
|
||||||
@ -14,6 +12,9 @@ class GildedRoseItem {
|
|||||||
itemFactory = new ItemFactory();
|
itemFactory = new ItemFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update quality and number of days left to sell
|
||||||
|
*/
|
||||||
public void updateQuality() {
|
public void updateQuality() {
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
ItemInterface typeItem = itemFactory.createItemType(item);
|
ItemInterface typeItem = itemFactory.createItemType(item);
|
||||||
|
|||||||
@ -2,6 +2,9 @@ package com.gildedrose;
|
|||||||
|
|
||||||
import com.gildedrose.items.*;
|
import com.gildedrose.items.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory pattern to create a generic item
|
||||||
|
*/
|
||||||
public class ItemFactory {
|
public class ItemFactory {
|
||||||
public static final String SULFURA = "Sulfuras, Hand of Ragnaros";
|
public static final String SULFURA = "Sulfuras, Hand of Ragnaros";
|
||||||
public static final String AGED_BRIE = "Aged Brie";
|
public static final String AGED_BRIE = "Aged Brie";
|
||||||
@ -9,6 +12,12 @@ public class ItemFactory {
|
|||||||
public static final String CONJURED = "Conjured Mana Cake";
|
public static final String CONJURED = "Conjured Mana Cake";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to create a generic item
|
||||||
|
*
|
||||||
|
* @param item
|
||||||
|
* @return ItemInterface using item functions
|
||||||
|
*/
|
||||||
public ItemInterface createItemType(Item item) {
|
public ItemInterface createItemType(Item item) {
|
||||||
if (item.name.equals(AGED_BRIE)) {
|
if (item.name.equals(AGED_BRIE)) {
|
||||||
return new AgedBrie(item);
|
return new AgedBrie(item);
|
||||||
|
|||||||
@ -1,5 +1,8 @@
|
|||||||
package com.gildedrose;
|
package com.gildedrose;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Common interface for all item types for updating the quality.
|
||||||
|
*/
|
||||||
public interface ItemInterface {
|
public interface ItemInterface {
|
||||||
void updateQuality();
|
void updateQuality();
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import com.gildedrose.Item;
|
|||||||
import com.gildedrose.ItemInterface;
|
import com.gildedrose.ItemInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for Aged Brie item inherited from NormalItem
|
* Class for Aged Brie item inherited from BaseItem
|
||||||
*/
|
*/
|
||||||
public class AgedBrie extends BaseItem implements ItemInterface {
|
public class AgedBrie extends BaseItem implements ItemInterface {
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import com.gildedrose.Item;
|
|||||||
import com.gildedrose.ItemInterface;
|
import com.gildedrose.ItemInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Back Stage item inherited form NormalItem
|
* Class Back Stage item inherited form BaseItem
|
||||||
*
|
*
|
||||||
* Business rules are inherited from NormalItem with more conditions:
|
* Business rules are inherited from BaseItem with more conditions:
|
||||||
* Quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less
|
* Quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less
|
||||||
*/
|
*/
|
||||||
public class BackStageItem extends BaseItem implements ItemInterface {
|
public class BackStageItem extends BaseItem implements ItemInterface {
|
||||||
|
|||||||
@ -3,10 +3,9 @@ package com.gildedrose.items;
|
|||||||
import com.gildedrose.BaseItem;
|
import com.gildedrose.BaseItem;
|
||||||
import com.gildedrose.Item;
|
import com.gildedrose.Item;
|
||||||
import com.gildedrose.ItemInterface;
|
import com.gildedrose.ItemInterface;
|
||||||
import com.sun.xml.internal.rngom.parse.host.Base;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for the item ConjuredItem inherited from NormalItem
|
* Class for the item ConjuredItem inherited from BaseItem
|
||||||
*/
|
*/
|
||||||
public class ConjuredItem extends BaseItem implements ItemInterface {
|
public class ConjuredItem extends BaseItem implements ItemInterface {
|
||||||
public ConjuredItem(Item item) {
|
public ConjuredItem(Item item) {
|
||||||
|
|||||||
@ -4,6 +4,9 @@ import com.gildedrose.Item;
|
|||||||
import com.gildedrose.BaseItem;
|
import com.gildedrose.BaseItem;
|
||||||
import com.gildedrose.ItemInterface;
|
import com.gildedrose.ItemInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class inherited by BaseItem
|
||||||
|
*/
|
||||||
public class SulfuraItem extends BaseItem implements ItemInterface {
|
public class SulfuraItem extends BaseItem implements ItemInterface {
|
||||||
public SulfuraItem(Item item) {
|
public SulfuraItem(Item item) {
|
||||||
this.item=item;
|
this.item=item;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user