new method with tests to get all cards with a filter predicate.

New method in Interface API to get all cards in a given setCode.
This has changed the implementation of getArtCount avoiding to iterate over all the possible card prints.
This commit is contained in:
leriomaggio
2021-08-25 19:39:54 +01:00
parent 02a241de12
commit bccf6e0a27
3 changed files with 58 additions and 11 deletions

View File

@@ -29,6 +29,7 @@ import forge.util.Lang;
import forge.util.TextUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import java.util.*;
import java.util.Map.Entry;
@@ -721,18 +722,16 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
}
@Override
public int getArtCount(String cardName, String setName) {
if (cardName == null || setName == null)
public int getArtCount(String cardName, String setCode) {
if (cardName == null || setCode == null)
return 0;
Collection<PaperCard> cards = getAllCards(cardName);
if (null == cards || cards.size() == 0)
return 0;
int artCount = 0;
for (PaperCard pc : cards) {
if (pc.getEdition().equalsIgnoreCase(setName))
artCount++;
}
return artCount;
Collection<PaperCard> cardsInSet = getAllCards(cardName, new Predicate<PaperCard>() {
@Override
public boolean apply(PaperCard card) {
return card.getEdition().equalsIgnoreCase(setCode);
}
});
return cardsInSet.size();
}
// returns a list of all cards from their respective latest (or preferred) editions
@@ -839,6 +838,11 @@ public final class CardDb implements ICardDatabase, IDeckGenPool {
return Lists.newArrayList(Iterables.filter(getAllCards(), predicate));
}
@Override
public List<PaperCard> getAllCards(final String cardName, Predicate<PaperCard> predicate){
return Lists.newArrayList(Iterables.filter(getAllCards(cardName), predicate));
}
/**
* Returns a modifiable list of cards matching the given predicate
*/

View File

@@ -79,6 +79,7 @@ public interface ICardDatabase extends Iterable<PaperCard> {
Collection<PaperCard> getAllCards();
Collection<PaperCard> getAllCards(String cardName);
Collection<PaperCard> getAllCards(Predicate<PaperCard> predicate);
Collection<PaperCard> getAllCards(String cardName,Predicate<PaperCard> predicate);
Collection<PaperCard> getAllCards(CardEdition edition);
Collection<PaperCard> getUniqueCards();