Further optimised cardDb method with filter using AlwaysTrue + and Chain

Signed-off-by: leriomaggio <valeriomaggio@gmail.com>
This commit is contained in:
leriomaggio
2021-09-13 18:58:54 +01:00
parent a9f1cd3c97
commit f8cb6141bd

View File

@@ -694,6 +694,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
List<PaperCard> cards; List<PaperCard> cards;
Predicate<PaperCard> cardQueryFilter; Predicate<PaperCard> cardQueryFilter;
filter = (filter != null) ? filter : Predicates.alwaysTrue();
if (releaseDate != null) { if (releaseDate != null) {
cardQueryFilter = new Predicate<PaperCard>() { cardQueryFilter = new Predicate<PaperCard>() {
@Override @Override
@@ -715,8 +716,7 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
return card.getArtIndex() == cr.artIndex; return card.getArtIndex() == cr.artIndex;
} }
}; };
if (filter != null) cardQueryFilter = Predicates.and(cardQueryFilter, filter);
cardQueryFilter = Predicates.and(cardQueryFilter, filter);
cards = getAllCards(cr.cardName, cardQueryFilter); cards = getAllCards(cr.cardName, cardQueryFilter);
// Note: No need to check whether "cards" is empty; the next for loop will validate condition at L699 // Note: No need to check whether "cards" is empty; the next for loop will validate condition at L699
if (cards.size() == 1) // if only one candidate, there much else we should do if (cards.size() == 1) // if only one candidate, there much else we should do