Add missing javadoc

This commit is contained in:
brianblessou 2019-05-12 22:22:25 +02:00
parent cc53ad07e0
commit a0d2f6fc70
9 changed files with 49 additions and 11 deletions

View File

@ -33,5 +33,4 @@
</plugin>
</plugins>
</build>
</project>

View File

@ -1,8 +1,10 @@
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 static final int MAX_QUAILITY_FOR_AN_ITEM = 50;
@ -12,6 +14,11 @@ public abstract class BaseItem implements ItemInterface {
this.item=item;
}
/**
* Check if item is expired
*
* @return true, false
*/
protected boolean itemHasExpired() {
boolean condition;
if (item.sellIn < 0) {
@ -22,26 +29,43 @@ public abstract class BaseItem implements ItemInterface {
return condition;
}
/**
* Increase quality for each item
*
* @param factor, number to increase quality
*/
protected void increaseQualityBy(int factor) {
item.quality += factor;
qualityOfAnItemIsNotMoreThan(MAX_QUAILITY_FOR_AN_ITEM);
}
/**
* Decrease quality for each item
*
* @param factor, number to decrease quality
*/
protected void decreaseQualityBy(int factor) {
item.quality -= factor;
qualityOfAnItemIsNeverNegative();
}
/**
* Quality can never be increased above a limit
*
* @param limit, max item quality
*/
private void qualityOfAnItemIsNotMoreThan(int limit) {
if (item.quality > limit) {
item.quality = limit;
}
}
/**
* Quality can never be negative
*/
private void qualityOfAnItemIsNeverNegative() {
if (item.quality < 0) {
item.quality = 0;
}
}
}

View File

@ -1,7 +1,5 @@
package com.gildedrose;
import com.sun.xml.internal.rngom.parse.host.Base;
/**
* Class which update quality for all items
*/
@ -14,6 +12,9 @@ class GildedRoseItem {
itemFactory = new ItemFactory();
}
/**
* Update quality and number of days left to sell
*/
public void updateQuality() {
for (Item item : items) {
ItemInterface typeItem = itemFactory.createItemType(item);

View File

@ -2,6 +2,9 @@ package com.gildedrose;
import com.gildedrose.items.*;
/**
* Factory pattern to create a generic item
*/
public class ItemFactory {
public static final String SULFURA = "Sulfuras, Hand of Ragnaros";
public static final String AGED_BRIE = "Aged Brie";
@ -9,6 +12,12 @@ public class ItemFactory {
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) {
if (item.name.equals(AGED_BRIE)) {
return new AgedBrie(item);

View File

@ -1,5 +1,8 @@
package com.gildedrose;
/**
* Common interface for all item types for updating the quality.
*/
public interface ItemInterface {
void updateQuality();

View File

@ -5,7 +5,7 @@ import com.gildedrose.Item;
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 {

View File

@ -5,9 +5,9 @@ import com.gildedrose.Item;
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
*/
public class BackStageItem extends BaseItem implements ItemInterface {

View File

@ -3,10 +3,9 @@ package com.gildedrose.items;
import com.gildedrose.BaseItem;
import com.gildedrose.Item;
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 ConjuredItem(Item item) {

View File

@ -4,6 +4,9 @@ import com.gildedrose.Item;
import com.gildedrose.BaseItem;
import com.gildedrose.ItemInterface;
/**
* Class inherited by BaseItem
*/
public class SulfuraItem extends BaseItem implements ItemInterface {
public SulfuraItem(Item item) {
this.item=item;