Rename package and cleanup

This commit is contained in:
Maxopoly 2021-11-04 17:33:57 +01:00
parent 5295ec2b3b
commit bee1b6d71e
16 changed files with 355 additions and 337 deletions

View File

@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.github.maxopoly</groupId> <groupId>com.github.tcgdex</groupId>
<artifactId>tcgdex</artifactId> <artifactId>tcgdex</artifactId>

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -29,16 +29,17 @@ public class Ability {
private final String name; private final String name;
private final String effect; private final String effect;
Ability(JSONObject json) {
this(json.getString("type"), json.getString("name"), json.getString("effect"));
}
Ability(String type, String name, String effect) { Ability(String type, String name, String effect) {
this.type = type; this.type = type;
this.name = name; this.name = name;
this.effect = effect; this.effect = effect;
} }
Ability(JSONObject json) { @Override
this(json.getString("type"), json.getString("name"), json.getString("effect"));
}
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof Ability)) { if (!(o instanceof Ability)) {
return false; return false;
@ -48,24 +49,6 @@ public class Ability {
new Object[] { other.type, other.name, other.effect }); 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 * @return Description/Effect of the ability
@ -74,4 +57,23 @@ public class Ability {
return effect; 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);
}
} }

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -30,6 +30,11 @@ public class Attack {
private final String effect; private final String effect;
private final String damage; private final String damage;
Attack(JSONObject json) {
this(Types.parse(json.getJSONArray("cost")), json.getString("name"), json.optString("effect"),
json.optString("damage"));
}
Attack(List<Types> cost, String name, String effect, String damage) { Attack(List<Types> cost, String name, String effect, String damage) {
super(); super();
this.cost = cost; this.cost = cost;
@ -38,11 +43,7 @@ public class Attack {
this.damage = damage; this.damage = damage;
} }
Attack(JSONObject json) { @Override
this(Types.parse(json.getJSONArray("cost")), json.getString("name"), json.optString("effect"),
json.optString("damage"));
}
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof Attack)) { if (!(o instanceof Attack)) {
return false; return false;
@ -52,10 +53,6 @@ public class Attack {
new Object[] { other.cost, other.name, other.effect, other.damage }); 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 * @return Cost of the attack in the same order as listed on the card
*/ */
@ -64,10 +61,11 @@ public class Attack {
} }
/** /**
* @return Name of the attack * @return Damage the attack deals. May just be a number like '30', but can also
* be a multiplier like 'x20'
*/ */
public String getName() { public String getDamage() {
return name; return damage;
} }
/** /**
@ -78,11 +76,15 @@ public class Attack {
} }
/** /**
* @return Damage the attack deals. May just be a number like '30', but can also * @return Name of the attack
* be a multiplier like 'x20'
*/ */
public String getDamage() { public String getName() {
return damage; return name;
}
@Override
public int hashCode() {
return Objects.hash(this.cost, this.name, this.effect, this.damage);
} }
} }

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -34,35 +34,6 @@ public class CardInfo extends CardResume {
private final Integer retreat; private final Integer retreat;
private final String regulationMark; 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<Integer> dexIDs, Integer hp, List<Types> types,
String evolveFrom, String description, String level, String stage, String suffix, List<Attack> attacks,
List<Weakness> weakness, List<Ability> 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) { CardInfo(JSONObject json) {
super(json); super(json);
this.illustrator = json.getString("illustrator"); this.illustrator = json.getString("illustrator");
@ -95,6 +66,35 @@ public class CardInfo extends CardResume {
this.abilities = Ability.parse(json.optJSONArray("abilities")); 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<Integer> dexIDs, Integer hp, List<Types> types,
String evolveFrom, String description, String level, String stage, String suffix, List<Attack> attacks,
List<Weakness> weakness, List<Ability> 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 * @return Pokemon's abilities. May be empty if it doesn't have any, but never
* null * null
@ -103,14 +103,6 @@ public class CardInfo extends CardResume {
return abilities; 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 * @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<Weakness> getWeakness() { public Categories getCategory() {
return weakness; 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() { public List<Integer> getDexIDs() {
return retreat; 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 illustrator;
} }
/**
*
* @return Pokemon level, may be 'X', hence not an integer
*/
public String getLevel() {
return level;
}
/** /**
* *
* @return Card rarity * @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() { public String getRegulationMark() {
return category; 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<Types> getTypes() {
return types;
}
/**
* @return Weaknesses the pokemon has. Empty for cards without attacks
*/
public List<Weakness> 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 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<Integer> 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<Types> 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;
}
} }

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -29,6 +29,10 @@ public class CardResume {
private final String name; private final String name;
private final String image; 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) { CardResume(String id, String localId, String name, String image) {
this.id = id; this.id = id;
this.localId = localId; this.localId = localId;
@ -36,10 +40,6 @@ public class CardResume {
this.image = image; 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 * @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 id;
} }
/**
*
* @return Card image, can be null
*/
public String getImage() {
return image;
}
/** /**
* @return ID indexing this card within its set, usually just its number * @return ID indexing this card within its set, usually just its number
*/ */
@ -61,12 +69,4 @@ public class CardResume {
public String getName() { public String getName() {
return name; return name;
} }
/**
*
* @return Card image, can be null
*/
public String getImage() {
return image;
}
} }

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
public enum Categories { public enum Categories {

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
public enum Rarities { public enum Rarities {

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import java.util.List; import java.util.List;
@ -12,16 +12,16 @@ public class SeriesInfo extends SeriesResume {
private final List<SetResume> sets; private final List<SetResume> sets;
SeriesInfo(String id, String name, List<SetResume> sets) {
super(id, name);
this.sets = sets;
}
SeriesInfo(JSONObject json) { SeriesInfo(JSONObject json) {
super(json); super(json);
this.sets = SetResume.parse(json.optJSONArray("sets")); this.sets = SetResume.parse(json.optJSONArray("sets"));
} }
SeriesInfo(String id, String name, List<SetResume> sets) {
super(id, name);
this.sets = sets;
}
/** /**
* @return Resumes of the sets part of this series * @return Resumes of the sets part of this series
*/ */

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import org.json.JSONObject; import org.json.JSONObject;
@ -11,15 +11,15 @@ public class SeriesResume {
private final String id; private final String id;
private final String name; private final String name;
SeriesResume(JSONObject json) {
this(json.getString("id"), json.getString("name"));
}
SeriesResume(String id, String name) { SeriesResume(String id, String name) {
this.id = id; this.id = id;
this.name = name; this.name = name;
} }
SeriesResume(JSONObject json) {
this(json.getString("id"), json.getString("name"));
}
/** /**
* @return Serie unique ID * @return Serie unique ID
*/ */

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -58,6 +58,20 @@ public class SetInfo extends SetResume {
this.cards = cards; this.cards = cards;
} }
/**
* @return All cards part of the set
*/
public List<CardResume> 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 * @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() { public LocalDate getReleaseDate() {
return firstEd; 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() { public boolean isLegalInExpanded() {
return releaseDate; return legalInExpanded;
} }
/** /**
@ -113,18 +127,4 @@ public class SetInfo extends SetResume {
public boolean isLegalInStandard() { public boolean isLegalInStandard() {
return legalInStandard; 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<CardResume> getCards() {
return cards;
}
} }

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -31,6 +31,11 @@ public class SetResume {
private final int officialCardCount; private final int officialCardCount;
private final int totalCardCount; 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) { SetResume(String id, String name, String logo, String symbol, int officialCardCount, int totalCardCount) {
this.id = id; this.id = id;
this.name = name; this.name = name;
@ -40,11 +45,6 @@ public class SetResume {
this.totalCardCount = totalCardCount; 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 * @return Set unique ID
*/ */
@ -52,13 +52,6 @@ public class SetResume {
return id; return id;
} }
/**
* @return Set name
*/
public String getName() {
return name;
}
/** /**
* @return Set logo URL, may be null * @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() { public String getName() {
return symbol; return name;
} }
/** /**
@ -80,6 +73,13 @@ public class SetResume {
return officialCardCount; return officialCardCount;
} }
/**
* @return Set symbol URL, may be null
*/
public String getSymbol() {
return symbol;
}
/** /**
* @return Total amount of cards in this set * @return Total amount of cards in this set
*/ */

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,6 +32,16 @@ public class TCGDexAPI {
this.language = language; 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 * 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 * Gets a list of all known card illustrators
* 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 * @return List of all illustrators
* @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 * @throws IOException Thrown in response to any kind of networking error
*/ */
public CardInfo getCardInfo(String setID, String cardID) throws IOException { public List<String> getAllIllustrators() throws IOException {
String data = Utils.doGet(buildURL("sets", setID, cardID)); return loadStringArrayFrom("illustrators");
return new CardInfo(new JSONObject(data));
} }
/** public List<Integer> getAllPossibleHPValues() throws IOException {
* Gets detailed information of a card based on its globally unique identifier, String data = Utils.doGet(buildURL("hp"));
* for example 'base4-1' JSONArray json = new JSONArray(data);
* List<Integer> result = new ArrayList<>();
* @param globalCardID Globally unique ID of the card for (int i = 0; i < json.length(); i++) {
* @return Card info obtained result.add(json.getInt(i));
* @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));
} }
return result;
/**
* 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());
} }
/** /**
@ -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 * @param card Card to get info for
* @return Detailed information of the series * @return Card info obtained
* @throws IOException Thrown in response to any kind of networking error * @throws IOException Thrown in response to any kind of networking error
*/ */
public SeriesInfo getSeriesInfo(String seriesID) throws IOException { public CardInfo getCardInfo(CardResume card) throws IOException {
String data = Utils.doGet(buildURL("series", seriesID)); return getCardInfo(card.getId());
return new SeriesInfo(new JSONObject(data)); }
/**
* 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,15 +153,15 @@ 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 * @param seriesID ID of the series
* @return Detailed information of the set * @return Detailed information of the series
* @throws IOException Thrown in response to any kind of networking error * @throws IOException Thrown in response to any kind of networking error
*/ */
public SetInfo getSetInfo(String setID) throws IOException { public SeriesInfo getSeriesInfo(String seriesID) throws IOException {
String data = Utils.doGet(buildURL("sets", setID)); String data = Utils.doGet(buildURL("series", seriesID));
return new SetInfo(new JSONObject(data)); return new SeriesInfo(new JSONObject(data));
} }
/** /**
@ -159,36 +177,24 @@ public class TCGDexAPI {
return new SetInfo(new JSONObject(data)); return new SetInfo(new JSONObject(data));
} }
List<String> 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<String> loadCategories() throws IOException { List<String> loadCategories() throws IOException {
return loadStringArrayFrom("categories"); return loadStringArrayFrom("categories");
} }
List<String> loadTypes() throws IOException { List<String> loadRarities() throws IOException {
return loadStringArrayFrom("types"); return loadStringArrayFrom("rarities");
}
/**
* 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<String> getAllIllustrators() throws IOException {
return loadStringArrayFrom("illustrators");
}
public List<Integer> getAllPossibleHPValues() throws IOException {
String data = Utils.doGet(buildURL("hp"));
JSONArray json = new JSONArray(data);
List<Integer> result = new ArrayList<>();
for (int i = 0; i < json.length(); i++) {
result.add(json.getInt(i));
}
return result;
} }
private List<String> loadStringArrayFrom(String path) throws IOException { private List<String> loadStringArrayFrom(String path) throws IOException {
@ -201,14 +207,8 @@ public class TCGDexAPI {
return result; return result;
} }
private String buildURL(String path, String... optional) { List<String> loadTypes() throws IOException {
String result = String.format(API_URL, this.language.getAPIID(), path); return loadStringArrayFrom("types");
// 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;
} }
} }

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,4 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -29,15 +29,16 @@ public class Weakness {
private final String value; private final String value;
Weakness(JSONObject json) {
this(Types.parse(json.getString("type")), json.getString("value"));
}
Weakness(Types type, String value) { Weakness(Types type, String value) {
this.type = type; this.type = type;
this.value = value; this.value = value;
} }
Weakness(JSONObject json) { @Override
this(Types.parse(json.getString("type")), json.getString("value"));
}
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof Weakness)) { if (!(o instanceof Weakness)) {
return false; return false;
@ -47,14 +48,6 @@ public class Weakness {
new Object[] { other.type, other.value}); 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 * @return Type the weakness is to
*/ */
@ -69,6 +62,16 @@ public class Weakness {
return value; 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);
}
} }

View File

@ -1,8 +1,19 @@
package com.github.maxopoly.tcgdex; package com.github.tcgdex;
import org.junit.Test; 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.*; import static org.junit.Assert.*;