Added test for corner cases with different case in card name and set code (also compared to legacy implementation)

Also, now LoadCard also uses the provided setCode (if any).
If null or empty string is provided in request, all editions will be used!
This commit is contained in:
leriomaggio
2021-08-04 15:57:28 +01:00
parent 09822bdda2
commit 58b2a070ed
2 changed files with 99 additions and 6 deletions

View File

@@ -227,17 +227,31 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
addCard(new PaperCard(cr, e.getCode(), cis.rarity, artIdx, false, cis.collectorNumber, cis.artistName));
}
public void loadCard(String cardName, CardRules cr) {
public void loadCard(String cardName, String setCode, CardRules cr) {
// @leriomaggio: This method is called when lazy-loading is set
System.out.println("Lazy Loading Card: " + cardName);
System.out.println("[LOG]: (Lazy) Loading Card: " + cardName);
rulesByName.put(cardName, cr);
for (CardEdition e : editions) {
boolean reIndexNecessary = false;
if ((setCode == null) || setCode.length() == 0 || setCode.equals(CardEdition.UNKNOWN.getCode())) {
// look for all possible editions
for (CardEdition e : editions) {
List<CardInSet> cardsInSet = e.getCardInSet(cardName); // empty collection if not present
for (CardInSet cis : cardsInSet) {
addSetCard(e, cis, cr);
reIndexNecessary = true;
}
}
} else {
CardEdition e = editions.get(setCode);
List<CardInSet> cardsInSet = e.getCardInSet(cardName); // empty collection if not present
for (CardInSet cis : cardsInSet)
for (CardInSet cis : cardsInSet) {
addSetCard(e, cis, cr);
reIndexNecessary = true;
}
}
reIndex();
if (reIndexNecessary)
reIndex();
}
public void initialize(boolean logMissingPerEdition, boolean logMissingSummary, boolean enableUnknownCards) {
@@ -441,7 +455,8 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
if ((reqEditionCode != null) && (reqEditionCode.length() > 0)) {
// This get is robust even against expansion aliases (e.g. TE and TMP both valid for Tempest) -
// MOST of the extensions have two short codes, 141 out of 221 (so far)
CardEdition edition = editions.get(reqEditionCode);
// ALSO: Set Code are always UpperCase
CardEdition edition = editions.get(reqEditionCode.toUpperCase());
return this.getCardFromSet(request.cardName, edition, request.artIndex,
request.collectorNumber, request.isFoil);
}