aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts/cardbase/card
diff options
context:
space:
mode:
authorEduardo Pedroni <e.pedroni91@gmail.com>2016-08-11 23:59:10 +0200
committerEduardo Pedroni <e.pedroni91@gmail.com>2016-08-11 23:59:10 +0200
commitc07d860f1d90dc3961b31c87dbe637dbcd87da76 (patch)
treee31997581287fd5d021aebc60ea7c5ad08539bbc /src/eu/equalparts/cardbase/card
parentf7fe057b745d3f0e19b5dd6bd1819b11fc89c551 (diff)
Refactored the Card data structure to be able to do filtering properly
Diffstat (limited to 'src/eu/equalparts/cardbase/card')
-rw-r--r--src/eu/equalparts/cardbase/card/Card.java68
-rw-r--r--src/eu/equalparts/cardbase/card/CardSetInformation.java34
-rw-r--r--src/eu/equalparts/cardbase/card/FullCardSet.java26
3 files changed, 128 insertions, 0 deletions
diff --git a/src/eu/equalparts/cardbase/card/Card.java b/src/eu/equalparts/cardbase/card/Card.java
new file mode 100644
index 0000000..adac286
--- /dev/null
+++ b/src/eu/equalparts/cardbase/card/Card.java
@@ -0,0 +1,68 @@
+package eu.equalparts.cardbase.card;
+
+import eu.equalparts.cardbase.cardfield.IntegerCardField;
+import eu.equalparts.cardbase.cardfield.StringCardField;
+import eu.equalparts.cardbase.comparator.SpecialFields.DirtyNumber;
+import eu.equalparts.cardbase.comparator.SpecialFields.Rarity;
+
+public class Card {
+ public StringCardField name;
+ public StringCardField layout;
+ public StringCardField manaCost;
+ public IntegerCardField cmc;
+ public StringCardField type;
+ @Rarity
+ public StringCardField rarity;
+ public StringCardField text;
+ public StringCardField flavor;
+ public StringCardField artist;
+ @DirtyNumber
+ public StringCardField number;
+ @DirtyNumber
+ public StringCardField power;
+ @DirtyNumber
+ public StringCardField toughness;
+ public IntegerCardField loyalty;
+ public IntegerCardField multiverseid;
+ public StringCardField imageName;
+ public StringCardField watermark;
+
+ // Not part of upstream JSON
+ public StringCardField setCode;
+ public StringCardField imageCode;
+
+ public static int makeHash(String setCode, String number) {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((number == null) ? 0 : number.hashCode());
+ result = prime * result + ((setCode == null) ? 0 : setCode.hashCode());
+ return result;
+ }
+
+ @Override
+ public int hashCode() {
+ return makeHash(setCode.get(), number.get());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Card other = (Card) obj;
+ if (number == null) {
+ if (other.number != null)
+ return false;
+ } else if (!number.equals(other.number))
+ return false;
+ if (setCode == null) {
+ if (other.setCode != null)
+ return false;
+ } else if (!setCode.equals(other.setCode))
+ return false;
+ return true;
+ }
+}
diff --git a/src/eu/equalparts/cardbase/card/CardSetInformation.java b/src/eu/equalparts/cardbase/card/CardSetInformation.java
new file mode 100644
index 0000000..a01c18d
--- /dev/null
+++ b/src/eu/equalparts/cardbase/card/CardSetInformation.java
@@ -0,0 +1,34 @@
+package eu.equalparts.cardbase.card;
+
+public class CardSetInformation {
+
+ private String name;
+ private String code;
+ private String releaseDate;
+
+ /**
+ * @return the set's name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the set code.
+ */
+ public String getCode() {
+ return code;
+ }
+
+ /**
+ * @return the set's release date.
+ */
+ public String getReleaseDate() {
+ return releaseDate;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%1$-12s : %2$s", code, name, releaseDate);
+ }
+}
diff --git a/src/eu/equalparts/cardbase/card/FullCardSet.java b/src/eu/equalparts/cardbase/card/FullCardSet.java
new file mode 100644
index 0000000..72f1e4a
--- /dev/null
+++ b/src/eu/equalparts/cardbase/card/FullCardSet.java
@@ -0,0 +1,26 @@
+package eu.equalparts.cardbase.card;
+
+import java.util.Map;
+
+public class FullCardSet {
+
+ public String name;
+ public String code;
+ public String magicCardsInfoCode;
+ public String releaseDate;
+ public String border;
+ public String type;
+ public String block;
+ public String gathererCode;
+ public Map<String, Card> cards;
+
+ /**
+ * Searches for a card by number (the one shown on the card itself).
+ *
+ * @param number the number of the card to search.
+ * @return the requested {@code Card}, or null if no card is found with that number.
+ */
+ public Card getCardByNumber(String number) {
+ return cards.get(number);
+ }
+} \ No newline at end of file