From 5ff8174b4dad984a30edd3cfa99cff19ece47769 Mon Sep 17 00:00:00 2001 From: leriomaggio Date: Wed, 4 Aug 2021 08:23:48 +0100 Subject: [PATCH] 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 --- .../src/main/java/forge/card/CardEdition.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/forge-core/src/main/java/forge/card/CardEdition.java b/forge-core/src/main/java/forge/card/CardEdition.java index e3aa49723fc..9c979641eb7 100644 --- a/forge-core/src/main/java/forge/card/CardEdition.java +++ b/forge-core/src/main/java/forge/card/CardEdition.java @@ -366,6 +366,22 @@ public final class CardEdition implements Comparable { return cardsInSet; } + private Map> cardsInSetLookupMap = null; + public List getCardInSet(String cardName){ + if (cardsInSetLookupMap == null) { + // initialise + cardsInSetLookupMap = new TreeMap<>(); + List cardsInSet = this.getAllCardsInSet(); + for (CardInSet cis : cardsInSet){ + String key = cis.name.toLowerCase(); + List 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 Map getTokens() { return tokenNormalized; }