From ea5f9d30ea4b31a258e786d8a9709227943c061f Mon Sep 17 00:00:00 2001 From: leriomaggio Date: Fri, 28 May 2021 15:57:19 +0100 Subject: [PATCH] Simplified definition of cardsInSet for CardEdition The ArrayList of Cards in a Single edition (that needs to be sorted) will be initalised and sorted **only** once now, directly in the constructor. CardEdition has no API to change content of Cards in Edition, and the **only** write access to structure happen in the constructor. Therefore, these two structures should not need to be kept aligned. This extra ArrayList is useful whenever an iteration over all the cards in a set is needed. This iteration will proceed in order, as this might be crucial (esp. for ArtIndex assignment at load time). --- forge-core/src/main/java/forge/card/CardEdition.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/forge-core/src/main/java/forge/card/CardEdition.java b/forge-core/src/main/java/forge/card/CardEdition.java index 81329c740f9..c5879a88b3e 100644 --- a/forge-core/src/main/java/forge/card/CardEdition.java +++ b/forge-core/src/main/java/forge/card/CardEdition.java @@ -250,6 +250,7 @@ public final class CardEdition implements Comparable { // immutable private String[] chaosDraftThemes = new String[0]; private final ListMultimap cardMap; + private final List cardsInSet; private final Map tokenNormalized; // custom print sheets that will be loaded lazily private final Map> customPrintSheetsToParse; @@ -259,13 +260,18 @@ public final class CardEdition implements Comparable { // immutable private CardEdition(ListMultimap cardMap, Map tokens, Map> customPrintSheetsToParse) { this.cardMap = cardMap; + this.cardsInSet = new ArrayList<>(cardMap.values()); + Collections.sort(cardsInSet); this.tokenNormalized = tokens; this.customPrintSheetsToParse = customPrintSheetsToParse; } private CardEdition(CardInSet[] cards, Map tokens) { + List cardsList = Arrays.asList(cards); this.cardMap = ArrayListMultimap.create(); - this.cardMap.replaceValues("cards", Arrays.asList(cards)); + this.cardMap.replaceValues("cards", cardsList); + this.cardsInSet = new ArrayList<>(cardsList); + Collections.sort(cardsInSet); this.tokenNormalized = tokens; this.customPrintSheetsToParse = new HashMap<>(); } @@ -331,8 +337,6 @@ public final class CardEdition implements Comparable { // immutable public List getCards() { return cardMap.get("cards"); } public List getAllCardsInSet() { - ArrayList cardsInSet = Lists.newArrayList(cardMap.values()); - Collections.sort(cardsInSet); return cardsInSet; } @@ -389,7 +393,7 @@ public final class CardEdition implements Comparable { // immutable } public boolean isLargeSet() { - return getAllCardsInSet().size() > 200 && !smallSetOverride; + return this.cardsInSet.size() > 200 && !smallSetOverride; } public int getCntBoosterPictures() {