diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-03-15 22:04:06 +0100 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2016-03-15 22:04:06 +0100 |
commit | f70899a487cf0cdc58b8f4e0efea98e8404766c8 (patch) | |
tree | 9d1df2575447bd9daa392d64d502401c53c9c6cd /src | |
parent | e36558c84c443b2236eb3dacd2e3f66981818232 (diff) |
Refactor is coming along, just need to sort out the new file structure now
Diffstat (limited to 'src')
-rw-r--r-- | src/eu/equalparts/cardbase/CardEntry.java | 25 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/Cardbase.java | 19 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/cli/CardbaseCLI.java | 6 |
3 files changed, 18 insertions, 32 deletions
diff --git a/src/eu/equalparts/cardbase/CardEntry.java b/src/eu/equalparts/cardbase/CardEntry.java deleted file mode 100644 index c4a4c94..0000000 --- a/src/eu/equalparts/cardbase/CardEntry.java +++ /dev/null @@ -1,25 +0,0 @@ -package eu.equalparts.cardbase; - -import eu.equalparts.cardbase.cards.Card; - -/** - * The purpose of this class is to hold a single {@code Card} object but - * also all associated metadata, such as count. - * - * @author Eduardo Pedroni - * - */ -public class CardEntry { - - private final Card card; - public int count; - - public CardEntry(Card card, int count) { - this.card = card; - this.count = count; - } - - public Card card() { - return card; - } -} diff --git a/src/eu/equalparts/cardbase/Cardbase.java b/src/eu/equalparts/cardbase/Cardbase.java index af8e7d5..075f7f3 100644 --- a/src/eu/equalparts/cardbase/Cardbase.java +++ b/src/eu/equalparts/cardbase/Cardbase.java @@ -11,8 +11,8 @@ 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 com.fasterxml.jackson.databind.JsonNode; import eu.equalparts.cardbase.cards.Card; import eu.equalparts.cardbase.comparator.CardComparator; @@ -56,14 +56,21 @@ public class Cardbase { * @throws IOException if a low-level I/O problem (unexpected end-of-input, network error) occurs. */ public Cardbase(File cardbaseFile) throws JsonParseException, JsonMappingException, IOException { - cards = JSON.mapper.readValue(cardbaseFile, new TypeReference<Map<Integer, Card>>() {}); + initialise(); + parseCardbase(JSON.mapper.readValue(cardbaseFile, JsonNode.class)); + } /** * Initialises a clean cardbase. */ public Cardbase() { + initialise(); + } + + private void initialise() { cards = new HashMap<Integer, Card>(); + collection = new HashMap<Integer, Integer>(); decks = new HashMap<String, ReferenceDeck>(); } @@ -192,11 +199,15 @@ public class Cardbase { return Collections.unmodifiableMap(decks); } - public int getCount(String setCode, String number) { - Integer count = collection.get(Card.makeHash(setCode, number)); + public int getCount(Card card) { + Integer count = collection.get(Card.makeHash(card.setCode, card.number)); return count != null ? count : 0; } + private void parseCardbase(JsonNode jsonTree) { + + } + // public List<Card> getMissingCards(StandaloneDeck deckToCheck) { // List<Card> missingCards = new ArrayList<Card>(); // for (Card card : deckToCheck.cards) { diff --git a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java index 8aece5d..b1a4028 100644 --- a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java +++ b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java @@ -337,7 +337,7 @@ public final class CardbaseCLI { int total = 0; for (Card card : cardbase.getCards()) { printGlance(card); - total += cardbase.getCount(card.setCode, card.number); + total += cardbase.getCount(card); } System.out.println("Total: " + total); } @@ -365,7 +365,7 @@ public final class CardbaseCLI { int total = 0; for (Card card : cardbase.getCards()) { printPerusal(card); - total += cardbase.getCount(card.setCode, card.number); + total += cardbase.getCount(card); } System.out.println("Total: " + total); } @@ -523,7 +523,7 @@ public final class CardbaseCLI { * @param card the card to glance. */ private void printGlance(Card card) { - System.out.println(String.format("%1$-4d %2$s (%3$s, %4$s)", cardbase.getCount(card.setCode, card.number), card.name, card.setCode, card.number)); + System.out.println(String.format("%1$-4d %2$s (%3$s, %4$s)", cardbase.getCount(card), card.name, card.setCode, card.number)); } /** |