mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
Find latest edition made through Aggregate
This commit is contained in:
@@ -39,6 +39,7 @@ import forge.Singletons;
|
|||||||
import forge.card.CardInSet;
|
import forge.card.CardInSet;
|
||||||
import forge.card.CardRules;
|
import forge.card.CardRules;
|
||||||
import forge.card.MtgDataParser;
|
import forge.card.MtgDataParser;
|
||||||
|
import forge.util.Aggregates;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -393,22 +394,13 @@ public final class CardDb {
|
|||||||
} else {
|
} else {
|
||||||
// OK, plain name here
|
// OK, plain name here
|
||||||
final Predicate<CardPrinted> predicate = CardPrinted.Predicates.name(nameWithSet.left);
|
final Predicate<CardPrinted> predicate = CardPrinted.Predicates.name(nameWithSet.left);
|
||||||
final List<CardPrinted> namedCards = Lists.newArrayList(Iterables.filter(this.allCardsFlat, predicate));
|
final Iterable<CardPrinted> namedCards = Iterables.filter(this.allCardsFlat, predicate);
|
||||||
if (namedCards.isEmpty()) {
|
// Find card with maximal set index
|
||||||
|
result = Aggregates.itemWithMax(namedCards, CardPrinted.FN_GET_EDITION_INDEX);
|
||||||
|
if (null == result) {
|
||||||
throw new NoSuchElementException(String.format("Card '%s' not found in our database.", name));
|
throw new NoSuchElementException(String.format("Card '%s' not found in our database.", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find card with maximal set index
|
|
||||||
result = namedCards.get(0);
|
|
||||||
int resIndex = Singletons.getModel().getEditions().get((result).getEdition()).getIndex();
|
|
||||||
for (final CardPrinted card : namedCards) {
|
|
||||||
|
|
||||||
final int thisIndex = Singletons.getModel().getEditions().get((card).getEdition()).getIndex();
|
|
||||||
if (thisIndex > resIndex) {
|
|
||||||
result = card;
|
|
||||||
resIndex = thisIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isFoil) {
|
if (isFoil) {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.google.common.base.Predicate;
|
|||||||
import forge.AllZone;
|
import forge.AllZone;
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.CardUtil;
|
import forge.CardUtil;
|
||||||
|
import forge.Singletons;
|
||||||
import forge.card.CardRarity;
|
import forge.card.CardRarity;
|
||||||
import forge.card.CardRules;
|
import forge.card.CardRules;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
@@ -176,6 +177,13 @@ public final class CardPrinted implements Comparable<CardPrinted>, InventoryItem
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static final Function<CardPrinted, Integer> FN_GET_EDITION_INDEX = new Function<CardPrinted, Integer>() {
|
||||||
|
@Override
|
||||||
|
public Integer apply(final CardPrinted from) {
|
||||||
|
return Integer.valueOf(Singletons.getModel().getEditions().get(from.getEdition()).getIndex());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Constructor is private. All non-foiled instances are stored in CardDb
|
// Constructor is private. All non-foiled instances are stored in CardDb
|
||||||
private CardPrinted(final CardRules c, final String edition0, final CardRarity rare, final int index, final boolean foil) {
|
private CardPrinted(final CardRules c, final String edition0, final CardRarity rare, final int index, final boolean foil) {
|
||||||
this.card = c;
|
this.card = c;
|
||||||
|
|||||||
Reference in New Issue
Block a user