From f66651cdd6cf6d7449428caae712eeeba8300194 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Fri, 25 Mar 2016 07:50:26 +0100 Subject: Refactoring decks to be more flexible --- src/eu/equalparts/cardbase/Cardbase.java | 3 --- src/eu/equalparts/cardbase/DataContainer.java | 5 ----- src/eu/equalparts/cardbase/decks/Deck.java | 14 +++++++++++++- src/eu/equalparts/cardbase/decks/ReferenceDeck.java | 16 +++++----------- src/eu/equalparts/cardbase/decks/StandaloneDeck.java | 8 +++++--- 5 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 src/eu/equalparts/cardbase/DataContainer.java (limited to 'src/eu/equalparts/cardbase') diff --git a/src/eu/equalparts/cardbase/Cardbase.java b/src/eu/equalparts/cardbase/Cardbase.java index ee49db1..cdceb75 100644 --- a/src/eu/equalparts/cardbase/Cardbase.java +++ b/src/eu/equalparts/cardbase/Cardbase.java @@ -2,7 +2,6 @@ package eu.equalparts.cardbase; import java.io.File; import java.io.IOException; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -12,13 +11,11 @@ import java.util.Map; import com.fasterxml.jackson.core.JsonGenerationException; import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import eu.equalparts.cardbase.cards.Card; import eu.equalparts.cardbase.comparator.CardComparator; import eu.equalparts.cardbase.decks.ReferenceDeck; -import eu.equalparts.cardbase.decks.StandaloneDeck; import eu.equalparts.cardbase.utils.JSON; /** diff --git a/src/eu/equalparts/cardbase/DataContainer.java b/src/eu/equalparts/cardbase/DataContainer.java deleted file mode 100644 index 892c76b..0000000 --- a/src/eu/equalparts/cardbase/DataContainer.java +++ /dev/null @@ -1,5 +0,0 @@ -package eu.equalparts.cardbase; - -public class DataContainer { - -} diff --git a/src/eu/equalparts/cardbase/decks/Deck.java b/src/eu/equalparts/cardbase/decks/Deck.java index 1f28d60..7a7b819 100644 --- a/src/eu/equalparts/cardbase/decks/Deck.java +++ b/src/eu/equalparts/cardbase/decks/Deck.java @@ -1,12 +1,24 @@ package eu.equalparts.cardbase.decks; -public abstract class Deck { +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +public abstract class Deck { public String name = "Unnamed Deck"; public int plains = 0, islands = 0, swamps = 0, mountains = 0, forests = 0; + + private Map cardReferences = new HashMap(); + + public void addCard(Integer cardHash, Integer count) { + cardReferences.put(cardHash, count); + } + public Map getCardReferences() { + return Collections.unmodifiableMap(cardReferences); + } } diff --git a/src/eu/equalparts/cardbase/decks/ReferenceDeck.java b/src/eu/equalparts/cardbase/decks/ReferenceDeck.java index 2303f24..ab9abf8 100644 --- a/src/eu/equalparts/cardbase/decks/ReferenceDeck.java +++ b/src/eu/equalparts/cardbase/decks/ReferenceDeck.java @@ -1,16 +1,11 @@ package eu.equalparts.cardbase.decks; -import java.util.HashMap; -import java.util.Map; - -import eu.equalparts.cardbase.cards.Card; +import java.util.Map.Entry; public class ReferenceDeck extends Deck { - - public Map cardReferences = new HashMap(); - public ReferenceDeck() { - + public ReferenceDeck(String deckName) { + this.name = deckName; } public ReferenceDeck(StandaloneDeck deck) { @@ -21,9 +16,8 @@ public class ReferenceDeck extends Deck { this.mountains = deck.mountains; this.forests = deck.forests; - // TODO sort this out - for (Card card : deck.cards) { - cardReferences.put(card.hashCode(), 1); + for (Entry entry : deck.getCardReferences().entrySet()) { + getCardReferences().put(entry.getKey(), entry.getValue()); } } diff --git a/src/eu/equalparts/cardbase/decks/StandaloneDeck.java b/src/eu/equalparts/cardbase/decks/StandaloneDeck.java index f015a91..d66311d 100644 --- a/src/eu/equalparts/cardbase/decks/StandaloneDeck.java +++ b/src/eu/equalparts/cardbase/decks/StandaloneDeck.java @@ -1,13 +1,15 @@ package eu.equalparts.cardbase.decks; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import eu.equalparts.cardbase.cards.Card; public class StandaloneDeck extends Deck { + private Map cardData = new HashMap(); - private Map cards = new HashMap(); - private Map counts = new HashMap(); - + public Map getCardData() { + return Collections.unmodifiableMap(cardData); + } } -- cgit v1.2.3