Same optimisation using iterator on getCardFromSet

This commit is contained in:
leriomaggio
2021-08-25 18:49:03 +01:00
parent 7b70a34da0
commit f507edada5

View File

@@ -536,17 +536,13 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
if (candidates.isEmpty()) if (candidates.isEmpty())
return null; return null;
PaperCard candidate = candidates.get(0); Iterator<PaperCard> candidatesIterator = candidates.iterator();
PaperCard candidate = candidatesIterator.next();
// Before returning make sure that actual candidate has Image. // Before returning make sure that actual candidate has Image.
// If not, try to replace current candidate with one having image, // If not, try to replace current candidate with one having image,
// so to align this implementation with old one. // so to align this implementation with old one.
if (!candidate.hasImage()) { while (!candidate.hasImage() && candidatesIterator.hasNext()) {
for (PaperCard card : candidates) { candidate = candidatesIterator.next();
if (card.hasImage()) {
candidate = card;
break; // found, ready to go
}
}
} }
return isFoil ? candidate.getFoiled() : candidate; return isFoil ? candidate.getFoiled() : candidate;
} }