Again reduced number of own methods of CardList,

removed pointless conversions toArray in GuiUtils.chooseXXX calls
removed useless casts to object array of (Object[])someList.toArray() structures
This commit is contained in:
Maxmtg
2012-09-25 08:07:02 +00:00
parent d3676ff1de
commit 8eb157606d
41 changed files with 113 additions and 234 deletions

View File

@@ -1565,10 +1565,9 @@ public class Card extends GameEntity implements Comparable<Card> {
* @return a int. * @return a int.
*/ */
public final int sumAllCounters() { public final int sumAllCounters() {
final Object[] values = this.counters.values().toArray();
int count = 0; int count = 0;
int num = 0; int num = 0;
for (final Object value2 : values) { for (final Object value2 : this.counters.values()) {
num = (Integer) value2; num = (Integer) value2;
count += num; count += num;
} }

View File

@@ -37,126 +37,10 @@ import forge.util.closures.Predicate;
public class CardList extends ArrayList<Card> { public class CardList extends ArrayList<Card> {
private static final long serialVersionUID = 7912620750458976012L; private static final long serialVersionUID = 7912620750458976012L;
/**
* <p>
* Constructor for CardList.
* </p>
*/
public CardList() {
}
/** public CardList() {}
* <p> public CardList(final Card c) { this.add(c); }
* Constructor for CardList. public CardList(final Iterable<Card> al) { for(Card c : al) this.add(c); }
* </p>
*
* @param c
* a {@link forge.Card} object.
*/
public CardList(final Card c) {
this.add(c);
}
/**
* <p>
* toArray.
* </p>
*
* @return an array of {@link forge.Card} objects.
*/
@Override
public final Card[] toArray() {
final Card[] c = new Card[this.size()];
this.toArray(c);
return c;
}
/**
* <p>
* Constructor for CardList.
* </p>
*
* @param al
* a {@link java.util.ArrayList} object.
*/
public CardList(final Iterable<Card> al) {
for(Card c : al)
this.add(c);
}
/** {@inheritDoc} */
@Override
public final boolean equals(final Object a) {
if (a instanceof CardList) {
final CardList b = (CardList) a;
if (this.size() != b.size()) {
return false;
}
for (int i = 0; i < this.size(); i++) {
if (!this.get(i).equals(b.get(i))) {
return false;
}
}
return true;
} else {
return false;
}
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return (41 * (41 + this.size() + this.hashCode()));
}
/**
* <p>
* addAll.
* </p>
*
* @param c
* an array of {@link java.lang.Object} objects.
*/
public final void addAll(final Card[] c) {
for (final Object element : c) {
this.add((Card) element);
}
}
/**
* <p>
* removeAll.
* </p>
*
* @param c
* a {@link forge.Card} object.
*/
public final void removeAll(final Card c) {
final ArrayList<Card> cList = new ArrayList<Card>();
cList.add(c);
this.removeAll(cList);
}
/**
* <p>
* removeAll.
* </p>
*
* @param c
* a {@link forge.Card} object.
*/
public final void removeAll(final CardList list) {
for (Card c : list) {
this.remove(c);
}
}
/** /**

View File

@@ -84,6 +84,18 @@ public final class CardUtil {
} }
} }
public static <T> T getRandom(final List<T> o) {
if (o == null) {
throw new IllegalArgumentException("CardUtil : getRandom(T) recieved null instead of array.");
}
int len = o.size();
switch(len) {
case 0: throw new IllegalArgumentException("CardUtil : getRandom(T) recieved an empty array.");
case 1: return o.get(0);
default: return o.get(CardUtil.RANDOM.nextInt(len));
}
}
/** /**
* <p> * <p>
* getRandomIndex. * getRandomIndex.

View File

@@ -1332,7 +1332,7 @@ public class GameAction {
crd = list.get(0); crd = list.get(0);
} else { } else {
if (c.getController().isHuman()) { if (c.getController().isHuman()) {
crd = GuiUtils.chooseOneOrNone("Select totem armor to destroy", list.toArray()); crd = GuiUtils.chooseOneOrNone("Select totem armor to destroy", list);
} else { } else {
crd = list.get(0); crd = list.get(0);
} }
@@ -1515,7 +1515,7 @@ public class GameAction {
crd = list.get(0); crd = list.get(0);
} else { } else {
if (c.getController().isHuman()) { if (c.getController().isHuman()) {
crd = GuiUtils.chooseOneOrNone("Select totem armor to destroy", list.toArray()); crd = GuiUtils.chooseOneOrNone("Select totem armor to destroy", list);
} else { } else {
crd = list.get(0); crd = list.get(0);
} }
@@ -1579,7 +1579,7 @@ public class GameAction {
} else if (choices.size() == 1) { } else if (choices.size() == 1) {
choice = choices.get(0); choice = choices.get(0);
} else { } else {
choice = (String) GuiUtils.chooseOneOrNone("Choose", choices.toArray()); choice = (String) GuiUtils.chooseOneOrNone("Choose", choices);
} }
if (choice == null) { if (choice == null) {
@@ -1617,7 +1617,7 @@ public class GameAction {
} else if (choices.size() == 1) { } else if (choices.size() == 1) {
sa = choices.get(0); sa = choices.get(0);
} else { } else {
sa = (SpellAbility) GuiUtils.chooseOneOrNone("Choose", choices.toArray()); sa = (SpellAbility) GuiUtils.chooseOneOrNone("Choose", choices);
} }
if (sa == null) { if (sa == null) {
@@ -1789,7 +1789,7 @@ public class GameAction {
Object tapForConvoke = null; Object tapForConvoke = null;
if (sa.getActivatingPlayer().isHuman()) { if (sa.getActivatingPlayer().isHuman()) {
tapForConvoke = GuiUtils.chooseOneOrNone("Tap for Convoke? " + newCost.toString(), tapForConvoke = GuiUtils.chooseOneOrNone("Tap for Convoke? " + newCost.toString(),
choices.toArray()); choices);
} else { } else {
// TODO: AI to choose a creature to tap would go here // TODO: AI to choose a creature to tap would go here
// Probably along with deciding how many creatures to // Probably along with deciding how many creatures to
@@ -1804,7 +1804,7 @@ public class GameAction {
if (usableColors.size() > 1) { if (usableColors.size() > 1) {
if (sa.getActivatingPlayer().isHuman()) { if (sa.getActivatingPlayer().isHuman()) {
chosenColor = (String) GuiUtils.chooseOne("Convoke for which color?", chosenColor = (String) GuiUtils.chooseOne("Convoke for which color?",
usableColors.toArray()); usableColors);
} else { } else {
// TODO: AI for choosing which color to // TODO: AI for choosing which color to
// convoke goes here. // convoke goes here.
@@ -1831,8 +1831,7 @@ public class GameAction {
} }
if (sa.getActivatingPlayer().isHuman()) { if (sa.getActivatingPlayer().isHuman()) {
tapForConvoke = GuiUtils.chooseOneOrNone("Tap for Convoke? " + newCost.toString(), tapForConvoke = GuiUtils.chooseOneOrNone("Tap for Convoke? " + newCost.toString(), choices);
choices.toArray());
} else { } else {
// TODO: AI to choose a creature to tap would go // TODO: AI to choose a creature to tap would go
// here // here
@@ -1923,12 +1922,12 @@ public class GameAction {
} }
String choice; String choice;
if (choices.size() == 0) { if (choices.isEmpty()) {
return null; return null;
} else if (choices.size() == 1) { } else if (choices.size() == 1) {
choice = choices.get(0); choice = choices.get(0);
} else { } else {
choice = (String) GuiUtils.chooseOneOrNone("Choose", choices.toArray()); choice = (String) GuiUtils.chooseOneOrNone("Choose", choices);
} }
final SpellAbility ability = map.get(choice); final SpellAbility ability = map.get(choice);

View File

@@ -153,7 +153,7 @@ public final class GameActionUtil {
} }
} // while } // while
GuiUtils.chooseOneOrNone("Revealed cards:", revealed.toArray()); GuiUtils.chooseOneOrNone("Revealed cards:", revealed);
if (cascadedCard != null) { if (cascadedCard != null) {
@@ -285,7 +285,7 @@ public final class GameActionUtil {
rippledCards[i] = crd; rippledCards[i] = crd;
} }
} // for } // for
GuiUtils.chooseOneOrNone("Revealed cards:", revealed.toArray()); GuiUtils.chooseOneOrNone("Revealed cards:", revealed);
for (int i = 0; i < rippleMax; i++) { for (int i = 0; i < rippleMax; i++) {
if (rippledCards[i] != null) { if (rippledCards[i] != null) {

View File

@@ -964,13 +964,13 @@ public final class AbilityFactoryChangeZone {
// choosing // choosing
// a card{ // a card{
GuiUtils.chooseOneOrNone(sa.getSourceCard().getName() + " - Looking at Library", GuiUtils.chooseOneOrNone(sa.getSourceCard().getName() + " - Looking at Library",
player.getCardsIn(ZoneType.Library).toArray()); player.getCardsIn(ZoneType.Library));
} }
// Look at opponents hand before moving onto choosing a card // Look at opponents hand before moving onto choosing a card
if (origin.contains(ZoneType.Hand) && player.isComputer()) { if (origin.contains(ZoneType.Hand) && player.isComputer()) {
GuiUtils.chooseOneOrNone(sa.getSourceCard().getName() + " - Looking at Opponent's Hand", player GuiUtils.chooseOneOrNone(sa.getSourceCard().getName() + " - Looking at Opponent's Hand", player
.getCardsIn(ZoneType.Hand).toArray()); .getCardsIn(ZoneType.Hand));
} }
fetchList = AbilityFactory.filterListByType(fetchList, params.get("ChangeType"), sa); fetchList = AbilityFactory.filterListByType(fetchList, params.get("ChangeType"), sa);
} }
@@ -990,7 +990,7 @@ public final class AbilityFactoryChangeZone {
Object o; Object o;
if (params.containsKey("AtRandom")) { if (params.containsKey("AtRandom")) {
o = CardUtil.getRandom(fetchList.toArray()); o = CardUtil.getRandom(fetchList);
} else if (params.containsKey("Mandatory")) { } else if (params.containsKey("Mandatory")) {
o = GuiUtils.chooseOne("Select a card", fetchList); o = GuiUtils.chooseOne("Select a card", fetchList);
} else if (params.containsKey("Defined")) { } else if (params.containsKey("Defined")) {
@@ -1159,7 +1159,7 @@ public final class AbilityFactoryChangeZone {
// Improve the AI for fetching. // Improve the AI for fetching.
Card c = null; Card c = null;
if (params.containsKey("AtRandom")) { if (params.containsKey("AtRandom")) {
c = CardUtil.getRandom(fetchList.toArray()); c = CardUtil.getRandom(fetchList);
} else if (defined) { } else if (defined) {
c = fetchList.get(0); c = fetchList.get(0);
} else { } else {

View File

@@ -1967,7 +1967,7 @@ public final class AbilityFactoryChoose {
for (int i = 0; i < validAmount; i++) { for (int i = 0; i < validAmount; i++) {
if (p.isHuman()) { if (p.isHuman()) {
final String choiceTitle = params.containsKey("ChoiceTitle") ? params.get("ChoiceTitle") : "Choose a card "; final String choiceTitle = params.containsKey("ChoiceTitle") ? params.get("ChoiceTitle") : "Choose a card ";
final Object o = GuiUtils.chooseOneOrNone(choiceTitle, choices.toArray()); final Card o = GuiUtils.chooseOneOrNone(choiceTitle, choices);
if (o != null) { if (o != null) {
chosen.add((Card) o); chosen.add((Card) o);
choices.remove((Card) o); choices.remove((Card) o);

View File

@@ -766,7 +766,7 @@ public final class AbilityFactoryClash {
// first, separate the cards into piles // first, separate the cards into piles
if (separator.isHuman()) { if (separator.isHuman()) {
final List<Object> firstPile = GuiUtils.getOrderChoices("Place into two piles", "Pile 1", -1, (Object[])pool.toArray(), null); final List<Object> firstPile = GuiUtils.getOrderChoices("Place into two piles", "Pile 1", -1, pool.toArray(), null);
for (final Object o : firstPile) { for (final Object o : firstPile) {
pile1.add((Card)o); pile1.add((Card)o);
} }

View File

@@ -1215,7 +1215,7 @@ public class AbilityFactoryCounters {
else { else {
// TODO: ArsenalNut (06 Feb 12) - computer needs better logic to pick a counter type and probably an initial target // TODO: ArsenalNut (06 Feb 12) - computer needs better logic to pick a counter type and probably an initial target
// find first nonzero counter on target // find first nonzero counter on target
for (Object key : tgtCounters.keySet().toArray()) { for (Object key : tgtCounters.keySet()) {
if (tgtCounters.get(key) > 0) { if (tgtCounters.get(key) > 0) {
chosenType = (Counters) key; chosenType = (Counters) key;
break; break;
@@ -1244,7 +1244,7 @@ public class AbilityFactoryCounters {
choices.add("" + i); choices.add("" + i);
} }
final String prompt = "Select the number of " + type + " counters to remove"; final String prompt = "Select the number of " + type + " counters to remove";
final Object o = GuiUtils.chooseOne(prompt, choices.toArray()); final String o = GuiUtils.chooseOne(prompt, choices);
counterAmount = Integer.parseInt((String) o); counterAmount = Integer.parseInt((String) o);
} }
} }

View File

@@ -924,7 +924,7 @@ public class AbilityFactoryMana {
baseMana = InputPayManaCostUtil.getShortColorString(colors.get(0)); baseMana = InputPayManaCostUtil.getShortColorString(colors.get(0));
} else { } else {
if (player.isHuman()) { if (player.isHuman()) {
final Object o = GuiUtils.chooseOneOrNone("Select Mana to Produce", colors.toArray()); final Object o = GuiUtils.chooseOneOrNone("Select Mana to Produce", colors);
if (o == null) { if (o == null) {
// User hit cancel // User hit cancel
abMana.setCanceled(true); abMana.setCanceled(true);

View File

@@ -466,7 +466,7 @@ public final class AbilityFactoryPlay {
if (sas.size() == 1) { if (sas.size() == 1) {
tgtSA = sas.get(0); tgtSA = sas.get(0);
} else if (sa.getActivatingPlayer().isHuman()) { } else if (sa.getActivatingPlayer().isHuman()) {
tgtSA = (SpellAbility) GuiUtils.chooseOne("Select a spell to cast", sas.toArray()); tgtSA = GuiUtils.chooseOne("Select a spell to cast", sas);
} else { } else {
tgtSA = sas.get(0); tgtSA = sas.get(0);
} }

View File

@@ -625,7 +625,7 @@ public final class AbilityFactoryReveal {
if (libraryPosition2 == -1) { if (libraryPosition2 == -1) {
prompt = "Put the rest on the bottom of the library in any order"; prompt = "Put the rest on the bottom of the library in any order";
} }
chosen = GuiUtils.chooseOne(prompt, rest.toArray()); chosen = GuiUtils.chooseOne(prompt, rest);
} else { } else {
chosen = rest.get(0); chosen = rest.get(0);
} }
@@ -1046,7 +1046,7 @@ public final class AbilityFactoryReveal {
} }
if (revealed.size() > 0) { if (revealed.size() > 0) {
GuiUtils.chooseOne(p + " revealed: ", revealed.toArray()); GuiUtils.chooseOne(p + " revealed: ", revealed);
} }
// TODO Allow Human to choose the order // TODO Allow Human to choose the order
@@ -1424,7 +1424,7 @@ public final class AbilityFactoryReveal {
final CardList hand = p.getCardsIn(ZoneType.Hand); final CardList hand = p.getCardsIn(ZoneType.Hand);
if (sa.getActivatingPlayer().isHuman()) { if (sa.getActivatingPlayer().isHuman()) {
if (hand.size() > 0) { if (hand.size() > 0) {
GuiUtils.chooseOne(p + "'s hand", hand.toArray()); GuiUtils.chooseOne(p + "'s hand", hand);
} else { } else {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append(p).append("'s hand is empty!"); sb.append(p).append("'s hand is empty!");
@@ -2050,7 +2050,7 @@ public final class AbilityFactoryReveal {
topCards.add(lib.get(j)); topCards.add(lib.get(j));
} }
List<Object> orderedCards = GuiUtils.getOrderChoices("Select order to Rearrange", "Top of Library", 0, (Object[]) topCards.toArray(), null); List<Object> orderedCards = GuiUtils.getOrderChoices("Select order to Rearrange", "Top of Library", 0, topCards.toArray(), null);
for (int i = maxCards - 1; i >= 0; i--) { for (int i = maxCards - 1; i >= 0; i--) {
Card next = (Card) orderedCards.get(i); Card next = (Card) orderedCards.get(i);
Singletons.getModel().getGameAction().moveToLibrary(next, 0); Singletons.getModel().getGameAction().moveToLibrary(next, 0);
@@ -2372,8 +2372,8 @@ public final class AbilityFactoryReveal {
if (handChoices.size() > 0) { if (handChoices.size() > 0) {
final CardList revealed = new CardList(); final CardList revealed = new CardList();
if (params.containsKey("Random")) { if (params.containsKey("Random")) {
revealed.add(CardUtil.getRandom(handChoices.toArray())); revealed.add(CardUtil.getRandom(handChoices));
GuiUtils.chooseOneOrNone("Revealed card(s)", revealed.toArray()); GuiUtils.chooseOneOrNone("Revealed card(s)", revealed);
} else { } else {
CardList valid = new CardList(handChoices); CardList valid = new CardList(handChoices);
int max = 1; int max = 1;
@@ -2385,7 +2385,7 @@ public final class AbilityFactoryReveal {
} }
revealed.addAll(AbilityFactoryReveal.getRevealedList(sa.getActivatingPlayer(), valid, max, anyNumber)); revealed.addAll(AbilityFactoryReveal.getRevealedList(sa.getActivatingPlayer(), valid, max, anyNumber));
if (sa.getActivatingPlayer().isComputer()) { if (sa.getActivatingPlayer().isComputer()) {
GuiUtils.chooseOneOrNone("Revealed card(s)", revealed.toArray()); GuiUtils.chooseOneOrNone("Revealed card(s)", revealed);
} }
} }
@@ -2414,7 +2414,7 @@ public final class AbilityFactoryReveal {
final int validamount = Math.min(valid.size(), max); final int validamount = Math.min(valid.size(), max);
if (anyNumber && player.isHuman() && validamount > 0) { if (anyNumber && player.isHuman() && validamount > 0) {
final List<Object> selection = GuiUtils.getOrderChoices("Choose Which Cards to Reveal", "Revealed", -1, (Object[]) valid.toArray(), null); final List<Object> selection = GuiUtils.getOrderChoices("Choose Which Cards to Reveal", "Revealed", -1, valid.toArray(), null);
for (final Object o : selection) { for (final Object o : selection) {
if (o != null && o instanceof Card) { if (o != null && o instanceof Card) {
chosen.add((Card) o); chosen.add((Card) o);

View File

@@ -566,9 +566,9 @@ public class AbilityFactorySacrifice {
} }
Object o; Object o;
if (optional) { if (optional) {
o = GuiUtils.chooseOneOrNone("Select a card to sacrifice", list.toArray()); o = GuiUtils.chooseOneOrNone("Select a card to sacrifice", list);
} else { } else {
o = GuiUtils.chooseOne("Select a card to sacrifice", list.toArray()); o = GuiUtils.chooseOne("Select a card to sacrifice", list);
} }
if (o != null) { if (o != null) {
final Card c = (Card) o; final Card c = (Card) o;
@@ -613,7 +613,7 @@ public class AbilityFactorySacrifice {
CardList battlefield = p.getCardsIn(ZoneType.Battlefield); CardList battlefield = p.getCardsIn(ZoneType.Battlefield);
CardList list = AbilityFactory.filterListByType(battlefield, valid, sa); CardList list = AbilityFactory.filterListByType(battlefield, valid, sa);
if (list.size() != 0) { if (list.size() != 0) {
final Card sac = CardUtil.getRandom(list.toArray()); final Card sac = CardUtil.getRandom(list);
if (destroy) { if (destroy) {
if (Singletons.getModel().getGameAction().destroy(sac)) { if (Singletons.getModel().getGameAction().destroy(sac)) {
sacList.add(sac); sacList.add(sac);

View File

@@ -1334,7 +1334,7 @@ public class AbilityFactoryZoneAffecting {
if (p.isHuman()) { if (p.isHuman()) {
// "reveal to computer" for information gathering // "reveal to computer" for information gathering
} else { } else {
GuiUtils.chooseOneOrNone("Revealed computer hand", dPHand.toArray()); GuiUtils.chooseOneOrNone("Revealed computer hand", dPHand);
} }
String valid = params.get("DiscardValid"); String valid = params.get("DiscardValid");
@@ -1381,7 +1381,7 @@ public class AbilityFactoryZoneAffecting {
if (p.isComputer()) { // discard AI cards if (p.isComputer()) { // discard AI cards
CardList list = ComputerUtil.discardNumTypeAI(numCards, dValid, sa); CardList list = ComputerUtil.discardNumTypeAI(numCards, dValid, sa);
if (mode.startsWith("Reveal")) { if (mode.startsWith("Reveal")) {
GuiUtils.chooseOneOrNone("Computer has chosen", list.toArray()); GuiUtils.chooseOneOrNone("Computer has chosen", list);
} }
discarded.addAll(list); discarded.addAll(list);
for (Card card : list) { for (Card card : list) {
@@ -1414,7 +1414,7 @@ public class AbilityFactoryZoneAffecting {
if (mode.startsWith("Reveal")) { if (mode.startsWith("Reveal")) {
final CardList dCs = new CardList(); final CardList dCs = new CardList();
dCs.add(dC); dCs.add(dC);
GuiUtils.chooseOneOrNone("Computer has chosen", dCs.toArray()); GuiUtils.chooseOneOrNone("Computer has chosen", dCs);
} }
discarded.add(dC); discarded.add(dC);
p.discard(dC, sa); p.discard(dC, sa);
@@ -1423,7 +1423,7 @@ public class AbilityFactoryZoneAffecting {
} else { } else {
// human // human
if (mode.startsWith("Reveal")) { if (mode.startsWith("Reveal")) {
GuiUtils.chooseOneOrNone("Revealed " + p + " hand", dPHand.toArray()); GuiUtils.chooseOneOrNone("Revealed " + p + " hand", dPHand);
} }
for (int i = 0; i < numCards; i++) { for (int i = 0; i < numCards; i++) {

View File

@@ -281,7 +281,7 @@ class CardFactoryArtifacts {
} }
} }
} // while } // while
GuiUtils.chooseOneOrNone("Revealed cards:", revealed.toArray()); GuiUtils.chooseOneOrNone("Revealed cards:", revealed);
for (final Card revealedCard : revealed) { for (final Card revealedCard : revealed) {
Singletons.getModel().getGameAction().moveToBottomOfLibrary(revealedCard); Singletons.getModel().getGameAction().moveToBottomOfLibrary(revealedCard);
} }
@@ -370,7 +370,7 @@ class CardFactoryArtifacts {
if (i == 4) { if (i == 4) {
title = "Put fourth from top of library: "; title = "Put fourth from top of library: ";
} }
final Object o = GuiUtils.chooseOneOrNone(title, lands.toArray()); final Object o = GuiUtils.chooseOneOrNone(title, lands);
if (o == null) { if (o == null) {
break; break;
} }

View File

@@ -506,7 +506,7 @@ public class CardFactoryCreatures {
final CardList cl = new CardList(); final CardList cl = new CardList();
cl.add(lib.get(0)); cl.add(lib.get(0));
GuiUtils.chooseOneOrNone("Top card", cl.toArray()); GuiUtils.chooseOneOrNone("Top card", cl);
} }
@Override @Override
@@ -1000,8 +1000,7 @@ public class CardFactoryCreatures {
if (card.getController().isHuman()) { if (card.getController().isHuman()) {
if (creats.size() > 0) { if (creats.size() > 0) {
final List<Card> selection = GuiUtils.chooseNoneOrMany("Select creatures to sacrifice", final List<Card> selection = GuiUtils.chooseNoneOrMany("Select creatures to sacrifice", creats);
creats.toArray());
numCreatures[0] = selection.size(); numCreatures[0] = selection.size();
for (int m = 0; m < selection.size(); m++) { for (int m = 0; m < selection.size(); m++) {
@@ -1345,7 +1344,7 @@ public class CardFactoryCreatures {
final CardList revealed = new CardList(); final CardList revealed = new CardList();
for (int i = 0; i < numCards; i++) { for (int i = 0; i < numCards; i++) {
final Card random = CardUtil.getRandom(hand.toArray()); final Card random = CardUtil.getRandom(hand);
revealed.add(random); revealed.add(random);
hand.remove(random); hand.remove(random);
} }

View File

@@ -125,7 +125,7 @@ public class CardFactoryInstants {
final CardList libraryList = AllZone.getHumanPlayer().getCardsIn(ZoneType.Library); final CardList libraryList = AllZone.getHumanPlayer().getCardsIn(ZoneType.Library);
final CardList selectedCards = new CardList(); final CardList selectedCards = new CardList();
Object o = GuiUtils.chooseOneOrNone("Select first card", libraryList.toArray()); Object o = GuiUtils.chooseOneOrNone("Select first card", libraryList);
if (o != null) { if (o != null) {
final Card c1 = (Card) o; final Card c1 = (Card) o;
libraryList.remove(c1); libraryList.remove(c1);
@@ -133,7 +133,7 @@ public class CardFactoryInstants {
} else { } else {
return; return;
} }
o = GuiUtils.chooseOneOrNone("Select second card", libraryList.toArray()); o = GuiUtils.chooseOneOrNone("Select second card", libraryList);
if (o != null) { if (o != null) {
final Card c2 = (Card) o; final Card c2 = (Card) o;
libraryList.remove(c2); libraryList.remove(c2);
@@ -141,7 +141,7 @@ public class CardFactoryInstants {
} else { } else {
return; return;
} }
o = GuiUtils.chooseOneOrNone("Select third card", libraryList.toArray()); o = GuiUtils.chooseOneOrNone("Select third card", libraryList);
if (o != null) { if (o != null) {
final Card c3 = (Card) o; final Card c3 = (Card) o;
libraryList.remove(c3); libraryList.remove(c3);

View File

@@ -196,7 +196,7 @@ public class CardFactorySorceries {
pile1.add(biggest); pile1.add(biggest);
cards.remove(biggest); cards.remove(biggest);
if (cards.size() > 2) { if (cards.size() > 2) {
final Card random = CardUtil.getRandom(cards.toArray()); final Card random = CardUtil.getRandom(cards);
pile1.add(random); pile1.add(random);
} }
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@@ -229,8 +229,7 @@ public class CardFactorySorceries {
final int numChosen = chosen.size(); final int numChosen = chosen.size();
for (int i = 0; i < numChosen; i++) { for (int i = 0; i < numChosen; i++) {
final Object check = GuiUtils.chooseOneOrNone("Select spells to play in reverse order: ", final Card check = GuiUtils.chooseOneOrNone("Select spells to play in reverse order: ", chosen);
chosen.toArray());
if (check == null) { if (check == null) {
break; break;
} }
@@ -1161,7 +1160,7 @@ public class CardFactorySorceries {
final int num = CardFactoryUtil.getNumberOfManaSymbolsByColor("U", topCards); final int num = CardFactoryUtil.getNumberOfManaSymbolsByColor("U", topCards);
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
sb.append("Revealed cards - ").append(num).append(" U mana symbols"); sb.append("Revealed cards - ").append(num).append(" U mana symbols");
GuiUtils.chooseOneOrNone(sb.toString(), topCards.toArray()); GuiUtils.chooseOneOrNone(sb.toString(), topCards);
// opponent moves this many cards to graveyard // opponent moves this many cards to graveyard
opp.mill(num); opp.mill(num);
@@ -1413,8 +1412,7 @@ public class CardFactorySorceries {
} }
}); });
final Object check = GuiUtils.chooseOneOrNone("Select target creature with CMC < X", final Card check = GuiUtils.chooseOneOrNone("Select target creature with CMC < X", grave);
grave.toArray());
if (check != null) { if (check != null) {
final Card c = (Card) check; final Card c = (Card) check;
if (c.canBeTargetedBy(spell)) { if (c.canBeTargetedBy(spell)) {
@@ -1584,14 +1582,14 @@ public class CardFactorySorceries {
private ArrayList<String> chooseTwo(final ArrayList<String> choices) { private ArrayList<String> chooseTwo(final ArrayList<String> choices) {
final ArrayList<String> out = new ArrayList<String>(); final ArrayList<String> out = new ArrayList<String>();
Object o = GuiUtils.chooseOneOrNone("Choose Two", choices.toArray()); Object o = GuiUtils.chooseOneOrNone("Choose Two", choices);
if (o == null) { if (o == null) {
return null; return null;
} }
out.add((String) o); out.add((String) o);
choices.remove(out.get(0)); choices.remove(out.get(0));
o = GuiUtils.chooseOneOrNone("Choose Two", choices.toArray()); o = GuiUtils.chooseOneOrNone("Choose Two", choices);
if (o == null) { if (o == null) {
return null; return null;
} }
@@ -1637,7 +1635,7 @@ public class CardFactorySorceries {
// Sacrifice an artifact // Sacrifice an artifact
CardList arts = p.getCardsIn(ZoneType.Battlefield); CardList arts = p.getCardsIn(ZoneType.Battlefield);
arts = arts.filter(Presets.ARTIFACTS); arts = arts.filter(Presets.ARTIFACTS);
final Object toSac = GuiUtils.chooseOneOrNone("Sacrifice an artifact", arts.toArray()); final Object toSac = GuiUtils.chooseOneOrNone("Sacrifice an artifact", arts);
if (toSac != null) { if (toSac != null) {
final Card c = (Card) toSac; final Card c = (Card) toSac;
baseCMC = CardUtil.getConvertedManaCost(c); baseCMC = CardUtil.getConvertedManaCost(c);
@@ -1648,9 +1646,9 @@ public class CardFactorySorceries {
// Search your library for an artifact // Search your library for an artifact
final CardList lib = p.getCardsIn(ZoneType.Library); final CardList lib = p.getCardsIn(ZoneType.Library);
GuiUtils.chooseOneOrNone("Looking at Library", lib.toArray()); GuiUtils.chooseOneOrNone("Looking at Library", lib);
final CardList libArts = lib.filter(Presets.ARTIFACTS); final CardList libArts = lib.filter(Presets.ARTIFACTS);
final Object o = GuiUtils.chooseOneOrNone("Search for artifact", libArts.toArray()); final Object o = GuiUtils.chooseOneOrNone("Search for artifact", libArts);
if (o != null) { if (o != null) {
newArtifact[0] = (Card) o; newArtifact[0] = (Card) o;
} else { } else {

View File

@@ -1119,7 +1119,7 @@ public class CardFactoryUtil {
return; return;
} }
final Object o = GuiUtils.chooseOneOrNone("Select a card", sameCost.toArray()); final Card o = GuiUtils.chooseOneOrNone("Select a card", sameCost);
if (o != null) { if (o != null) {
// ability.setTargetCard((Card)o); // ability.setTargetCard((Card)o);
@@ -1327,7 +1327,7 @@ public class CardFactoryUtil {
question.append(manacost).append(" or less from your graveyard to your hand?"); question.append(manacost).append(" or less from your graveyard to your hand?");
if (GameActionUtil.showYesNoDialog(sourceCard, question.toString())) { if (GameActionUtil.showYesNoDialog(sourceCard, question.toString())) {
final Object o = GuiUtils.chooseOneOrNone("Select a card", sameCost.toArray()); final Card o = GuiUtils.chooseOneOrNone("Select a card", sameCost);
if (o != null) { if (o != null) {
final Card c1 = (Card) o; final Card c1 = (Card) o;
@@ -5063,7 +5063,7 @@ public class CardFactoryUtil {
card.clearDevoured(); card.clearDevoured();
if (card.getController().isHuman()) { if (card.getController().isHuman()) {
if (creats.size() > 0) { if (creats.size() > 0) {
final List<Object> selection = GuiUtils.getOrderChoices("Devour", "Devouring", -1, (Object[]) creats.toArray(), null); final List<Object> selection = GuiUtils.getOrderChoices("Devour", "Devouring", -1, creats.toArray(), null);
numCreatures[0] = selection.size(); numCreatures[0] = selection.size();
for (Object o : selection) { for (Object o : selection) {

View File

@@ -325,8 +325,8 @@ public class CostExile extends CostPartWithList {
this.cancel(); this.cancel();
} }
final Object o = GuiUtils final Card o = GuiUtils
.chooseOneOrNone("Exile from " + part.getFrom(), this.typeList.toArray()); .chooseOneOrNone("Exile from " + part.getFrom(), this.typeList);
if (o != null) { if (o != null) {
final Card c = (Card) o; final Card c = (Card) o;

View File

@@ -418,8 +418,8 @@ public class CostRemoveCounter extends CostPartWithList {
this.cancel(); this.cancel();
} }
final Object o = GuiUtils final Card o = GuiUtils
.chooseOneOrNone("Remove counter(s) from a card in " + costRemoveCounter.getZone(), this.typeList.toArray()); .chooseOneOrNone("Remove counter(s) from a card in " + costRemoveCounter.getZone(), this.typeList);
if (o != null) { if (o != null) {
final Card card = (Card) o; final Card card = (Card) o;

View File

@@ -129,7 +129,7 @@ public class CostReveal extends CostPartWithList {
*/ */
@Override @Override
public final void payAI(final SpellAbility ability, final Card source, final CostPayment payment) { public final void payAI(final SpellAbility ability, final Card source, final CostPayment payment) {
GuiUtils.chooseOneOrNone("Revealed cards:", this.getList().toArray()); GuiUtils.chooseOneOrNone("Revealed cards:", this.getList());
} }
/* /*

View File

@@ -331,7 +331,7 @@ public class ManaPool {
Object o; Object o;
if (this.owner.isHuman()) { if (this.owner.isHuman()) {
o = GuiUtils.chooseOneOrNone("Pay Mana from Mana Pool", alChoice.toArray()); o = GuiUtils.chooseOneOrNone("Pay Mana from Mana Pool", alChoice);
} else { } else {
o = alChoice.get(0); // owner is computer o = alChoice.get(0); // owner is computer
} }

View File

@@ -127,8 +127,8 @@ public class ReplacementHandler {
if (possibleReplacers.size() > 1) { if (possibleReplacers.size() > 1) {
if (decider.isHuman()) { if (decider.isHuman()) {
chosenRE = (ReplacementEffect) GuiUtils.chooseOne("Choose which replacement effect to apply.", chosenRE = GuiUtils.chooseOne("Choose which replacement effect to apply.",
possibleReplacers.toArray()); possibleReplacers);
} else { } else {
// AI logic for choosing which replacement effect to apply // AI logic for choosing which replacement effect to apply
// happens here. // happens here.

View File

@@ -21,7 +21,6 @@ import java.util.Arrays;
import forge.Card; import forge.Card;
import forge.CardCharacteristicName; import forge.CardCharacteristicName;
import forge.CardList;
import forge.Command; import forge.Command;
import forge.card.CardCharacteristics; import forge.card.CardCharacteristics;
import forge.card.trigger.ZCTrigger; import forge.card.trigger.ZCTrigger;
@@ -133,7 +132,7 @@ public class AbilityTriggered extends Ability implements Command {
* @return a boolean. * @return a boolean.
*/ */
public final boolean triggerFor(final Card c) { public final boolean triggerFor(final Card c) {
return !(new CardList(c)).getValidCards(this.restrictions, c.getController(), c).isEmpty(); return c != null && c.isValid(this.restrictions, c.getController(), c);
} }
/** /**

View File

@@ -527,7 +527,7 @@ public class TargetSelection {
choicesWithDone.add(dummy); choicesWithDone.add(dummy);
} }
final Object check = GuiUtils.chooseOneOrNone(message, choicesWithDone.toArray()); final Card check = GuiUtils.chooseOneOrNone(message, choicesWithDone);
if (check != null) { if (check != null) {
final Card c = (Card) check; final Card c = (Card) check;
if (!c.equals(divBattlefield) && !c.equals(divExile) && !c.equals(divGrave) if (!c.equals(divBattlefield) && !c.equals(divExile) && !c.equals(divGrave)

View File

@@ -141,7 +141,7 @@ public class DeckSerializer extends StorageReaderFolder<Deck> implements IItemSe
final Map<String, Object> root = new HashMap<String, Object>(); final Map<String, Object> root = new HashMap<String, Object>();
root.put("title", d.getName()); root.put("title", d.getName());
final List<String> list = new ArrayList<String>(); final List<String> list = new ArrayList<String>();
for (final Card card : d.getMain().toForgeCardList().toArray()) { for (final Card card : d.getMain().toForgeCardList()) {
// System.out.println(card.getSets().get(card.getSets().size() - // System.out.println(card.getSets().get(card.getSets().size() -
// 1).URL); // 1).URL);
list.add(card.getSets().get(card.getSets().size() - 1).getUrl()); list.add(card.getSets().get(card.getSets().size() - 1).getUrl());

View File

@@ -1,7 +1,6 @@
package forge.game; package forge.game;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
@@ -272,9 +271,9 @@ public class GameNew {
final CardList lib = p.getCardsIn(ZoneType.Library); final CardList lib = p.getCardsIn(ZoneType.Library);
Card ante; Card ante;
if ((lib.size() > 0) && (lib.getNotType("Basic").size() > 1)) { if ((lib.size() > 0) && (lib.getNotType("Basic").size() > 1)) {
ante = CardUtil.getRandom(lib.toArray()); ante = CardUtil.getRandom(lib);
while (ante.isBasicLand()) { while (ante.isBasicLand()) {
ante = CardUtil.getRandom(lib.toArray()); ante = CardUtil.getRandom(lib);
} }
} else if (lib.size() > 1) { } else if (lib.size() > 1) {
ante = lib.get(0); ante = lib.get(0);
@@ -412,7 +411,7 @@ public class GameNew {
System.out.println(library.get(i)); System.out.println(library.get(i));
} }
return Arrays.asList(library.toArray()); return library;
} // smoothComputerManaCurve() } // smoothComputerManaCurve()
// decides who goes first when starting another game, used by newGame() // decides who goes first when starting another game, used by newGame()

View File

@@ -144,7 +144,7 @@ public final class BoosterDraft implements IBoosterDraft {
.showMessageDialog(null, "No custom draft files found.", "", JOptionPane.INFORMATION_MESSAGE); .showMessageDialog(null, "No custom draft files found.", "", JOptionPane.INFORMATION_MESSAGE);
} else { } else {
final CustomLimited draft = (CustomLimited) GuiUtils.chooseOne("Choose Custom Draft", final CustomLimited draft = (CustomLimited) GuiUtils.chooseOne("Choose Custom Draft",
myDrafts.toArray()); myDrafts);
this.setupCustomDraft(draft); this.setupCustomDraft(draft);
} }
break; break;

View File

@@ -439,7 +439,7 @@ public class CombatUtil {
CardList orderedBlockers = null; CardList orderedBlockers = null;
if (player.isHuman()) { if (player.isHuman()) {
List<Object> ordered = GuiUtils.getOrderChoices("Choose Blocking Order", "Damaged First", 0, (Object[])blockers.toArray(), null); List<Object> ordered = GuiUtils.getOrderChoices("Choose Blocking Order", "Damaged First", 0, blockers.toArray(), null);
orderedBlockers = new CardList(); orderedBlockers = new CardList();
for(Object o : ordered) { for(Object o : ordered) {
@@ -467,7 +467,7 @@ public class CombatUtil {
CardList orderedAttacker = null; CardList orderedAttacker = null;
if (player.isHuman()) { if (player.isHuman()) {
List<Object> ordered = GuiUtils.getOrderChoices("Choose Blocking Order", "Damaged First", 0, (Object[])attackers.toArray(), null); List<Object> ordered = GuiUtils.getOrderChoices("Choose Blocking Order", "Damaged First", 0, attackers.toArray(), null);
orderedAttacker = new CardList(); orderedAttacker = new CardList();
for(Object o : ordered) { for(Object o : ordered) {
@@ -2531,7 +2531,7 @@ public class CombatUtil {
public static String getCombatBlockForLog() { public static String getCombatBlockForLog() {
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
Card[] defend = null; CardList defend = null;
// Loop through Defenders // Loop through Defenders
// Append Defending Player/Planeswalker // Append Defending Player/Planeswalker
@@ -2546,9 +2546,9 @@ public class CombatUtil {
for (final Card attacker : list) { for (final Card attacker : list) {
sb.append(combat.getDefendingPlayer()).append(" assigned "); sb.append(combat.getDefendingPlayer()).append(" assigned ");
defend = AllZone.getCombat().getBlockers(attacker).toArray(); defend = AllZone.getCombat().getBlockers(attacker);
if (defend.length > 0) { if (!defend.isEmpty()) {
// loop through blockers // loop through blockers
for (final Card blocker : defend) { for (final Card blocker : defend) {
sb.append(blocker).append(" "); sb.append(blocker).append(" ");
@@ -2833,7 +2833,7 @@ public class CombatUtil {
if (lib.size() > 0) { if (lib.size() > 0) {
final CardList cl = new CardList(); final CardList cl = new CardList();
cl.add(lib.get(0)); cl.add(lib.get(0));
GuiUtils.chooseOneOrNone("Top card", cl.toArray()); GuiUtils.chooseOneOrNone("Top card", cl);
final Card top = lib.get(0); final Card top = lib.get(0);
if (top.isCreature()) { if (top.isCreature()) {
player.gainLife(top.getBaseDefense(), c); player.gainLife(top.getBaseDefense(), c);

View File

@@ -2028,8 +2028,7 @@ public class Upkeep extends Phase implements java.io.Serializable {
if (AllZoneUtil.compareTypeAmountInGraveyard(player, "Creature") > 0) { if (AllZoneUtil.compareTypeAmountInGraveyard(player, "Creature") > 0) {
if (player.isHuman()) { if (player.isHuman()) {
final Object o = GuiUtils.chooseOneOrNone("Pick a creature to return to hand", final Card o = GuiUtils.chooseOneOrNone("Pick a creature to return to hand", graveyardCreatures);
graveyardCreatures.toArray());
if (o != null) { if (o != null) {
final Card card = (Card) o; final Card card = (Card) o;

View File

@@ -174,7 +174,7 @@ public class ComputerUtil {
if (pay.payComputerCosts()) { if (pay.payComputerCosts()) {
AllZone.getStack().addAndUnfreeze(sa); AllZone.getStack().addAndUnfreeze(sa);
if (sa.getSplicedCards() != null && !sa.getSplicedCards().isEmpty()) { if (sa.getSplicedCards() != null && !sa.getSplicedCards().isEmpty()) {
GuiUtils.chooseOneOrNone("Computer reveals spliced cards:", sa.getSplicedCards().toArray()); GuiUtils.chooseOneOrNone("Computer reveals spliced cards:", sa.getSplicedCards());
} }
return true; return true;
// TODO: solve problems with TapsForMana triggers by adding // TODO: solve problems with TapsForMana triggers by adding

View File

@@ -696,7 +696,7 @@ public class ComputerUtilBlock {
&& ((CardFactoryUtil.evaluateCreature(blocker) + ComputerUtilBlock.getDiff()) < CardFactoryUtil && ((CardFactoryUtil.evaluateCreature(blocker) + ComputerUtilBlock.getDiff()) < CardFactoryUtil
.evaluateCreature(attacker)) && CombatUtil.canBlock(attacker, blocker, combat)) { .evaluateCreature(attacker)) && CombatUtil.canBlock(attacker, blocker, combat)) {
combat.addBlocker(attacker, blocker); combat.addBlocker(attacker, blocker);
ComputerUtilBlock.getBlockersLeft().removeAll(blocker); ComputerUtilBlock.getBlockersLeft().remove(blocker);
} }
} }
} }
@@ -903,7 +903,7 @@ public class ComputerUtilBlock {
&& (CombatUtil.mustBlockAnAttacker(blocker, combat) && (CombatUtil.mustBlockAnAttacker(blocker, combat)
|| blocker.hasKeyword("CARDNAME blocks each turn if able."))) { || blocker.hasKeyword("CARDNAME blocks each turn if able."))) {
combat.addBlocker(attacker, blocker); combat.addBlocker(attacker, blocker);
ComputerUtilBlock.getBlockersLeft().removeAll(blocker); ComputerUtilBlock.getBlockersLeft().remove(blocker);
} }
} }
} }

View File

@@ -181,7 +181,7 @@ public class HumanPlayer extends Player {
protected final void doScry(final CardList topN, final int n) { protected final void doScry(final CardList topN, final int n) {
int num = n; int num = n;
for (int i = 0; i < num; i++) { for (int i = 0; i < num; i++) {
final Card c = GuiUtils.chooseOneOrNone("Put on bottom of library.", topN.toArray()); final Card c = GuiUtils.chooseOneOrNone("Put on bottom of library.", topN);
if (c != null) { if (c != null) {
topN.remove(c); topN.remove(c);
Singletons.getModel().getGameAction().moveToBottomOfLibrary(c); Singletons.getModel().getGameAction().moveToBottomOfLibrary(c);

View File

@@ -1646,7 +1646,7 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
CardList list = this.getCardsIn(ZoneType.Hand); CardList list = this.getCardsIn(ZoneType.Hand);
list = list.getValidCards(valid, sa.getSourceCard().getController(), sa.getSourceCard()); list = list.getValidCards(valid, sa.getSourceCard().getController(), sa.getSourceCard());
if (list.size() != 0) { if (list.size() != 0) {
final Card disc = CardUtil.getRandom(list.toArray()); final Card disc = CardUtil.getRandom(list);
discarded.add(disc); discarded.add(disc);
this.doDiscard(disc, sa); this.doDiscard(disc, sa);
} }
@@ -1721,13 +1721,12 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
*/ */
public final void shuffle() { public final void shuffle() {
final PlayerZone library = this.getZone(ZoneType.Library); final PlayerZone library = this.getZone(ZoneType.Library);
final Card[] c = this.getCardsIn(ZoneType.Library).toArray(); final List<Card> list = this.getCardsIn(ZoneType.Library);
if (c.length <= 1) { if (list.size() <= 1) {
return; return;
} }
final ArrayList<Card> list = new ArrayList<Card>(Arrays.asList(c));
// overdone but wanted to make sure it was really random // overdone but wanted to make sure it was really random
final Random random = MyRandom.getRandom(); final Random random = MyRandom.getRandom();
Collections.shuffle(list, random); Collections.shuffle(list, random);

View File

@@ -1350,7 +1350,7 @@ public class MagicStack extends MyObservable {
} }
else{ else{
// Otherwise, gave a dual list form to create instead of needing to do it one at a time // Otherwise, gave a dual list form to create instead of needing to do it one at a time
List<Object> orderedSAs = GuiUtils.getOrderChoices("Select order for Simultaneous Spell Abilities", "Resolve first", 0, (Object[])activePlayerSAs.toArray(), null); List<Object> orderedSAs = GuiUtils.getOrderChoices("Select order for Simultaneous Spell Abilities", "Resolve first", 0, activePlayerSAs.toArray(), null);
int size = orderedSAs.size(); int size = orderedSAs.size();
for(int i = size-1; i >= 0; i--){ for(int i = size-1; i >= 0; i--){
SpellAbility next = (SpellAbility)orderedSAs.get(i); SpellAbility next = (SpellAbility)orderedSAs.get(i);

View File

@@ -620,7 +620,7 @@ public final class GuiDisplayUtil {
*/ */
public static void devModeTutor() { public static void devModeTutor() {
final CardList lib = AllZone.getHumanPlayer().getCardsIn(ZoneType.Library); final CardList lib = AllZone.getHumanPlayer().getCardsIn(ZoneType.Library);
final Object o = GuiUtils.chooseOneOrNone("Choose a card", lib.toArray()); final Object o = GuiUtils.chooseOneOrNone("Choose a card", lib);
if (null == o) { if (null == o) {
return; return;
} else { } else {
@@ -685,8 +685,7 @@ public final class GuiDisplayUtil {
* @since 1.0.15 * @since 1.0.15
*/ */
public static void devModeAddCounter() { public static void devModeAddCounter() {
final CardList play = AllZoneUtil.getCardsIn(ZoneType.Battlefield); final Card o = GuiUtils.chooseOneOrNone("Add counters to which card?", AllZoneUtil.getCardsIn(ZoneType.Battlefield));
final Object o = GuiUtils.chooseOneOrNone("Add counters to which card?", play.toArray());
if (null == o) { if (null == o) {
return; return;
} else { } else {
@@ -718,7 +717,7 @@ public final class GuiDisplayUtil {
*/ */
public static void devModeTapPerm() { public static void devModeTapPerm() {
final CardList play = AllZoneUtil.getCardsIn(ZoneType.Battlefield); final CardList play = AllZoneUtil.getCardsIn(ZoneType.Battlefield);
final Object o = GuiUtils.chooseOneOrNone("Choose a permanent", play.toArray()); final Object o = GuiUtils.chooseOneOrNone("Choose a permanent", play);
if (null == o) { if (null == o) {
return; return;
} else { } else {
@@ -736,7 +735,7 @@ public final class GuiDisplayUtil {
*/ */
public static void devModeUntapPerm() { public static void devModeUntapPerm() {
final CardList play = AllZoneUtil.getCardsIn(ZoneType.Battlefield); final CardList play = AllZoneUtil.getCardsIn(ZoneType.Battlefield);
final Object o = GuiUtils.chooseOneOrNone("Choose a permanent", play.toArray()); final Object o = GuiUtils.chooseOneOrNone("Choose a permanent", play);
if (null == o) { if (null == o) {
return; return;
} else { } else {
@@ -765,7 +764,7 @@ public final class GuiDisplayUtil {
*/ */
public static void devModeSetLife() { public static void devModeSetLife() {
final List<Player> players = AllZone.getPlayersInGame(); final List<Player> players = AllZone.getPlayersInGame();
final Object o = GuiUtils.chooseOneOrNone("Set life for which player?", players.toArray()); final Player o = GuiUtils.chooseOneOrNone("Set life for which player?", players);
if (null == o) { if (null == o) {
return; return;
} else { } else {

View File

@@ -44,7 +44,6 @@ import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import forge.Card; import forge.Card;
import forge.CardList;
import forge.gui.match.CMatchUI; import forge.gui.match.CMatchUI;
import forge.properties.ForgeProps; import forge.properties.ForgeProps;
import forge.properties.NewConstants; import forge.properties.NewConstants;
@@ -260,10 +259,6 @@ public final class GuiUtils {
return choice.isEmpty() ? null : choice.get(0); return choice.isEmpty() ? null : choice.get(0);
} // getChoiceOptional(String,T...) } // getChoiceOptional(String,T...)
public static Card chooseOneOrNone(final String message, final CardList choices) {
return chooseOneOrNone(message, choices.toArray());
} // getChoiceOptional(String,T...)
// returned Object will never be null // returned Object will never be null
/** /**
* <p> * <p>
@@ -291,10 +286,6 @@ public final class GuiUtils {
return chooseOne(message, choices); return chooseOne(message, choices);
} }
public static Card chooseOne(final String message, final CardList cardList) {
return chooseOne(message, cardList.toArray());
}
public static <T> T chooseOne(final String message, final Collection<T> choices) { public static <T> T chooseOne(final String message, final Collection<T> choices) {
final List<T> choice = GuiUtils.getChoices(message, 1, 1, choices); final List<T> choice = GuiUtils.getChoices(message, 1, 1, choices);
assert choice.size() == 1; assert choice.size() == 1;
@@ -318,7 +309,9 @@ public final class GuiUtils {
public static <T> List<T> chooseNoneOrMany(final String message, final T[] choices) { public static <T> List<T> chooseNoneOrMany(final String message, final T[] choices) {
return GuiUtils.getChoices(message, 0, choices.length, choices); return GuiUtils.getChoices(message, 0, choices.length, choices);
} // getChoice() } // getChoice()
public static <T> List<T> chooseNoneOrMany(final String message, final List<T> choices) {
return GuiUtils.getChoices(message, 0, choices.size(), choices);
}
// returned Object will never be null // returned Object will never be null
/** /**
* <p> * <p>

View File

@@ -21,7 +21,7 @@ class UnsortedListModel extends AbstractListModel {
} }
public Object getElementAt(int index) { public Object getElementAt(int index) {
return model.toArray()[index]; return model.get(index);
} }
public void add(Object element) { public void add(Object element) {

View File

@@ -106,7 +106,7 @@ public class ControlWinLose {
Constant.Runtime.COMPUTER_DECK[0] = cDeck; Constant.Runtime.COMPUTER_DECK[0] = cDeck;
List<Card> o = GuiUtils.chooseNoneOrMany("Select cards to add to your deck", compAntes.toArray()); List<Card> o = GuiUtils.chooseNoneOrMany("Select cards to add to your deck", compAntes);
if (null != o) { if (null != o) {
for (Card c : o) { for (Card c : o) {
hDeck.getMain().add(c); hDeck.getMain().add(c);

View File

@@ -304,7 +304,7 @@ public class CField implements ICDoc {
choices2.add(crd); choices2.add(crd);
} }
} }
final Card choice = (Card) GuiUtils.chooseOneOrNone(this.title, choices2.toArray()); final Card choice = (Card) GuiUtils.chooseOneOrNone(this.title, choices2);
if (choice != null) { if (choice != null) {
this.doAction(choice); this.doAction(choice);
} }