aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/data
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/equalparts/cardbase/data')
-rw-r--r--src/eu/equalparts/cardbase/data/Card.java4
-rw-r--r--src/eu/equalparts/cardbase/data/CardBase.java18
-rw-r--r--src/eu/equalparts/cardbase/data/CardBaseManager.java68
-rw-r--r--src/eu/equalparts/cardbase/data/Deck.java10
-rw-r--r--src/eu/equalparts/cardbase/data/MetaCardSet.java31
5 files changed, 93 insertions, 38 deletions
diff --git a/src/eu/equalparts/cardbase/data/Card.java b/src/eu/equalparts/cardbase/data/Card.java
index 8e25d56..1bf6a75 100644
--- a/src/eu/equalparts/cardbase/data/Card.java
+++ b/src/eu/equalparts/cardbase/data/Card.java
@@ -28,8 +28,8 @@ public class Card {
public String border;
public String watermark;
- // Not part of JSON, will be set later
+ // Not part of upstream JSON
public String setCode;
- public String setName;
+ public Integer count;
} \ No newline at end of file
diff --git a/src/eu/equalparts/cardbase/data/CardBase.java b/src/eu/equalparts/cardbase/data/CardBase.java
index 70ae0ea..abdd423 100644
--- a/src/eu/equalparts/cardbase/data/CardBase.java
+++ b/src/eu/equalparts/cardbase/data/CardBase.java
@@ -4,9 +4,21 @@ import java.util.ArrayList;
public class CardBase {
- private ArrayList<Card> cards;
- private ArrayList<Deck> decks;
-
+ public ArrayList<Card> cards = new ArrayList<>();
+ public ArrayList<Deck> decks = new ArrayList<>();
+ /**
+ * @param setCode
+ * @param number
+ * @return the card if found, else null.
+ */
+ public Card getCardByNumber(String setCode, String number) {
+ for (Card card : cards) {
+ if (card.setCode.equals(setCode) && card.number.equals(number))
+ return card;
+ }
+
+ return null;
+ }
}
diff --git a/src/eu/equalparts/cardbase/data/CardBaseManager.java b/src/eu/equalparts/cardbase/data/CardBaseManager.java
index acf5a3a..0baf9d7 100644
--- a/src/eu/equalparts/cardbase/data/CardBaseManager.java
+++ b/src/eu/equalparts/cardbase/data/CardBaseManager.java
@@ -2,6 +2,7 @@ package eu.equalparts.cardbase.data;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Iterator;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
@@ -11,19 +12,17 @@ import eu.equalparts.cardbase.query.IO;
public class CardBaseManager {
private ArrayList<MetaCardSet> metaSets;
+ public CardBase cardBase;
- public static void main(String... args) {
-
- }
-
/**
* Parse a cardbase file and create an associated CardBase object.
* @throws IOException
* @throws JsonMappingException
* @throws JsonParseException
*/
- public CardBaseManager(File cardbase) throws JsonParseException, JsonMappingException, IOException {
+ public CardBaseManager(File cardBaseFile) throws JsonParseException, JsonMappingException, IOException {
metaSets = IO.getAllMetaSets();
+ cardBase = IO.readCardBase(cardBaseFile);
}
/**
@@ -34,10 +33,69 @@ public class CardBaseManager {
*/
public CardBaseManager() throws JsonParseException, JsonMappingException, IOException {
metaSets = IO.getAllMetaSets();
+ cardBase = new CardBase();
}
public ArrayList<MetaCardSet> getAllMetaSets() {
return metaSets;
}
+ /**
+ * Add a specific amount of a card to the cardbase.
+ * If the card is not already in the cardbase, it is added.
+ * If it is already present, the count is simply updated.
+ *
+ *
+ * @param newCard
+ * @param count
+ */
+ public void addCard(Card newCard, Integer count) {
+ Card card = cardBase.getCardByNumber(newCard.setCode, newCard.number);
+ if (card != null) {
+ card.count += count;
+ } else {
+ newCard.count = count;
+ cardBase.cards.add(newCard);
+ }
+ }
+
+ /**
+ * Remove a specific amount of a card from the cardbase.
+ * If the card is not present in the cardbase, nothing happens.
+ * If the card is present in the card, the specified amount is removed.
+ * If that amount is equal to or exceeds the count already in the cardbase,
+ * the card entry is removed altogether.
+ *
+ * @param remove
+ * @param count
+ */
+ public void removeCard(Card remove, Integer count) {
+ Card card = cardBase.getCardByNumber(remove.setCode, remove.number);
+ if (card != null) {
+ if (card.count <= count) {
+ cardBase.cards.remove(card);
+ } else {
+ card.count -= count;
+ }
+ }
+ }
+
+ /**
+ * @return an iterator to the cards in the cardbase.
+ */
+ public Iterator<Card> cardIterator() {
+ return cardBase.cards.iterator();
+ }
+
+ /**
+ * Return a card from the cardBase by setCode and number.
+ * If no such card is in the cardbase, return null.
+ *
+ * @param code
+ * @param string
+ * @return
+ */
+ public Card getCard(String code, String number) {
+ return cardBase.getCardByNumber(code, number);
+ }
}
diff --git a/src/eu/equalparts/cardbase/data/Deck.java b/src/eu/equalparts/cardbase/data/Deck.java
index 50f1129..b5fe402 100644
--- a/src/eu/equalparts/cardbase/data/Deck.java
+++ b/src/eu/equalparts/cardbase/data/Deck.java
@@ -1,5 +1,15 @@
package eu.equalparts.cardbase.data;
+import java.util.HashMap;
+
public class Deck {
+ /**
+ * Cards stored in key-value pairs of [multiverse ID, amount].
+ */
+ public HashMap<Integer, Integer> cards;
+
+ public Deck() {
+
+ }
}
diff --git a/src/eu/equalparts/cardbase/data/MetaCardSet.java b/src/eu/equalparts/cardbase/data/MetaCardSet.java
index 4ddf228..3b7d4fd 100644
--- a/src/eu/equalparts/cardbase/data/MetaCardSet.java
+++ b/src/eu/equalparts/cardbase/data/MetaCardSet.java
@@ -2,34 +2,9 @@ package eu.equalparts.cardbase.data;
public class MetaCardSet {
- private String name = "";
- private String code = "";
- private String releaseDate = "";
-
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getCode() {
- return code;
- }
-
- public void setCode(String code) {
- this.code = code;
- }
-
- public String getReleaseDate() {
- return releaseDate;
- }
-
- public void setReleaseDate(String releaseDate) {
- this.releaseDate = releaseDate;
- }
+ public String name = "";
+ public String code = "";
+ public String releaseDate = "";
@Override
public String toString() {