New data structure in CardEdition allocated for quick cardInset lookup

CardEdition now includes a new Map data strcuture that is allocated only if necessary (i.e. when lazy card loading is enabled) and it will be used for faster card in set lookup by card name. The Map will return a List of cards to account for multiple versions (prints) of a card with the same name within a CardEdition
This commit is contained in:
leriomaggio
2021-08-04 08:23:48 +01:00
parent 0e5611cfea
commit 5ff8174b4d

View File

@@ -366,6 +366,22 @@ public final class CardEdition implements Comparable<CardEdition> {
return cardsInSet; return cardsInSet;
} }
private Map<String, List<CardInSet>> cardsInSetLookupMap = null;
public List<CardInSet> getCardInSet(String cardName){
if (cardsInSetLookupMap == null) {
// initialise
cardsInSetLookupMap = new TreeMap<>();
List<CardInSet> cardsInSet = this.getAllCardsInSet();
for (CardInSet cis : cardsInSet){
String key = cis.name.toLowerCase();
List<CardInSet> versions = cardsInSetLookupMap.getOrDefault(key, new ArrayList<>());
versions.add(cis);
cardsInSetLookupMap.put(key, versions);
}
}
return this.cardsInSetLookupMap.getOrDefault(cardName.toLowerCase(), new ArrayList<>());
}
public boolean isModern() { return getDate().after(parseDate("2003-07-27")); } //8ED and above are modern except some promo cards and others public boolean isModern() { return getDate().after(parseDate("2003-07-27")); } //8ED and above are modern except some promo cards and others
public Map<String, Integer> getTokens() { return tokenNormalized; } public Map<String, Integer> getTokens() { return tokenNormalized; }