From bee1b6d71ed8ae65e4e6405c140c3fd17da7a2b5 Mon Sep 17 00:00:00 2001 From: Maxopoly Date: Thu, 4 Nov 2021 17:33:57 +0100 Subject: [PATCH] Rename package and cleanup --- pom.xml | 2 +- .../github/{maxopoly => }/tcgdex/Ability.java | 48 ++-- .../github/{maxopoly => }/tcgdex/Attack.java | 50 ++-- .../{maxopoly => }/tcgdex/CardInfo.java | 262 +++++++++--------- .../{maxopoly => }/tcgdex/CardResume.java | 26 +- .../{maxopoly => }/tcgdex/Categories.java | 2 +- .../{maxopoly => }/tcgdex/Rarities.java | 2 +- .../{maxopoly => }/tcgdex/SeriesInfo.java | 12 +- .../{maxopoly => }/tcgdex/SeriesResume.java | 10 +- .../github/{maxopoly => }/tcgdex/SetInfo.java | 42 +-- .../{maxopoly => }/tcgdex/SetResume.java | 32 +-- .../{maxopoly => }/tcgdex/TCGDexAPI.java | 156 +++++------ .../github/{maxopoly => }/tcgdex/Types.java | 2 +- .../github/{maxopoly => }/tcgdex/Utils.java | 2 +- .../{maxopoly => }/tcgdex/Weakness.java | 29 +- .../github/{maxopoly => }/tcgdex/TestAPI.java | 15 +- 16 files changed, 355 insertions(+), 337 deletions(-) rename src/main/java/com/github/{maxopoly => }/tcgdex/Ability.java (96%) rename src/main/java/com/github/{maxopoly => }/tcgdex/Attack.java (97%) rename src/main/java/com/github/{maxopoly => }/tcgdex/CardInfo.java (99%) rename src/main/java/com/github/{maxopoly => }/tcgdex/CardResume.java (97%) rename src/main/java/com/github/{maxopoly => }/tcgdex/Categories.java (87%) rename src/main/java/com/github/{maxopoly => }/tcgdex/Rarities.java (88%) rename src/main/java/com/github/{maxopoly => }/tcgdex/SeriesInfo.java (93%) rename src/main/java/com/github/{maxopoly => }/tcgdex/SeriesResume.java (93%) rename src/main/java/com/github/{maxopoly => }/tcgdex/SetInfo.java (98%) rename src/main/java/com/github/{maxopoly => }/tcgdex/SetResume.java (98%) rename src/main/java/com/github/{maxopoly => }/tcgdex/TCGDexAPI.java (99%) rename src/main/java/com/github/{maxopoly => }/tcgdex/Types.java (95%) rename src/main/java/com/github/{maxopoly => }/tcgdex/Utils.java (97%) rename src/main/java/com/github/{maxopoly => }/tcgdex/Weakness.java (96%) rename src/test/java/com/github/{maxopoly => }/tcgdex/TestAPI.java (92%) diff --git a/pom.xml b/pom.xml index b0462cc..2c7d148 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.github.maxopoly + com.github.tcgdex tcgdex diff --git a/src/main/java/com/github/maxopoly/tcgdex/Ability.java b/src/main/java/com/github/tcgdex/Ability.java similarity index 96% rename from src/main/java/com/github/maxopoly/tcgdex/Ability.java rename to src/main/java/com/github/tcgdex/Ability.java index 20344be..030b1c9 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/Ability.java +++ b/src/main/java/com/github/tcgdex/Ability.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import java.util.ArrayList; import java.util.Collections; @@ -29,16 +29,17 @@ public class Ability { private final String name; private final String effect; + Ability(JSONObject json) { + this(json.getString("type"), json.getString("name"), json.getString("effect")); + } + Ability(String type, String name, String effect) { this.type = type; this.name = name; this.effect = effect; } - Ability(JSONObject json) { - this(json.getString("type"), json.getString("name"), json.getString("effect")); - } - + @Override public boolean equals(Object o) { if (!(o instanceof Ability)) { return false; @@ -48,24 +49,6 @@ public class Ability { new Object[] { other.type, other.name, other.effect }); } - public int hashCode() { - return Objects.hash(this.type, this.name, this.effect); - } - - /** - * @return Type of the ability, for example 'Poke-POWER' - */ - public String getType() { - return type; - } - - /** - * @return Name of the ability - */ - public String getName() { - return name; - } - /** * * @return Description/Effect of the ability @@ -74,4 +57,23 @@ public class Ability { return effect; } + /** + * @return Name of the ability + */ + public String getName() { + return name; + } + + /** + * @return Type of the ability, for example 'Poke-POWER' + */ + public String getType() { + return type; + } + + @Override + public int hashCode() { + return Objects.hash(this.type, this.name, this.effect); + } + } diff --git a/src/main/java/com/github/maxopoly/tcgdex/Attack.java b/src/main/java/com/github/tcgdex/Attack.java similarity index 97% rename from src/main/java/com/github/maxopoly/tcgdex/Attack.java rename to src/main/java/com/github/tcgdex/Attack.java index 69a9752..28aad87 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/Attack.java +++ b/src/main/java/com/github/tcgdex/Attack.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import java.util.ArrayList; import java.util.Collections; @@ -30,6 +30,11 @@ public class Attack { private final String effect; private final String damage; + Attack(JSONObject json) { + this(Types.parse(json.getJSONArray("cost")), json.getString("name"), json.optString("effect"), + json.optString("damage")); + } + Attack(List cost, String name, String effect, String damage) { super(); this.cost = cost; @@ -38,11 +43,7 @@ public class Attack { this.damage = damage; } - Attack(JSONObject json) { - this(Types.parse(json.getJSONArray("cost")), json.getString("name"), json.optString("effect"), - json.optString("damage")); - } - + @Override public boolean equals(Object o) { if (!(o instanceof Attack)) { return false; @@ -52,10 +53,6 @@ public class Attack { new Object[] { other.cost, other.name, other.effect, other.damage }); } - public int hashCode() { - return Objects.hash(this.cost, this.name, this.effect, this.damage); - } - /** * @return Cost of the attack in the same order as listed on the card */ @@ -63,20 +60,6 @@ public class Attack { return cost; } - /** - * @return Name of the attack - */ - public String getName() { - return name; - } - - /** - * @return Effect/Description of the attack, may be null for attacks without text - */ - public String getEffect() { - return effect; - } - /** * @return Damage the attack deals. May just be a number like '30', but can also * be a multiplier like 'x20' @@ -85,4 +68,23 @@ public class Attack { return damage; } + /** + * @return Effect/Description of the attack, may be null for attacks without text + */ + public String getEffect() { + return effect; + } + + /** + * @return Name of the attack + */ + public String getName() { + return name; + } + + @Override + public int hashCode() { + return Objects.hash(this.cost, this.name, this.effect, this.damage); + } + } diff --git a/src/main/java/com/github/maxopoly/tcgdex/CardInfo.java b/src/main/java/com/github/tcgdex/CardInfo.java similarity index 99% rename from src/main/java/com/github/maxopoly/tcgdex/CardInfo.java rename to src/main/java/com/github/tcgdex/CardInfo.java index b746557..6d76763 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/CardInfo.java +++ b/src/main/java/com/github/tcgdex/CardInfo.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import java.util.ArrayList; import java.util.List; @@ -34,35 +34,6 @@ public class CardInfo extends CardResume { private final Integer retreat; private final String regulationMark; - public CardInfo(String id, String localId, String name, String image, String illustrator, Rarities rarity, - Categories category, boolean hasNormalVariant, boolean hasReverseVariant, boolean hasHolo, - boolean hasFirstEditionPic, SetResume set, List dexIDs, Integer hp, List types, - String evolveFrom, String description, String level, String stage, String suffix, List attacks, - List weakness, List abilities, Integer retreat, String regulationMark) { - super(id, localId, name, image); - this.illustrator = illustrator; - this.rarity = rarity; - this.category = category; - this.hasNormalVariant = hasNormalVariant; - this.hasReverseVariant = hasReverseVariant; - this.hasHolo = hasHolo; - this.hasFirstEditionPic = hasFirstEditionPic; - this.set = set; - this.dexIDs = dexIDs; - this.hp = hp; - this.types = types; - this.evolveFrom = evolveFrom; - this.description = description; - this.level = level; - this.stage = stage; - this.suffix = suffix; - this.attacks = attacks; - this.weakness = weakness; - this.abilities = abilities; - this.retreat = retreat; - this.regulationMark = regulationMark; - } - CardInfo(JSONObject json) { super(json); this.illustrator = json.getString("illustrator"); @@ -95,6 +66,35 @@ public class CardInfo extends CardResume { this.abilities = Ability.parse(json.optJSONArray("abilities")); } + public CardInfo(String id, String localId, String name, String image, String illustrator, Rarities rarity, + Categories category, boolean hasNormalVariant, boolean hasReverseVariant, boolean hasHolo, + boolean hasFirstEditionPic, SetResume set, List dexIDs, Integer hp, List types, + String evolveFrom, String description, String level, String stage, String suffix, List attacks, + List weakness, List abilities, Integer retreat, String regulationMark) { + super(id, localId, name, image); + this.illustrator = illustrator; + this.rarity = rarity; + this.category = category; + this.hasNormalVariant = hasNormalVariant; + this.hasReverseVariant = hasReverseVariant; + this.hasHolo = hasHolo; + this.hasFirstEditionPic = hasFirstEditionPic; + this.set = set; + this.dexIDs = dexIDs; + this.hp = hp; + this.types = types; + this.evolveFrom = evolveFrom; + this.description = description; + this.level = level; + this.stage = stage; + this.suffix = suffix; + this.attacks = attacks; + this.weakness = weakness; + this.abilities = abilities; + this.retreat = retreat; + this.regulationMark = regulationMark; + } + /** * @return Pokemon's abilities. May be empty if it doesn't have any, but never * null @@ -103,14 +103,6 @@ public class CardInfo extends CardResume { return abilities; } - /** - * - * @return Card's regulation mark. May be null if unknown or doesn't exist - */ - public String getRegulationMark() { - return regulationMark; - } - /** * @return Attacks the pokemon has. Empty for cards without attacks */ @@ -119,17 +111,43 @@ public class CardInfo extends CardResume { } /** - * @return Weaknesses the pokemon has. Empty for cards without attacks + * + * @return Card category */ - public List getWeakness() { - return weakness; + public Categories getCategory() { + return category; } /** - * @return Card's retreat. Will be null for cards without retreat + * + * @return List of the national pokedex IDs of the pokemon on the card (may be + * multiple) */ - public Integer getRetreat() { - return retreat; + public List getDexIDs() { + return dexIDs; + } + + /** + * + * @return Card effect/description, may be null + */ + public String getEffect() { + return description; + } + + /** + * + * @return Name of the pokemon this one evolves from + */ + public String getEvolveFrom() { + return evolveFrom; + } + + /** + * @return HP of the pokemon, will be null if the card is not a pokemon + */ + public Integer getHp() { + return hp; } /** @@ -140,6 +158,14 @@ public class CardInfo extends CardResume { return illustrator; } + /** + * + * @return Pokemon level, may be 'X', hence not an integer + */ + public String getLevel() { + return level; + } + /** * * @return Card rarity @@ -150,10 +176,68 @@ public class CardInfo extends CardResume { /** * - * @return Card category + * @return Card's regulation mark. May be null if unknown or doesn't exist */ - public Categories getCategory() { - return category; + public String getRegulationMark() { + return regulationMark; + } + + /** + * @return Card's retreat. Will be null for cards without retreat + */ + public Integer getRetreat() { + return retreat; + } + + /** + * @return Resume of the set the card belongs to + */ + public SetResume getSet() { + return set; + } + + /** + * @return Pokemon's stage, like 'Basic' + */ + public String getStage() { + return stage; + } + + /** + * @return Suffix, like 'V', may be null + */ + public String getSuffix() { + return suffix; + } + + /** + * @return Types of the pokemon + */ + public List getTypes() { + return types; + } + + /** + * @return Weaknesses the pokemon has. Empty for cards without attacks + */ + public List getWeakness() { + return weakness; + } + + /** + * + * @return Does the card have a small first edition in the middle left + */ + public boolean hasFirstEditionPic() { + return hasFirstEditionPic; + } + + /** + * + * @return Does the card have a holo variant (picture is shining) + */ + public boolean hasHoloVariant() { + return hasHolo; } /** @@ -172,88 +256,4 @@ public class CardInfo extends CardResume { return hasReverseVariant; } - /** - * - * @return Does the card have a holo variant (picture is shining) - */ - public boolean hasHoloVariant() { - return hasHolo; - } - - /** - * - * @return Does the card have a small first edition in the middle left - */ - public boolean hasFirstEditionPic() { - return hasFirstEditionPic; - } - - /** - * @return Resume of the set the card belongs to - */ - public SetResume getSet() { - return set; - } - - /** - * - * @return List of the national pokedex IDs of the pokemon on the card (may be - * multiple) - */ - public List getDexIDs() { - return dexIDs; - } - - /** - * @return HP of the pokemon, will be null if the card is not a pokemon - */ - public Integer getHp() { - return hp; - } - - /** - * @return Types of the pokemon - */ - public List getTypes() { - return types; - } - - /** - * - * @return Name of the pokemon this one evolves from - */ - public String getEvolveFrom() { - return evolveFrom; - } - - /** - * - * @return Card effect/description, may be null - */ - public String getEffect() { - return description; - } - - /** - * - * @return Pokemon level, may be 'X', hence not an integer - */ - public String getLevel() { - return level; - } - - /** - * @return Pokemon's stage, like 'Basic' - */ - public String getStage() { - return stage; - } - - /** - * @return Suffix, like 'V', may be null - */ - public String getSuffix() { - return suffix; - } - } diff --git a/src/main/java/com/github/maxopoly/tcgdex/CardResume.java b/src/main/java/com/github/tcgdex/CardResume.java similarity index 97% rename from src/main/java/com/github/maxopoly/tcgdex/CardResume.java rename to src/main/java/com/github/tcgdex/CardResume.java index 2d9a239..3589ba5 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/CardResume.java +++ b/src/main/java/com/github/tcgdex/CardResume.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import java.util.ArrayList; import java.util.Collections; @@ -29,6 +29,10 @@ public class CardResume { private final String name; private final String image; + CardResume(JSONObject json) { + this(json.getString("id"), json.getString("localId"), json.getString("name"), json.optString("image")); + } + CardResume(String id, String localId, String name, String image) { this.id = id; this.localId = localId; @@ -36,10 +40,6 @@ public class CardResume { this.image = image; } - CardResume(JSONObject json) { - this(json.getString("id"), json.getString("localId"), json.getString("name"), json.optString("image")); - } - /** * @return Globally unique card ID based on the set ID and the cards ID within the set */ @@ -47,6 +47,14 @@ public class CardResume { return id; } + /** + * + * @return Card image, can be null + */ + public String getImage() { + return image; + } + /** * @return ID indexing this card within its set, usually just its number */ @@ -61,12 +69,4 @@ public class CardResume { public String getName() { return name; } - - /** - * - * @return Card image, can be null - */ - public String getImage() { - return image; - } } diff --git a/src/main/java/com/github/maxopoly/tcgdex/Categories.java b/src/main/java/com/github/tcgdex/Categories.java similarity index 87% rename from src/main/java/com/github/maxopoly/tcgdex/Categories.java rename to src/main/java/com/github/tcgdex/Categories.java index 224b204..aec05b1 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/Categories.java +++ b/src/main/java/com/github/tcgdex/Categories.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; public enum Categories { diff --git a/src/main/java/com/github/maxopoly/tcgdex/Rarities.java b/src/main/java/com/github/tcgdex/Rarities.java similarity index 88% rename from src/main/java/com/github/maxopoly/tcgdex/Rarities.java rename to src/main/java/com/github/tcgdex/Rarities.java index a499231..a21bd58 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/Rarities.java +++ b/src/main/java/com/github/tcgdex/Rarities.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; public enum Rarities { diff --git a/src/main/java/com/github/maxopoly/tcgdex/SeriesInfo.java b/src/main/java/com/github/tcgdex/SeriesInfo.java similarity index 93% rename from src/main/java/com/github/maxopoly/tcgdex/SeriesInfo.java rename to src/main/java/com/github/tcgdex/SeriesInfo.java index bb4d95d..756713e 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/SeriesInfo.java +++ b/src/main/java/com/github/tcgdex/SeriesInfo.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import java.util.List; @@ -12,16 +12,16 @@ public class SeriesInfo extends SeriesResume { private final List sets; - SeriesInfo(String id, String name, List sets) { - super(id, name); - this.sets = sets; - } - SeriesInfo(JSONObject json) { super(json); this.sets = SetResume.parse(json.optJSONArray("sets")); } + SeriesInfo(String id, String name, List sets) { + super(id, name); + this.sets = sets; + } + /** * @return Resumes of the sets part of this series */ diff --git a/src/main/java/com/github/maxopoly/tcgdex/SeriesResume.java b/src/main/java/com/github/tcgdex/SeriesResume.java similarity index 93% rename from src/main/java/com/github/maxopoly/tcgdex/SeriesResume.java rename to src/main/java/com/github/tcgdex/SeriesResume.java index 7ebb655..70245f7 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/SeriesResume.java +++ b/src/main/java/com/github/tcgdex/SeriesResume.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import org.json.JSONObject; @@ -11,15 +11,15 @@ public class SeriesResume { private final String id; private final String name; + SeriesResume(JSONObject json) { + this(json.getString("id"), json.getString("name")); + } + SeriesResume(String id, String name) { this.id = id; this.name = name; } - SeriesResume(JSONObject json) { - this(json.getString("id"), json.getString("name")); - } - /** * @return Serie unique ID */ diff --git a/src/main/java/com/github/maxopoly/tcgdex/SetInfo.java b/src/main/java/com/github/tcgdex/SetInfo.java similarity index 98% rename from src/main/java/com/github/maxopoly/tcgdex/SetInfo.java rename to src/main/java/com/github/tcgdex/SetInfo.java index 5b1bbb7..18be0c9 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/SetInfo.java +++ b/src/main/java/com/github/tcgdex/SetInfo.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import java.time.LocalDate; import java.time.format.DateTimeFormatter; @@ -58,6 +58,20 @@ public class SetInfo extends SetResume { this.cards = cards; } + /** + * @return All cards part of the set + */ + public List getCards() { + return cards; + } + + /** + * @return Amount of first edition cards the set has + */ + public int getFirstEdCardCount() { + return firstEd; + } + /** * @return Amount of holo cards the set has */ @@ -73,10 +87,10 @@ public class SetInfo extends SetResume { } /** - * @return Amount of first edition cards the set has + * @return When the set was released */ - public int getFirstEdCardCount() { - return firstEd; + public LocalDate getReleaseDate() { + return releaseDate; } /** @@ -101,10 +115,10 @@ public class SetInfo extends SetResume { } /** - * @return When the set was released + * @return Ability to use this set in Expanded competitions */ - public LocalDate getReleaseDate() { - return releaseDate; + public boolean isLegalInExpanded() { + return legalInExpanded; } /** @@ -113,18 +127,4 @@ public class SetInfo extends SetResume { public boolean isLegalInStandard() { return legalInStandard; } - - /** - * @return Ability to use this set in Expanded competitions - */ - public boolean isLegalInExpanded() { - return legalInExpanded; - } - - /** - * @return All cards part of the set - */ - public List getCards() { - return cards; - } } diff --git a/src/main/java/com/github/maxopoly/tcgdex/SetResume.java b/src/main/java/com/github/tcgdex/SetResume.java similarity index 98% rename from src/main/java/com/github/maxopoly/tcgdex/SetResume.java rename to src/main/java/com/github/tcgdex/SetResume.java index afe4768..44bb581 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/SetResume.java +++ b/src/main/java/com/github/tcgdex/SetResume.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import java.util.ArrayList; import java.util.Collections; @@ -31,6 +31,11 @@ public class SetResume { private final int officialCardCount; private final int totalCardCount; + public SetResume(JSONObject json) { + this(json.getString("id"), json.getString("name"), json.optString("logo"), json.optString("symbol"), + json.getJSONObject("cardCount").getInt("total"), json.getJSONObject("cardCount").getInt("official")); + } + SetResume(String id, String name, String logo, String symbol, int officialCardCount, int totalCardCount) { this.id = id; this.name = name; @@ -40,11 +45,6 @@ public class SetResume { this.totalCardCount = totalCardCount; } - public SetResume(JSONObject json) { - this(json.getString("id"), json.getString("name"), json.optString("logo"), json.optString("symbol"), - json.getJSONObject("cardCount").getInt("total"), json.getJSONObject("cardCount").getInt("official")); - } - /** * @return Set unique ID */ @@ -52,13 +52,6 @@ public class SetResume { return id; } - /** - * @return Set name - */ - public String getName() { - return name; - } - /** * @return Set logo URL, may be null */ @@ -67,10 +60,10 @@ public class SetResume { } /** - * @return Set symbol URL, may be null + * @return Set name */ - public String getSymbol() { - return symbol; + public String getName() { + return name; } /** @@ -80,6 +73,13 @@ public class SetResume { return officialCardCount; } + /** + * @return Set symbol URL, may be null + */ + public String getSymbol() { + return symbol; + } + /** * @return Total amount of cards in this set */ diff --git a/src/main/java/com/github/maxopoly/tcgdex/TCGDexAPI.java b/src/main/java/com/github/tcgdex/TCGDexAPI.java similarity index 99% rename from src/main/java/com/github/maxopoly/tcgdex/TCGDexAPI.java rename to src/main/java/com/github/tcgdex/TCGDexAPI.java index 5ff4f0b..fbc9e8f 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/TCGDexAPI.java +++ b/src/main/java/com/github/tcgdex/TCGDexAPI.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import java.io.IOException; import java.util.ArrayList; @@ -32,6 +32,16 @@ public class TCGDexAPI { this.language = language; } + private String buildURL(String path, String... optional) { + String result = String.format(API_URL, this.language.getAPIID(), path); + // not gonna do a string builder here, because we intend this array to be of + // length 1 in almost all cases + for (String opt : optional) { + result += "/" + opt; + } + return result; + } + /** * Gets a list containing the core information for every core * @@ -44,43 +54,23 @@ public class TCGDexAPI { } /** - * Gets detailed information of a card based on a sets identifier and the - * identifier/index of a card within this set. Note that for example 'base4-1' - * is already a combined identifier, here the correct setID would be 'base4' and - * the cardID '1' + * Gets a list of all known card illustrators * - * @param setID Unique ID of the set - * @param cardID ID/index describing the card within the set - * @return Card info obtained + * @return List of all illustrators * @throws IOException Thrown in response to any kind of networking error */ - public CardInfo getCardInfo(String setID, String cardID) throws IOException { - String data = Utils.doGet(buildURL("sets", setID, cardID)); - return new CardInfo(new JSONObject(data)); + public List getAllIllustrators() throws IOException { + return loadStringArrayFrom("illustrators"); } - /** - * Gets detailed information of a card based on its globally unique identifier, - * for example 'base4-1' - * - * @param globalCardID Globally unique ID of the card - * @return Card info obtained - * @throws IOException Thrown in response to any kind of networking error - */ - public CardInfo getCardInfo(String globalCardID) throws IOException { - String data = Utils.doGet(buildURL("cards", globalCardID)); - return new CardInfo(new JSONObject(data)); - } - - /** - * Gets detailed information of a card based on its resume - * - * @param card Card to get info for - * @return Card info obtained - * @throws IOException Thrown in response to any kind of networking error - */ - public CardInfo getCardInfo(CardResume card) throws IOException { - return getCardInfo(card.getId()); + public List getAllPossibleHPValues() throws IOException { + String data = Utils.doGet(buildURL("hp")); + JSONArray json = new JSONArray(data); + List result = new ArrayList<>(); + for (int i = 0; i < json.length(); i++) { + result.add(json.getInt(i)); + } + return result; } /** @@ -111,15 +101,43 @@ public class TCGDexAPI { } /** - * Gets detailed information of a series based on its ID + * Gets detailed information of a card based on its resume * - * @param seriesID ID of the series - * @return Detailed information of the series + * @param card Card to get info for + * @return Card info obtained * @throws IOException Thrown in response to any kind of networking error */ - public SeriesInfo getSeriesInfo(String seriesID) throws IOException { - String data = Utils.doGet(buildURL("series", seriesID)); - return new SeriesInfo(new JSONObject(data)); + public CardInfo getCardInfo(CardResume card) throws IOException { + return getCardInfo(card.getId()); + } + + /** + * Gets detailed information of a card based on its globally unique identifier, + * for example 'base4-1' + * + * @param globalCardID Globally unique ID of the card + * @return Card info obtained + * @throws IOException Thrown in response to any kind of networking error + */ + public CardInfo getCardInfo(String globalCardID) throws IOException { + String data = Utils.doGet(buildURL("cards", globalCardID)); + return new CardInfo(new JSONObject(data)); + } + + /** + * Gets detailed information of a card based on a sets identifier and the + * identifier/index of a card within this set. Note that for example 'base4-1' + * is already a combined identifier, here the correct setID would be 'base4' and + * the cardID '1' + * + * @param setID Unique ID of the set + * @param cardID ID/index describing the card within the set + * @return Card info obtained + * @throws IOException Thrown in response to any kind of networking error + */ + public CardInfo getCardInfo(String setID, String cardID) throws IOException { + String data = Utils.doGet(buildURL("sets", setID, cardID)); + return new CardInfo(new JSONObject(data)); } /** @@ -135,17 +153,17 @@ public class TCGDexAPI { } /** - * Gets detailed information of a set based on its ID + * Gets detailed information of a series based on its ID * - * @param setID ID of the set - * @return Detailed information of the set + * @param seriesID ID of the series + * @return Detailed information of the series * @throws IOException Thrown in response to any kind of networking error */ - public SetInfo getSetInfo(String setID) throws IOException { - String data = Utils.doGet(buildURL("sets", setID)); - return new SetInfo(new JSONObject(data)); + public SeriesInfo getSeriesInfo(String seriesID) throws IOException { + String data = Utils.doGet(buildURL("series", seriesID)); + return new SeriesInfo(new JSONObject(data)); } - + /** * Gets detailed information of a set based on a card belonging to it * @@ -159,36 +177,24 @@ public class TCGDexAPI { return new SetInfo(new JSONObject(data)); } - List loadRarities() throws IOException { - return loadStringArrayFrom("rarities"); + /** + * Gets detailed information of a set based on its ID + * + * @param setID ID of the set + * @return Detailed information of the set + * @throws IOException Thrown in response to any kind of networking error + */ + public SetInfo getSetInfo(String setID) throws IOException { + String data = Utils.doGet(buildURL("sets", setID)); + return new SetInfo(new JSONObject(data)); } List loadCategories() throws IOException { return loadStringArrayFrom("categories"); } - List loadTypes() throws IOException { - return loadStringArrayFrom("types"); - } - - /** - * Gets a list of all known card illustrators - * - * @return List of all illustrators - * @throws IOException Thrown in response to any kind of networking error - */ - public List getAllIllustrators() throws IOException { - return loadStringArrayFrom("illustrators"); - } - - public List getAllPossibleHPValues() throws IOException { - String data = Utils.doGet(buildURL("hp")); - JSONArray json = new JSONArray(data); - List result = new ArrayList<>(); - for (int i = 0; i < json.length(); i++) { - result.add(json.getInt(i)); - } - return result; + List loadRarities() throws IOException { + return loadStringArrayFrom("rarities"); } private List loadStringArrayFrom(String path) throws IOException { @@ -201,14 +207,8 @@ public class TCGDexAPI { return result; } - private String buildURL(String path, String... optional) { - String result = String.format(API_URL, this.language.getAPIID(), path); - // not gonna do a string builder here, because we intend this array to be of - // length 1 in almost all cases - for (String opt : optional) { - result += "/" + opt; - } - return result; + List loadTypes() throws IOException { + return loadStringArrayFrom("types"); } } diff --git a/src/main/java/com/github/maxopoly/tcgdex/Types.java b/src/main/java/com/github/tcgdex/Types.java similarity index 95% rename from src/main/java/com/github/maxopoly/tcgdex/Types.java rename to src/main/java/com/github/tcgdex/Types.java index a31b4df..942dca6 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/Types.java +++ b/src/main/java/com/github/tcgdex/Types.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/com/github/maxopoly/tcgdex/Utils.java b/src/main/java/com/github/tcgdex/Utils.java similarity index 97% rename from src/main/java/com/github/maxopoly/tcgdex/Utils.java rename to src/main/java/com/github/tcgdex/Utils.java index 816b08f..be90f03 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/Utils.java +++ b/src/main/java/com/github/tcgdex/Utils.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import java.io.BufferedReader; import java.io.IOException; diff --git a/src/main/java/com/github/maxopoly/tcgdex/Weakness.java b/src/main/java/com/github/tcgdex/Weakness.java similarity index 96% rename from src/main/java/com/github/maxopoly/tcgdex/Weakness.java rename to src/main/java/com/github/tcgdex/Weakness.java index 978ebae..8ee2511 100644 --- a/src/main/java/com/github/maxopoly/tcgdex/Weakness.java +++ b/src/main/java/com/github/tcgdex/Weakness.java @@ -1,4 +1,4 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import java.util.ArrayList; import java.util.Collections; @@ -29,15 +29,16 @@ public class Weakness { private final String value; + Weakness(JSONObject json) { + this(Types.parse(json.getString("type")), json.getString("value")); + } + Weakness(Types type, String value) { this.type = type; this.value = value; } - Weakness(JSONObject json) { - this(Types.parse(json.getString("type")), json.getString("value")); - } - + @Override public boolean equals(Object o) { if (!(o instanceof Weakness)) { return false; @@ -47,14 +48,6 @@ public class Weakness { new Object[] { other.type, other.value}); } - public int hashCode() { - return Objects.hash(this.type, this.value); - } - - public String toString() { - return String.format("%s %s", this.type, this.value); - } - /** * @return Type the weakness is to */ @@ -69,6 +62,16 @@ public class Weakness { return value; } + @Override + public int hashCode() { + return Objects.hash(this.type, this.value); + } + + @Override + public String toString() { + return String.format("%s %s", this.type, this.value); + } + } diff --git a/src/test/java/com/github/maxopoly/tcgdex/TestAPI.java b/src/test/java/com/github/tcgdex/TestAPI.java similarity index 92% rename from src/test/java/com/github/maxopoly/tcgdex/TestAPI.java rename to src/test/java/com/github/tcgdex/TestAPI.java index 30dd848..e9d96dd 100644 --- a/src/test/java/com/github/maxopoly/tcgdex/TestAPI.java +++ b/src/test/java/com/github/tcgdex/TestAPI.java @@ -1,8 +1,19 @@ -package com.github.maxopoly.tcgdex; +package com.github.tcgdex; import org.junit.Test; -import com.github.maxopoly.tcgdex.TCGDexAPI.Language; +import com.github.tcgdex.Ability; +import com.github.tcgdex.Attack; +import com.github.tcgdex.CardInfo; +import com.github.tcgdex.Categories; +import com.github.tcgdex.Rarities; +import com.github.tcgdex.SeriesInfo; +import com.github.tcgdex.SetInfo; +import com.github.tcgdex.SetResume; +import com.github.tcgdex.TCGDexAPI; +import com.github.tcgdex.Types; +import com.github.tcgdex.Weakness; +import com.github.tcgdex.TCGDexAPI.Language; import static org.junit.Assert.*;