mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 18:58:00 +00:00
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:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package forge.card;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import forge.StaticData;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.PaperCard;
|
||||
@@ -10,7 +11,10 @@ import org.testng.annotations.Test;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
@@ -101,6 +105,44 @@ public class CardDbTestCase extends ForgeCardMockTestCase {
|
||||
this.legacyCardDb = new LegacyCardDb(data.getCommonCards().getAllCards(), data.getEditions());
|
||||
}
|
||||
|
||||
/*
|
||||
* TEST FOR GET ALL CARDS
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testGetAllCardsWithName(){
|
||||
List<PaperCard> allCounterSpellPrints = this.cardDb.getAllCards(this.cardNameCounterspell);
|
||||
assertNotNull(allCounterSpellPrints);
|
||||
for (PaperCard card : allCounterSpellPrints)
|
||||
assertEquals(card.getName(), this.cardNameCounterspell);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAllCardsThatWerePrintedInSets(){
|
||||
List<String> allowedSets = new ArrayList<>();
|
||||
allowedSets.add(this.latestArtShivanDragonEdition);
|
||||
Predicate<PaperCard> wasPrinted = (Predicate<PaperCard>) this.cardDb.wasPrintedInSets(allowedSets);
|
||||
List<PaperCard> allCardsInSet = this.cardDb.getAllCards(wasPrinted);
|
||||
assertNotNull(allCardsInSet);
|
||||
}
|
||||
|
||||
@Test void testGetAllCardsOfaGivenNameAndLegalInSets(){
|
||||
List<String> allowedSets = new ArrayList<>(Arrays.asList(this.editionsCounterspell));
|
||||
Predicate<PaperCard> printedInSets = (Predicate<PaperCard>) this.cardDb.wasPrintedInSets(allowedSets);
|
||||
List<PaperCard> allCounterSpellsInSets = this.cardDb.getAllCards(this.cardNameCounterspell, printedInSets);
|
||||
assertNotNull(allCounterSpellsInSets);
|
||||
assertTrue(allCounterSpellsInSets.size() > 0);
|
||||
assertTrue(allCounterSpellsInSets.size() > 1);
|
||||
for (PaperCard card : allCounterSpellsInSets) {
|
||||
assertEquals(card.getName(), this.cardNameCounterspell);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* TEST FOR CARD RETRIEVAL METHODS
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testGetCardByName() {
|
||||
PaperCard legacyCard = this.legacyCardDb.getCard(cardNameShivanDragon);
|
||||
|
||||
Reference in New Issue
Block a user