mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Refined implementation (+ test) for getEarliestEditionWithAllCards
This method should still be optimised, and definetly renamed.
This commit is contained in:
@@ -813,21 +813,14 @@ public final class CardEdition implements Comparable<CardEdition> {
|
|||||||
*/
|
*/
|
||||||
public CardEdition getEarliestEditionWithAllCards(CardPool cards) {
|
public CardEdition getEarliestEditionWithAllCards(CardPool cards) {
|
||||||
Set<String> minEditions = new HashSet<>();
|
Set<String> minEditions = new HashSet<>();
|
||||||
|
CardDb db = StaticData.instance().getCommonCards();
|
||||||
CardArtPreference strictness = CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY;
|
|
||||||
|
|
||||||
for (Entry<PaperCard, Integer> k : cards) {
|
for (Entry<PaperCard, Integer> k : cards) {
|
||||||
PaperCard cp = StaticData.instance().getCommonCards().getCardFromEditions(k.getKey().getName(), strictness);
|
PaperCard cp = db.getCardFromEditions(k.getKey().getName(),
|
||||||
if( cp == null && strictness == CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY) {
|
CardArtPreference.ORIGINAL_ART_CORE_EXPANSIONS_REPRINT_ONLY);
|
||||||
strictness = CardArtPreference.ORIGINAL_ART_ALL_EDITIONS; // card is not found in core and expansions only (probably something CMD or C13)
|
|
||||||
cp = StaticData.instance().getCommonCards().getCardFromEditions(k.getKey().getName(), strictness);
|
|
||||||
}
|
|
||||||
if (cp == null)
|
if (cp == null)
|
||||||
cp = k.getKey(); // it's unlikely, this code will ever run
|
cp = k.getKey(); // it's unlikely, this code will ever run
|
||||||
|
|
||||||
minEditions.add(cp.getEdition());
|
minEditions.add(cp.getEdition());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CardEdition ed : getOrderedEditions()) {
|
for (CardEdition ed : getOrderedEditions()) {
|
||||||
if (minEditions.contains(ed.getCode()))
|
if (minEditions.contains(ed.getCode()))
|
||||||
return ed;
|
return ed;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class CardEditionCollectionTestCase extends ForgeCardMockTestCase {
|
|||||||
for (int i=0; i < 5; i++){
|
for (int i=0; i < 5; i++){
|
||||||
String cardName = cardNames[i];
|
String cardName = cardNames[i];
|
||||||
String expectedSet = expectedSets[i];
|
String expectedSet = expectedSets[i];
|
||||||
PaperCard card = cardDb.getCardFromEditions(cardName, CardDb.CardArtPreference.OldArtAllEditions);
|
PaperCard card = cardDb.getCardFromEditions(cardName, CardDb.CardArtPreference.ORIGINAL_ART_ALL_EDITIONS);
|
||||||
assertEquals(card.getEdition(), expectedSet);
|
assertEquals(card.getEdition(), expectedSet);
|
||||||
cards.add(card);
|
cards.add(card);
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,6 @@ public class CardEditionCollectionTestCase extends ForgeCardMockTestCase {
|
|||||||
CardPool pool = new CardPool();
|
CardPool pool = new CardPool();
|
||||||
pool.add(cards);
|
pool.add(cards);
|
||||||
CardEdition ed = editions.getEarliestEditionWithAllCards(pool);
|
CardEdition ed = editions.getEarliestEditionWithAllCards(pool);
|
||||||
assertEquals(ed.getCode(), "LEA");
|
assertEquals(ed.getCode(), "ALL");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user