diff options
Diffstat (limited to 'src/eu/equalparts/cardbase/cardstorage/ReferenceCardContainer.java')
-rw-r--r-- | src/eu/equalparts/cardbase/cardstorage/ReferenceCardContainer.java | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/eu/equalparts/cardbase/cardstorage/ReferenceCardContainer.java b/src/eu/equalparts/cardbase/cardstorage/ReferenceCardContainer.java index ccd5508..f265d24 100644 --- a/src/eu/equalparts/cardbase/cardstorage/ReferenceCardContainer.java +++ b/src/eu/equalparts/cardbase/cardstorage/ReferenceCardContainer.java @@ -7,19 +7,34 @@ import com.fasterxml.jackson.annotation.JsonProperty; import eu.equalparts.cardbase.cards.Card; +/** + * A class which holds card counts by reference (hash). + * + * @author Eduardo Pedroni + * + */ public abstract class ReferenceCardContainer { - @JsonProperty private Map<Integer, Integer> cardReferences; - - public ReferenceCardContainer() { - cardReferences = new HashMap<>(); - } + /** + * A map with card hashes as entry keys (calculated used {@code Card.hashCode()}) and card amounts as entry values. + */ + @JsonProperty private Map<Integer, Integer> cardReferences = new HashMap<>(); + /** + * Returns the amount of the specified card. If the card is not present at all, return 0. + * + * @param cardToCount a card whose count is to be returned. + * @return the count of the returned card in the container. + */ public int getCount(Card cardToCount) { int hashCode = cardToCount.hashCode(); return cardReferences.containsKey(hashCode) ? cardReferences.get(hashCode) : 0; } + /** + * @param cardToAdd the card to add the container. + * @param count the amount to add. + */ public void addCard(Card cardToAdd, int count) { int hashCode = cardToAdd.hashCode(); if (cardReferences.containsKey(hashCode)) { @@ -29,6 +44,11 @@ public abstract class ReferenceCardContainer { } } + /** + * @param cardToRemove the card to remove from the container. + * @param count the amount to remove. + * @return the amount that was effectively removed. Could be less than {@code count} depending on how many of the card were present. + */ public int removeCard(Card cardToRemove, int count) { int hashCode = cardToRemove.hashCode(); int removed = 0; |