mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
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:
@@ -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; }
|
||||||
|
|||||||
Reference in New Issue
Block a user