diff options
Diffstat (limited to 'src/eu')
-rw-r--r-- | src/eu/equalparts/cardbase/data/Card.java | 233 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/data/CardBase.java | 23 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/data/CardSet.java | 86 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/query/Test.java | 72 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/standalone/CardBaseCLI.java | 69 |
5 files changed, 483 insertions, 0 deletions
diff --git a/src/eu/equalparts/cardbase/data/Card.java b/src/eu/equalparts/cardbase/data/Card.java new file mode 100644 index 0000000..d125c54 --- /dev/null +++ b/src/eu/equalparts/cardbase/data/Card.java @@ -0,0 +1,233 @@ +package eu.equalparts.cardbase.data; + +import java.util.ArrayList; + +public class Card { + private String layout; + private String name; + private ArrayList<String> names; + private String manaCost; + private Integer cmc; + private ArrayList<String> colors; + private String type; + private ArrayList<String> supertypes; + private ArrayList<String> types; + private ArrayList<String> subtypes; + private String rarity; + private String text; + private String flavor; + private String artist; + private String number; + private String power; + private String toughness; + private Integer loyalty; + private Integer multiverseid; + private ArrayList<String> variations; + private String imageName; + private String border; + private String watermark; + + // Not part of JSON, will be set later + private String setCode; + private String setName; + + public String getLayout() { + return layout; + } + + public void setLayout(String layout) { + this.layout = layout; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ArrayList<String> getNames() { + return names; + } + + public void setNames(ArrayList<String> names) { + this.names = names; + } + + public String getManaCost() { + return manaCost; + } + + public void setManaCost(String manaCost) { + this.manaCost = manaCost; + } + + public Integer getCmc() { + return cmc; + } + + public void setCmc(Integer cmc) { + this.cmc = cmc; + } + + public ArrayList<String> getColors() { + return colors; + } + + public void setColors(ArrayList<String> colors) { + this.colors = colors; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public ArrayList<String> getSupertypes() { + return supertypes; + } + + public void setSupertypes(ArrayList<String> supertypes) { + this.supertypes = supertypes; + } + + public ArrayList<String> getTypes() { + return types; + } + + public void setTypes(ArrayList<String> types) { + this.types = types; + } + + public ArrayList<String> getSubtypes() { + return subtypes; + } + + public void setSubtypes(ArrayList<String> subtypes) { + this.subtypes = subtypes; + } + + public String getRarity() { + return rarity; + } + + public void setRarity(String rarity) { + this.rarity = rarity; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getFlavor() { + return flavor; + } + + public void setFlavor(String flavor) { + this.flavor = flavor; + } + + public String getArtist() { + return artist; + } + + public void setArtist(String artist) { + this.artist = artist; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } + + public String getPower() { + return power; + } + + public void setPower(String power) { + this.power = power; + } + + public String getToughness() { + return toughness; + } + + public void setToughness(String toughness) { + this.toughness = toughness; + } + + public Integer getLoyalty() { + return loyalty; + } + + public void setLoyalty(Integer loyalty) { + this.loyalty = loyalty; + } + + public Integer getMultiverseid() { + return multiverseid; + } + + public void setMultiverseid(Integer multiverseid) { + this.multiverseid = multiverseid; + } + + public ArrayList<String> getVariations() { + return variations; + } + + public void setVariations(ArrayList<String> variations) { + this.variations = variations; + } + + public String getImageName() { + return imageName; + } + + public void setImageName(String imageName) { + this.imageName = imageName; + } + + public String getBorder() { + return border; + } + + public void setBorder(String border) { + this.border = border; + } + + public String getWatermark() { + return watermark; + } + + public void setWatermark(String watermark) { + this.watermark = watermark; + } + + public String getSetName() { + return setName; + } + + public void setSetName(String setName) { + this.setName = setName; + } + + public String getSetCode() { + return setCode; + } + + public void setSetCode(String setCode) { + this.setCode = setCode; + } +}
\ No newline at end of file diff --git a/src/eu/equalparts/cardbase/data/CardBase.java b/src/eu/equalparts/cardbase/data/CardBase.java new file mode 100644 index 0000000..14c30a5 --- /dev/null +++ b/src/eu/equalparts/cardbase/data/CardBase.java @@ -0,0 +1,23 @@ +package eu.equalparts.cardbase.data; +import java.io.File; + +public class CardBase { + + public static void main(String... args) { + + } + + /** + * Parse a cardbase file and create an associated CardBase object. + */ + public CardBase(File cardbase) { + + } + + /** + * Create an empty CardBase. + */ + public CardBase() { + + } +} diff --git a/src/eu/equalparts/cardbase/data/CardSet.java b/src/eu/equalparts/cardbase/data/CardSet.java new file mode 100644 index 0000000..97622db --- /dev/null +++ b/src/eu/equalparts/cardbase/data/CardSet.java @@ -0,0 +1,86 @@ +package eu.equalparts.cardbase.data; + +import java.util.ArrayList; + +public class CardSet { + private String name; + private String code; + private String releaseDate; + private String border; + private String type; + private String block; + private String gathererCode; + private ArrayList<Card> cards; + + 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 getBorder() { + return border; + } + + public void setBorder(String border) { + this.border = border; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getBlock() { + return block; + } + + public void setBlock(String block) { + this.block = block; + } + + public ArrayList<Card> getCards() { + return cards; + } + + public Card getCardByNumber(String number) { + for (Card card : cards) { + if (card.getNumber().equals(number)) + return card; + } + return null; + } + + public void setCards(ArrayList<Card> cards) { + this.cards = cards; + } + + public String getGathererCode() { + return gathererCode; + } + + public void setGathererCode(String gathererCode) { + this.gathererCode = gathererCode; + } +}
\ No newline at end of file diff --git a/src/eu/equalparts/cardbase/query/Test.java b/src/eu/equalparts/cardbase/query/Test.java new file mode 100644 index 0000000..646139e --- /dev/null +++ b/src/eu/equalparts/cardbase/query/Test.java @@ -0,0 +1,72 @@ +package eu.equalparts.cardbase.query; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import eu.equalparts.cardbase.data.Card; +import eu.equalparts.cardbase.data.CardSet; + +public class Test { + +// public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException { +// ObjectMapper mapper = new ObjectMapper(); +// mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); +// +// @SuppressWarnings("unchecked") +// List<Card> allCards = getAllCards((Map<String, CardSet>) mapper +// .readValue(new File("AllSets.json"), new TypeReference<Map<String, CardSet>>() {})); +// +// System.out.println("Number of cards: " + allCards.size()); +// } +// +// public static List<Card> getAllCards(Map<String, CardSet> sets) { +// List<Card> allCards = new ArrayList<Card>(); +// +// for (CardSet set : sets.values()) { +// for (Card card : set.getCards()) { +// card.setSetCode(set.getCode()); +// card.setSetName(set.getName()); +// // System.out.println(set.getName() + ": " + card.getName()); +// +// allCards.add(card); +// } +// } +// +// return allCards; +// } + + public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + +// @SuppressWarnings("unchecked") + CardSet set = mapper.readValue(new File("M15.json"), CardSet.class); + System.out.println(set.getCardByNumber("281").getName()); + + } + + public static List<Card> getAllCards(Map<String, CardSet> sets) { + List<Card> allCards = new ArrayList<Card>(); + + for (CardSet set : sets.values()) { + for (Card card : set.getCards()) { + card.setSetCode(set.getCode()); + card.setSetName(set.getName()); + // System.out.println(set.getName() + ": " + card.getName()); + + allCards.add(card); + } + } + + return allCards; + } +} diff --git a/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java b/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java new file mode 100644 index 0000000..4b746b2 --- /dev/null +++ b/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java @@ -0,0 +1,69 @@ +package eu.equalparts.cardbase.standalone; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; + +import eu.equalparts.cardbase.data.CardBase; + +/** + * This provides a lightweight CLI for interacting with cardbase files. + * + */ +public class CardBaseCLI { + + /** + * Execute the interface. + * + * @param args the first argument is the cardbase file. Further arguments are ignored. + */ + public static void main(String... args) { + + System.out.println("Welcome to cardbase"); + CardBase cb; + + // construct the cardbase + if (args.length > 0) { + System.out.println("Building cardbase from " + args[0]); + cb = new CardBase(new File(args[0])); + } else { + System.out.println("No cardbase file was provided, initialising a clean cardbase"); + cb = new CardBase(); + } + + // main UI loop + try { + // initialise necessary components + System.out.println("Fetching card sets from upstream"); + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + boolean exit = false; + + while (!exit) { + String rawInput = br.readLine().trim().toLowerCase(); + String[] commands = rawInput.split("[ \t]+"); + + if (commands.length > 0) { + switch (commands[0]) { + case "exit": + exit = true; + break; + case "sets": + break; + case "set": + break; + case "write": + break; + default: + break; + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + + + } + +} |