diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-06-04 20:57:10 +0200 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-06-04 20:57:10 +0200 |
commit | 1f0159bcf903c0f422ab47b07cd296da1e816f87 (patch) | |
tree | 237ea7d5a71313cc0bb4db850174a76462de35cb | |
parent | 129cfbf8d5afec5725a88835869203a8825de22a (diff) |
Made a plan, now i'm following it. CLI is well under way
-rw-r--r-- | SetList.json | 1 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/data/Card.java | 250 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/data/CardBase.java | 23 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/data/CardBaseManager.java | 43 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/data/CardSet.java | 90 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/data/Deck.java | 5 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/data/MetaCardSet.java | 39 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/query/IO.java | 43 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/query/Test.java | 9 | ||||
-rw-r--r-- | src/eu/equalparts/cardbase/standalone/CardBaseCLI.java | 112 |
10 files changed, 263 insertions, 352 deletions
diff --git a/SetList.json b/SetList.json new file mode 100644 index 0000000..bb5f4d6 --- /dev/null +++ b/SetList.json @@ -0,0 +1 @@ +[{"name":"Limited Edition Alpha","code":"LEA","releaseDate":"1993-08-05"},{"name":"Limited Edition Beta","code":"LEB","releaseDate":"1993-10-01"},{"name":"Arabian Nights","code":"ARN","releaseDate":"1993-12-01"},{"name":"Unlimited Edition","code":"2ED","releaseDate":"1993-12-01"},{"name":"Dragon Con","code":"pDRC","releaseDate":"1994-01-01"},{"name":"Antiquities","code":"ATQ","releaseDate":"1994-03-01"},{"name":"Revised Edition","code":"3ED","releaseDate":"1994-04-01"},{"name":"Legends","code":"LEG","releaseDate":"1994-06-01"},{"name":"The Dark","code":"DRK","releaseDate":"1994-08-01"},{"name":"Media Inserts","code":"pMEI","releaseDate":"1995-01-01"},{"name":"Fallen Empires","code":"FEM","releaseDate":"1994-11-01"},{"name":"Legend Membership","code":"pLGM","releaseDate":"1995-01-01"},{"name":"Fourth Edition","code":"4ED","releaseDate":"1995-04-01"},{"name":"Ice Age","code":"ICE","releaseDate":"1995-06-01"},{"name":"Chronicles","code":"CHR","releaseDate":"1995-07-01"},{"name":"Homelands","code":"HML","releaseDate":"1995-10-01"},{"name":"Alliances","code":"ALL","releaseDate":"1996-06-10"},{"name":"Rivals Quick Start Set","code":"RQS","releaseDate":"1996-07-01"},{"name":"Arena League","code":"pARL","releaseDate":"1996-08-02"},{"name":"Celebration","code":"pCEL","releaseDate":"1996-08-14"},{"name":"Mirage","code":"MIR","releaseDate":"1996-10-08"},{"name":"Multiverse Gift Box","code":"MGB","releaseDate":"1996-11-01"},{"name":"Introductory Two-Player Set","code":"ITP","releaseDate":"1996-12-31"},{"name":"Visions","code":"VIS","releaseDate":"1997-02-03"},{"name":"Fifth Edition","code":"5ED","releaseDate":"1997-03-24"},{"name":"Portal Demo Game","code":"pPOD","releaseDate":"1997-05-01"},{"name":"Portal","code":"POR","releaseDate":"1997-05-01"},{"name":"Vanguard","code":"VAN","releaseDate":"1997-05-01"},{"name":"Weatherlight","code":"WTH","releaseDate":"1997-06-09"},{"name":"Prerelease Events","code":"pPRE","releaseDate":"1997-10-04"},{"name":"Tempest","code":"TMP","releaseDate":"1997-10-14"},{"name":"Stronghold","code":"STH","releaseDate":"1998-03-02"},{"name":"Portal Second Age","code":"PO2","releaseDate":"1998-06-01"},{"name":"Judge Gift Program","code":"pJGP","releaseDate":"1998-06-01"},{"name":"Exodus","code":"EXO","releaseDate":"1998-06-15"},{"name":"Unglued","code":"UGL","releaseDate":"1998-08-11"},{"name":"Asia Pacific Land Program","code":"pALP","releaseDate":"1998-09-01"},{"name":"Urza's Saga","code":"USG","releaseDate":"1998-10-12"},{"name":"Anthologies","code":"ATH","releaseDate":"1998-11-01"},{"name":"Urza's Legacy","code":"ULG","releaseDate":"1999-02-15"},{"name":"Classic Sixth Edition","code":"6ED","releaseDate":"1999-04-21"},{"name":"Portal Three Kingdoms","code":"PTK","releaseDate":"1999-05-01"},{"name":"Urza's Destiny","code":"UDS","releaseDate":"1999-06-07"},{"name":"Starter 1999","code":"S99","releaseDate":"1999-07-01"},{"name":"Guru","code":"pGRU","releaseDate":"1999-07-12"},{"name":"Worlds","code":"pWOR","releaseDate":"1999-08-04"},{"name":"Wizards of the Coast Online Store","code":"pWOS","releaseDate":"1999-09-04"},{"name":"Mercadian Masques","code":"MMQ","releaseDate":"1999-10-04"},{"name":"Battle Royale Box Set","code":"BRB","releaseDate":"1999-11-12"},{"name":"Super Series","code":"pSUS","releaseDate":"1999-12-01"},{"name":"Friday Night Magic","code":"pFNM","releaseDate":"2000-02-01"},{"name":"European Land Program","code":"pELP","releaseDate":"2000-02-05"},{"name":"Nemesis","code":"NMS","releaseDate":"2000-02-14"},{"name":"Starter 2000","code":"S00","releaseDate":"2000-04-01"},{"name":"Prophecy","code":"PCY","releaseDate":"2000-06-05"},{"name":"Beatdown Box Set","code":"BTD","releaseDate":"2000-10-01"},{"name":"Invasion","code":"INV","releaseDate":"2000-10-02"},{"name":"Planeshift","code":"PLS","releaseDate":"2001-02-05"},{"name":"Seventh Edition","code":"7ED","releaseDate":"2001-04-11"},{"name":"Magic Player Rewards","code":"pMPR","releaseDate":"2001-05-01"},{"name":"Apocalypse","code":"APC","releaseDate":"2001-06-04"},{"name":"Odyssey","code":"ODY","releaseDate":"2001-10-01"},{"name":"Deckmasters","code":"DKM","releaseDate":"2001-12-01"},{"name":"Torment","code":"TOR","releaseDate":"2002-02-04"},{"name":"Judgment","code":"JUD","releaseDate":"2002-05-27"},{"name":"Onslaught","code":"ONS","releaseDate":"2002-10-07"},{"name":"Legions","code":"LGN","releaseDate":"2003-02-03"},{"name":"Scourge","code":"SCG","releaseDate":"2003-05-26"},{"name":"Release Events","code":"pREL","releaseDate":"2003-07-26"},{"name":"Eighth Edition","code":"8ED","releaseDate":"2003-07-28"},{"name":"Mirrodin","code":"MRD","releaseDate":"2003-10-02"},{"name":"Darksteel","code":"DST","releaseDate":"2004-02-06"},{"name":"Fifth Dawn","code":"5DN","releaseDate":"2004-06-04"},{"name":"Champions of Kamigawa","code":"CHK","releaseDate":"2004-10-01"},{"name":"Unhinged","code":"UNH","releaseDate":"2004-11-20"},{"name":"Betrayers of Kamigawa","code":"BOK","releaseDate":"2005-02-04"},{"name":"Saviors of Kamigawa","code":"SOK","releaseDate":"2005-06-03"},{"name":"Ninth Edition","code":"9ED","releaseDate":"2005-07-29"},{"name":"Ravnica: City of Guilds","code":"RAV","releaseDate":"2005-10-07"},{"name":"Two-Headed Giant Tournament","code":"p2HG","releaseDate":"2005-12-09"},{"name":"WPN and Gateway","code":"pWPN","releaseDate":"2006-01-01"},{"name":"Guildpact","code":"GPT","releaseDate":"2006-02-03"},{"name":"Champs and States","code":"pCMP","releaseDate":"2006-03-18"},{"name":"Dissension","code":"DIS","releaseDate":"2006-05-05"},{"name":"Coldsnap","code":"CSP","releaseDate":"2006-07-21"},{"name":"Coldsnap Theme Decks","code":"CST","releaseDate":"2006-07-21"},{"name":"Time Spiral","code":"TSP","releaseDate":"2006-10-06"},{"name":"Time Spiral \"Timeshifted\"","code":"TSB","releaseDate":"2006-10-06"},{"name":"Happy Holidays","code":"pHHO","releaseDate":"2006-12-31"},{"name":"Planar Chaos","code":"PLC","releaseDate":"2007-02-02"},{"name":"Pro Tour","code":"pPRO","releaseDate":"2007-02-09"},{"name":"Grand Prix","code":"pGPX","releaseDate":"2007-02-24"},{"name":"Future Sight","code":"FUT","releaseDate":"2007-05-04"},{"name":"Tenth Edition","code":"10E","releaseDate":"2007-07-13"},{"name":"Magic Game Day","code":"pMGD","releaseDate":"2007-07-14"},{"name":"Masters Edition","code":"MED","releaseDate":"2007-09-10"},{"name":"Lorwyn","code":"LRW","releaseDate":"2007-10-12"},{"name":"Duel Decks: Elves vs. Goblins","code":"EVG","releaseDate":"2007-11-16"},{"name":"Launch Parties","code":"pLPA","releaseDate":"2008-02-01"},{"name":"Morningtide","code":"MOR","releaseDate":"2008-02-01"},{"name":"15th Anniversary","code":"p15A","releaseDate":"2008-04-01"},{"name":"Shadowmoor","code":"SHM","releaseDate":"2008-05-02"},{"name":"Summer of Magic","code":"pSUM","releaseDate":"2007-07-21"},{"name":"Eventide","code":"EVE","releaseDate":"2008-07-25"},{"name":"From the Vault: Dragons","code":"DRB","releaseDate":"2008-08-29"},{"name":"Masters Edition II","code":"ME2","releaseDate":"2008-09-22"},{"name":"Shards of Alara","code":"ALA","releaseDate":"2008-10-03"},{"name":"Duel Decks: Jace vs. Chandra","code":"DD2","releaseDate":"2008-11-07"},{"name":"Conflux","code":"CON","releaseDate":"2009-02-06"},{"name":"Duel Decks: Divine vs. Demonic","code":"DDC","releaseDate":"2009-04-10"},{"name":"Alara Reborn","code":"ARB","releaseDate":"2009-04-30"},{"name":"Magic 2010","code":"M10","releaseDate":"2009-07-17"},{"name":"From the Vault: Exiled","code":"V09","releaseDate":"2009-08-28"},{"name":"Planechase","code":"HOP","releaseDate":"2009-09-04"},{"name":"Masters Edition III","code":"ME3","releaseDate":"2009-09-07"},{"name":"Zendikar","code":"ZEN","releaseDate":"2009-10-02"},{"name":"Duel Decks: Garruk vs. Liliana","code":"DDD","releaseDate":"2009-10-30"},{"name":"Premium Deck Series: Slivers","code":"H09","releaseDate":"2009-11-20"},{"name":"Worldwake","code":"WWK","releaseDate":"2010-02-05"},{"name":"Duel Decks: Phyrexia vs. the Coalition","code":"DDE","releaseDate":"2010-03-19"},{"name":"Rise of the Eldrazi","code":"ROE","releaseDate":"2010-04-23"},{"name":"Duels of the Planeswalkers","code":"DPA","releaseDate":"2010-06-04"},{"name":"Archenemy","code":"ARC","releaseDate":"2010-06-18"},{"name":"Magic 2011","code":"M11","releaseDate":"2010-07-16"},{"name":"From the Vault: Relics","code":"V10","releaseDate":"2010-08-27"},{"name":"Duel Decks: Elspeth vs. Tezzeret","code":"DDF","releaseDate":"2010-09-03"},{"name":"Scars of Mirrodin","code":"SOM","releaseDate":"2010-10-01"},{"name":"Premium Deck Series: Fire and Lightning","code":"PD2","releaseDate":"2010-11-19"},{"name":"Masters Edition IV","code":"ME4","releaseDate":"2011-01-10"},{"name":"Mirrodin Besieged","code":"MBS","releaseDate":"2011-02-04"},{"name":"Duel Decks: Knights vs. Dragons","code":"DDG","releaseDate":"2011-04-01"},{"name":"New Phyrexia","code":"NPH","releaseDate":"2011-05-13"},{"name":"Magic: The Gathering-Commander","code":"CMD","releaseDate":"2011-06-17"},{"name":"Magic 2012","code":"M12","releaseDate":"2011-07-15"},{"name":"From the Vault: Legends","code":"V11","releaseDate":"2011-08-26"},{"name":"Duel Decks: Ajani vs. Nicol Bolas","code":"DDH","releaseDate":"2011-09-02"},{"name":"Innistrad","code":"ISD","releaseDate":"2011-09-30"},{"name":"Premium Deck Series: Graveborn","code":"PD3","releaseDate":"2011-11-18"},{"name":"Dark Ascension","code":"DKA","releaseDate":"2012-02-03"},{"name":"Duel Decks: Venser vs. Koth","code":"DDI","releaseDate":"2012-03-30"},{"name":"Avacyn Restored","code":"AVR","releaseDate":"2012-05-04"},{"name":"Planechase 2012 Edition","code":"PC2","releaseDate":"2012-06-01"},{"name":"Magic 2013","code":"M13","releaseDate":"2012-07-13"},{"name":"From the Vault: Realms","code":"V12","releaseDate":"2012-08-31"},{"name":"Duel Decks: Izzet vs. Golgari","code":"DDJ","releaseDate":"2012-09-07"},{"name":"Return to Ravnica","code":"RTR","releaseDate":"2012-10-05"},{"name":"Commander's Arsenal","code":"CM1","releaseDate":"2012-11-02"},{"name":"Gatecrash","code":"GTC","releaseDate":"2013-02-01"},{"name":"Duel Decks: Sorin vs. Tibalt","code":"DDK","releaseDate":"2013-03-15"},{"name":"World Magic Cup Qualifiers","code":"pWCQ","releaseDate":"2013-04-06"},{"name":"Dragon's Maze","code":"DGM","releaseDate":"2013-05-03"},{"name":"Modern Masters","code":"MMA","releaseDate":"2013-06-07"},{"name":"Magic 2014 Core Set","code":"M14","releaseDate":"2013-07-19"},{"name":"From the Vault: Twenty","code":"V13","releaseDate":"2013-08-23"},{"name":"Duel Decks: Heroes vs. Monsters","code":"DDL","releaseDate":"2013-09-06"},{"name":"Theros","code":"THS","releaseDate":"2013-09-27"},{"name":"Commander 2013 Edition","code":"C13","releaseDate":"2013-11-01"},{"name":"Born of the Gods","code":"BNG","releaseDate":"2014-02-07"},{"name":"Duel Decks: Jace vs. Vraska","code":"DDM","releaseDate":"2014-03-14"},{"name":"Journey into Nyx","code":"JOU","releaseDate":"2014-05-02"},{"name":"Modern Event Deck 2014","code":"MD1","releaseDate":"2014-05-30"},{"name":"Magic: The Gathering—Conspiracy","code":"CNS","releaseDate":"2014-06-06"},{"name":"Vintage Masters","code":"VMA","releaseDate":"2014-06-16"},{"name":"Magic 2015 Core Set","code":"M15","releaseDate":"2014-07-18"},{"name":"From the Vault: Annihilation (2014)","code":"V14","releaseDate":"2014-08-22"},{"name":"Duel Decks: Speed vs. Cunning","code":"DDN","releaseDate":"2014-09-05"},{"name":"Khans of Tarkir","code":"KTK","releaseDate":"2014-09-26"},{"name":"Commander 2014","code":"C14","releaseDate":"2014-11-07"},{"name":"Duel Decks Anthology, Divine vs. Demonic","code":"DD3_DVD","releaseDate":"2014-12-05"},{"name":"Duel Decks Anthology, Elves vs. Goblins","code":"DD3_EVG","releaseDate":"2014-12-05"},{"name":"Duel Decks Anthology, Garruk vs. Liliana","code":"DD3_GVL","releaseDate":"2014-12-05"},{"name":"Duel Decks Anthology, Jace vs. Chandra","code":"DD3_JVC","releaseDate":"2014-12-05"},{"name":"Ugin's Fate promos","code":"FRF_UGIN","releaseDate":"2015-01-17"},{"name":"Fate Reforged","code":"FRF","releaseDate":"2015-01-23"},{"name":"Duel Decks: Elspeth vs. Kiora","code":"DDO","releaseDate":"2015-02-27"},{"name":"Dragons of Tarkir","code":"DTK","releaseDate":"2015-03-27"},{"name":"Tempest Remastered","code":"TPR","releaseDate":"2015-05-06"},{"name":"Modern Masters 2015 Edition","code":"MM2","releaseDate":"2015-05-22"}]
\ No newline at end of file diff --git a/src/eu/equalparts/cardbase/data/Card.java b/src/eu/equalparts/cardbase/data/Card.java index d125c54..8e25d56 100644 --- a/src/eu/equalparts/cardbase/data/Card.java +++ b/src/eu/equalparts/cardbase/data/Card.java @@ -3,231 +3,33 @@ 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; + + public String layout; + public String name; + public ArrayList<String> names; + public String manaCost; + public Integer cmc; + public ArrayList<String> colors; + public String type; + public ArrayList<String> supertypes; + public ArrayList<String> types; + public ArrayList<String> subtypes; + public String rarity; + public String text; + public String flavor; + public String artist; + public String number; + public String power; + public String toughness; + public Integer loyalty; + public Integer multiverseid; + public ArrayList<String> variations; + public String imageName; + public String border; + public String watermark; // Not part of JSON, will be set later - private String setCode; - private String setName; + public String setCode; + public 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 index 14c30a5..70ae0ea 100644 --- a/src/eu/equalparts/cardbase/data/CardBase.java +++ b/src/eu/equalparts/cardbase/data/CardBase.java @@ -1,23 +1,12 @@ package eu.equalparts.cardbase.data; -import java.io.File; + +import java.util.ArrayList; public class CardBase { - public static void main(String... args) { - - } + private ArrayList<Card> cards; + private ArrayList<Deck> decks; + + - /** - * 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/CardBaseManager.java b/src/eu/equalparts/cardbase/data/CardBaseManager.java new file mode 100644 index 0000000..acf5a3a --- /dev/null +++ b/src/eu/equalparts/cardbase/data/CardBaseManager.java @@ -0,0 +1,43 @@ +package eu.equalparts.cardbase.data; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + +import eu.equalparts.cardbase.query.IO; + +public class CardBaseManager { + + private ArrayList<MetaCardSet> metaSets; + + 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 { + metaSets = IO.getAllMetaSets(); + } + + /** + * Create an empty CardBase. + * @throws IOException + * @throws JsonMappingException + * @throws JsonParseException + */ + public CardBaseManager() throws JsonParseException, JsonMappingException, IOException { + metaSets = IO.getAllMetaSets(); + } + + public ArrayList<MetaCardSet> getAllMetaSets() { + return metaSets; + } + +} diff --git a/src/eu/equalparts/cardbase/data/CardSet.java b/src/eu/equalparts/cardbase/data/CardSet.java index 97622db..2c8f950 100644 --- a/src/eu/equalparts/cardbase/data/CardSet.java +++ b/src/eu/equalparts/cardbase/data/CardSet.java @@ -3,84 +3,26 @@ 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 String name; + public String code; + public String releaseDate; + public String border; + public String type; + public String block; + public String gathererCode; + public ArrayList<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 card, or null if no card is found with that number. + */ public Card getCardByNumber(String number) { for (Card card : cards) { - if (card.getNumber().equals(number)) + if (card.number.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/data/Deck.java b/src/eu/equalparts/cardbase/data/Deck.java new file mode 100644 index 0000000..50f1129 --- /dev/null +++ b/src/eu/equalparts/cardbase/data/Deck.java @@ -0,0 +1,5 @@ +package eu.equalparts.cardbase.data; + +public class Deck { + +} diff --git a/src/eu/equalparts/cardbase/data/MetaCardSet.java b/src/eu/equalparts/cardbase/data/MetaCardSet.java new file mode 100644 index 0000000..4ddf228 --- /dev/null +++ b/src/eu/equalparts/cardbase/data/MetaCardSet.java @@ -0,0 +1,39 @@ +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; + } + + @Override + public String toString() { + return String.format("%1$-12s : %2$s", code, name, releaseDate); + } + +} diff --git a/src/eu/equalparts/cardbase/query/IO.java b/src/eu/equalparts/cardbase/query/IO.java new file mode 100644 index 0000000..65a3a34 --- /dev/null +++ b/src/eu/equalparts/cardbase/query/IO.java @@ -0,0 +1,43 @@ +package eu.equalparts.cardbase.query; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; + +import com.fasterxml.jackson.core.JsonGenerationException; +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.CardBase; +import eu.equalparts.cardbase.data.CardSet; +import eu.equalparts.cardbase.data.MetaCardSet; + +public class IO { + + public static final String BASE_URL = "http://mtgjson.com/json/"; + public static final String SETS_URL = BASE_URL + "SetList.json"; + + private static final ObjectMapper mapper = new ObjectMapper(); + + public static CardSet getCardSet(String setId) { + return new CardSet(); + } + + public static ArrayList<MetaCardSet> getAllMetaSets() throws JsonParseException, JsonMappingException, IOException { + //mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + return mapper.readValue(new URL(SETS_URL), new TypeReference<ArrayList<MetaCardSet>>() {}); + } + + public static CardBase readCardBase(File file) throws JsonParseException, JsonMappingException, IOException { + return mapper.readValue(file, CardBase.class); + } + + public static void writeCardBase(File file, CardBase cardBase) throws JsonGenerationException, JsonMappingException, IOException { + mapper.writeValue(file, cardBase); + } + +} diff --git a/src/eu/equalparts/cardbase/query/Test.java b/src/eu/equalparts/cardbase/query/Test.java index 646139e..2050c76 100644 --- a/src/eu/equalparts/cardbase/query/Test.java +++ b/src/eu/equalparts/cardbase/query/Test.java @@ -7,7 +7,6 @@ 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; @@ -50,7 +49,7 @@ public class Test { // @SuppressWarnings("unchecked") CardSet set = mapper.readValue(new File("M15.json"), CardSet.class); - System.out.println(set.getCardByNumber("281").getName()); + System.out.println(set.getCardByNumber("281").name); } @@ -58,9 +57,9 @@ public class Test { List<Card> allCards = new ArrayList<Card>(); for (CardSet set : sets.values()) { - for (Card card : set.getCards()) { - card.setSetCode(set.getCode()); - card.setSetName(set.getName()); + for (Card card : set.cards) { + card.setCode = set.code; + card.setName = set.name; // System.out.println(set.getName() + ": " + card.getName()); allCards.add(card); diff --git a/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java b/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java index 4b746b2..2806a9e 100644 --- a/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java +++ b/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java @@ -5,7 +5,11 @@ import java.io.File; import java.io.IOException; import java.io.InputStreamReader; -import eu.equalparts.cardbase.data.CardBase; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + +import eu.equalparts.cardbase.data.CardBaseManager; +import eu.equalparts.cardbase.data.MetaCardSet; /** * This provides a lightweight CLI for interacting with cardbase files. @@ -13,6 +17,10 @@ import eu.equalparts.cardbase.data.CardBase; */ public class CardBaseCLI { + private static String selectedSet = ""; + private static CardBaseManager cbm; + private static boolean exit = false; + /** * Execute the interface. * @@ -21,49 +29,89 @@ public class CardBaseCLI { 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 { + // construct the cardbase + if (args.length > 0) { + System.out.println("Building cardbase from " + args[0]); + cbm = new CardBaseManager(new File(args[0])); + } else { + System.out.println("No cardbase file was provided, initialising a clean cardbase"); + cbm = new CardBaseManager(); + } + // 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; - } - } + + parse(commands); } + + } catch (JsonParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JsonMappingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } catch (IOException e) { + // TODO Auto-generated catch block e.printStackTrace(); } - } - + + private static void parse(String[] commands) { + if (commands.length > 0) { + switch (commands[0]) { + /* + * Exit procedures + */ + case "exit": + exit = true; + break; + /* + * Show help (externalised?) + */ + case "help": + System.out.println("google it"); + break; + /* + * Print a list of valid set codes + */ + case "sets": + for (MetaCardSet mcs : cbm.getAllMetaSets()) { + System.out.println(mcs); + } + break; + /* + * Select a set, any card numbers provided will be fetched from that set + */ + case "set": + for (MetaCardSet mcs : cbm.getAllMetaSets()) { + if (mcs.getCode().equalsIgnoreCase(commands[1])) { + System.out.println("Selected set: " + mcs.getName()); + selectedSet = mcs.getCode(); + return; + } + } + System.out.println(commands[1] + " does not correspond to any set (use \"sets\" to see all valid set codes)"); + break; + /* + * Write current CardBase to file + */ + case "write": + break; + /* + * Try to parse a card number and get it from the set + */ + default: + break; + } + } + } + } |