- Cleaned up the code I added recently to return a list of cards sharing the highest cmc. Thanks for the assistence Max!

This commit is contained in:
moomarc
2013-03-19 14:18:47 +00:00
parent 37126549cc
commit 9333d4fe4f

View File

@@ -263,36 +263,21 @@ public class CardLists {
/** /**
* Given a List<Card> cardList, return a List<Card> that are tied for having the highest CMC. * Given a List<Card> cardList, return a List<Card> that are tied for having the highest CMC.
* *
* @param cardList the Card List to be filtered. * @param cardList the Card List to be filtered.
* @return CardList the list of Cards sharing the highest CMC. * @return the list of Cards sharing the highest CMC.
*/ */
public static List<Card> getCardsWithHighestCMC(Iterable<Card> cardList) { public static List<Card> getCardsWithHighestCMC(Iterable<Card> cardList) {
final List<Card> tiedForHighest = new ArrayList<Card>(); final List<Card> tiedForHighest = new ArrayList<Card>();
int highest = 0; int highest = 0;
for (final Card crd : cardList) { for (final Card crd : cardList) {
if (crd.isSplitCard()) { int curCmc = crd.isSplitCard() ? Math.max(crd.getCMC(Card.SplitCMCMode.LeftSplitCMC), crd.getCMC(Card.SplitCMCMode.RightSplitCMC)) : crd.getCMC();
if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) > highest) {
highest = crd.getCMC(Card.SplitCMCMode.LeftSplitCMC); if (curCmc > highest) {
tiedForHighest.clear(); highest = curCmc;
tiedForHighest.add(crd); tiedForHighest.clear();
} else if (crd.getCMC(Card.SplitCMCMode.LeftSplitCMC) == highest && !tiedForHighest.contains(crd)) { }
tiedForHighest.add(crd); if (curCmc >= highest) {
} tiedForHighest.add(crd);
if (crd.getCMC(Card.SplitCMCMode.RightSplitCMC) > highest) {
highest = crd.getCMC(Card.SplitCMCMode.RightSplitCMC);
tiedForHighest.clear();
tiedForHighest.add(crd);
} else if (crd.getCMC(Card.SplitCMCMode.RightSplitCMC) == highest && !tiedForHighest.contains(crd)) {
tiedForHighest.add(crd);
}
} else {
if (crd.getCMC() > highest) {
highest = crd.getCMC();
tiedForHighest.clear();
tiedForHighest.add(crd);
} else if (crd.getCMC() == highest && !tiedForHighest.contains(crd)) {
tiedForHighest.add(crd);
}
} }
} }
return tiedForHighest; return tiedForHighest;