From c07d860f1d90dc3961b31c87dbe637dbcd87da76 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Thu, 11 Aug 2016 23:59:10 +0200 Subject: Refactored the Card data structure to be able to do filtering properly --- src/eu/equalparts/cardbase/card/Card.java | 68 ++++++++++++++++++++++ .../cardbase/card/CardSetInformation.java | 34 +++++++++++ src/eu/equalparts/cardbase/card/FullCardSet.java | 26 +++++++++ 3 files changed, 128 insertions(+) create mode 100644 src/eu/equalparts/cardbase/card/Card.java create mode 100644 src/eu/equalparts/cardbase/card/CardSetInformation.java create mode 100644 src/eu/equalparts/cardbase/card/FullCardSet.java (limited to 'src/eu/equalparts/cardbase/card') 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 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 -- cgit v1.2.3