FIX and Impros to CardEdition, CardInSet and Reader

- Reader has a new updated regexp to deal with non-numerical collectorNumbers
- CardInSet have been now made sortable based on CollectorNumber.
To do so, collectorNumbers are transformed accordingly to allow for natural ordering (as expected) instead of lexicographic order.
- CardEdition now return cards (CardInSet) as sorted, to allow for correct artIndex matching when creating corresponding `PaperCard` instances.
Moreover, `compareTo` of card edition has been improved to also take into account set name (in cases of same release date).
This commit is contained in:
leriomaggio
2021-05-28 15:37:44 +00:00
committed by Michael Kamensky
parent a17c42e07e
commit 8b7ae19508
2 changed files with 10 additions and 4 deletions

View File

@@ -250,6 +250,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
private String[] chaosDraftThemes = new String[0];
private final ListMultimap<String, CardInSet> cardMap;
private final List<CardInSet> cardsInSet;
private final Map<String, Integer> tokenNormalized;
// custom print sheets that will be loaded lazily
private final Map<String, List<String>> customPrintSheetsToParse;
@@ -259,13 +260,18 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
private CardEdition(ListMultimap<String, CardInSet> cardMap, Map<String, Integer> tokens, Map<String, List<String>> customPrintSheetsToParse) {
this.cardMap = cardMap;
this.cardsInSet = new ArrayList<>(cardMap.values());
Collections.sort(cardsInSet);
this.tokenNormalized = tokens;
this.customPrintSheetsToParse = customPrintSheetsToParse;
}
private CardEdition(CardInSet[] cards, Map<String, Integer> tokens) {
List<CardInSet> 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<CardEdition> { // immutable
public List<CardInSet> getCards() { return cardMap.get("cards"); }
public List<CardInSet> getAllCardsInSet() {
ArrayList<CardInSet> cardsInSet = Lists.newArrayList(cardMap.values());
Collections.sort(cardsInSet);
return cardsInSet;
}
@@ -389,7 +393,7 @@ public final class CardEdition implements Comparable<CardEdition> { // immutable
}
public boolean isLargeSet() {
return getAllCardsInSet().size() > 200 && !smallSetOverride;
return this.cardsInSet.size() > 200 && !smallSetOverride;
}
public int getCntBoosterPictures() {

View File

@@ -308,6 +308,8 @@ public final class PaperCard implements Comparable<IPaperCard>, InventoryItemFro
private String retrieveCollectorNumber() {
CardEdition.Collection editions = StaticData.instance().getEditions();
CardEdition edition = editions.get(this.edition);
if (edition == null) // don't bother continuing - non-existing card!
return NO_COLLECTOR_NUMBER;
int artIndexCount = 0;
String collectorNumberInEdition = "";
for (CardEdition.CardInSet card : edition.getAllCardsInSet()) {