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.
*/
public final int sumAllCounters() {
final Object[] values = this.counters.values().toArray();
int count = 0;
int num = 0;
for (final Object value2 : values) {
for (final Object value2 : this.counters.values()) {
num = (Integer) value2;
count += num;
}

View File

@@ -37,126 +37,10 @@ import forge.util.closures.Predicate;
public class CardList extends ArrayList<Card> {
private static final long serialVersionUID = 7912620750458976012L;
/**
* <p>
* Constructor for CardList.
* </p>
*/
public CardList() {
}
/**
* <p>
* Constructor for CardList.
* </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);
}
}
public CardList() {}
public CardList(final Card c) { this.add(c); }
public CardList(final Iterable<Card> al) { for(Card c : al) this.add(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>
* getRandomIndex.

View File

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

View File

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

View File

@@ -964,13 +964,13 @@ public final class AbilityFactoryChangeZone {
// choosing
// a card{
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
if (origin.contains(ZoneType.Hand) && player.isComputer()) {
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);
}
@@ -990,7 +990,7 @@ public final class AbilityFactoryChangeZone {
Object o;
if (params.containsKey("AtRandom")) {
o = CardUtil.getRandom(fetchList.toArray());
o = CardUtil.getRandom(fetchList);
} else if (params.containsKey("Mandatory")) {
o = GuiUtils.chooseOne("Select a card", fetchList);
} else if (params.containsKey("Defined")) {
@@ -1159,7 +1159,7 @@ public final class AbilityFactoryChangeZone {
// Improve the AI for fetching.
Card c = null;
if (params.containsKey("AtRandom")) {
c = CardUtil.getRandom(fetchList.toArray());
c = CardUtil.getRandom(fetchList);
} else if (defined) {
c = fetchList.get(0);
} else {

View File

@@ -1967,7 +1967,7 @@ public final class AbilityFactoryChoose {
for (int i = 0; i < validAmount; i++) {
if (p.isHuman()) {
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) {
chosen.add((Card) o);
choices.remove((Card) o);

View File

@@ -766,7 +766,7 @@ public final class AbilityFactoryClash {
// first, separate the cards into piles
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) {
pile1.add((Card)o);
}

View File

@@ -1215,7 +1215,7 @@ public class AbilityFactoryCounters {
else {
// 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
for (Object key : tgtCounters.keySet().toArray()) {
for (Object key : tgtCounters.keySet()) {
if (tgtCounters.get(key) > 0) {
chosenType = (Counters) key;
break;
@@ -1244,7 +1244,7 @@ public class AbilityFactoryCounters {
choices.add("" + i);
}
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);
}
}

View File

@@ -924,7 +924,7 @@ public class AbilityFactoryMana {
baseMana = InputPayManaCostUtil.getShortColorString(colors.get(0));
} else {
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) {
// User hit cancel
abMana.setCanceled(true);

View File

@@ -466,7 +466,7 @@ public final class AbilityFactoryPlay {
if (sas.size() == 1) {
tgtSA = sas.get(0);
} 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 {
tgtSA = sas.get(0);
}

View File

@@ -625,7 +625,7 @@ public final class AbilityFactoryReveal {
if (libraryPosition2 == -1) {
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 {
chosen = rest.get(0);
}
@@ -1046,7 +1046,7 @@ public final class AbilityFactoryReveal {
}
if (revealed.size() > 0) {
GuiUtils.chooseOne(p + " revealed: ", revealed.toArray());
GuiUtils.chooseOne(p + " revealed: ", revealed);
}
// TODO Allow Human to choose the order
@@ -1424,7 +1424,7 @@ public final class AbilityFactoryReveal {
final CardList hand = p.getCardsIn(ZoneType.Hand);
if (sa.getActivatingPlayer().isHuman()) {
if (hand.size() > 0) {
GuiUtils.chooseOne(p + "'s hand", hand.toArray());
GuiUtils.chooseOne(p + "'s hand", hand);
} else {
final StringBuilder sb = new StringBuilder();
sb.append(p).append("'s hand is empty!");
@@ -2050,7 +2050,7 @@ public final class AbilityFactoryReveal {
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--) {
Card next = (Card) orderedCards.get(i);
Singletons.getModel().getGameAction().moveToLibrary(next, 0);
@@ -2372,8 +2372,8 @@ public final class AbilityFactoryReveal {
if (handChoices.size() > 0) {
final CardList revealed = new CardList();
if (params.containsKey("Random")) {
revealed.add(CardUtil.getRandom(handChoices.toArray()));
GuiUtils.chooseOneOrNone("Revealed card(s)", revealed.toArray());
revealed.add(CardUtil.getRandom(handChoices));
GuiUtils.chooseOneOrNone("Revealed card(s)", revealed);
} else {
CardList valid = new CardList(handChoices);
int max = 1;
@@ -2385,7 +2385,7 @@ public final class AbilityFactoryReveal {
}
revealed.addAll(AbilityFactoryReveal.getRevealedList(sa.getActivatingPlayer(), valid, max, anyNumber));
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);
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) {
if (o != null && o instanceof Card) {
chosen.add((Card) o);

View File

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

View File

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

View File

@@ -281,7 +281,7 @@ class CardFactoryArtifacts {
}
}
} // while
GuiUtils.chooseOneOrNone("Revealed cards:", revealed.toArray());
GuiUtils.chooseOneOrNone("Revealed cards:", revealed);
for (final Card revealedCard : revealed) {
Singletons.getModel().getGameAction().moveToBottomOfLibrary(revealedCard);
}
@@ -370,7 +370,7 @@ class CardFactoryArtifacts {
if (i == 4) {
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) {
break;
}

View File

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

View File

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

View File

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

View File

@@ -1119,7 +1119,7 @@ public class CardFactoryUtil {
return;
}
final Object o = GuiUtils.chooseOneOrNone("Select a card", sameCost.toArray());
final Card o = GuiUtils.chooseOneOrNone("Select a card", sameCost);
if (o != null) {
// ability.setTargetCard((Card)o);
@@ -1327,7 +1327,7 @@ public class CardFactoryUtil {
question.append(manacost).append(" or less from your graveyard to your hand?");
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) {
final Card c1 = (Card) o;
@@ -5063,7 +5063,7 @@ public class CardFactoryUtil {
card.clearDevoured();
if (card.getController().isHuman()) {
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();
for (Object o : selection) {

View File

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

View File

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

View File

@@ -129,7 +129,7 @@ public class CostReveal extends CostPartWithList {
*/
@Override
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;
if (this.owner.isHuman()) {
o = GuiUtils.chooseOneOrNone("Pay Mana from Mana Pool", alChoice.toArray());
o = GuiUtils.chooseOneOrNone("Pay Mana from Mana Pool", alChoice);
} else {
o = alChoice.get(0); // owner is computer
}

View File

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

View File

@@ -21,7 +21,6 @@ import java.util.Arrays;
import forge.Card;
import forge.CardCharacteristicName;
import forge.CardList;
import forge.Command;
import forge.card.CardCharacteristics;
import forge.card.trigger.ZCTrigger;
@@ -133,7 +132,7 @@ public class AbilityTriggered extends Ability implements Command {
* @return a boolean.
*/
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);
}
final Object check = GuiUtils.chooseOneOrNone(message, choicesWithDone.toArray());
final Card check = GuiUtils.chooseOneOrNone(message, choicesWithDone);
if (check != null) {
final Card c = (Card) check;
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>();
root.put("title", d.getName());
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() -
// 1).URL);
list.add(card.getSets().get(card.getSets().size() - 1).getUrl());

View File

@@ -1,7 +1,6 @@
package forge.game;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map.Entry;
import java.util.Random;
@@ -272,9 +271,9 @@ public class GameNew {
final CardList lib = p.getCardsIn(ZoneType.Library);
Card ante;
if ((lib.size() > 0) && (lib.getNotType("Basic").size() > 1)) {
ante = CardUtil.getRandom(lib.toArray());
ante = CardUtil.getRandom(lib);
while (ante.isBasicLand()) {
ante = CardUtil.getRandom(lib.toArray());
ante = CardUtil.getRandom(lib);
}
} else if (lib.size() > 1) {
ante = lib.get(0);
@@ -412,7 +411,7 @@ public class GameNew {
System.out.println(library.get(i));
}
return Arrays.asList(library.toArray());
return library;
} // smoothComputerManaCurve()
// 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);
} else {
final CustomLimited draft = (CustomLimited) GuiUtils.chooseOne("Choose Custom Draft",
myDrafts.toArray());
myDrafts);
this.setupCustomDraft(draft);
}
break;

View File

@@ -439,7 +439,7 @@ public class CombatUtil {
CardList orderedBlockers = null;
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();
for(Object o : ordered) {
@@ -467,7 +467,7 @@ public class CombatUtil {
CardList orderedAttacker = null;
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();
for(Object o : ordered) {
@@ -2531,7 +2531,7 @@ public class CombatUtil {
public static String getCombatBlockForLog() {
final StringBuilder sb = new StringBuilder();
Card[] defend = null;
CardList defend = null;
// Loop through Defenders
// Append Defending Player/Planeswalker
@@ -2546,9 +2546,9 @@ public class CombatUtil {
for (final Card attacker : list) {
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
for (final Card blocker : defend) {
sb.append(blocker).append(" ");
@@ -2833,7 +2833,7 @@ public class CombatUtil {
if (lib.size() > 0) {
final CardList cl = new CardList();
cl.add(lib.get(0));
GuiUtils.chooseOneOrNone("Top card", cl.toArray());
GuiUtils.chooseOneOrNone("Top card", cl);
final Card top = lib.get(0);
if (top.isCreature()) {
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 (player.isHuman()) {
final Object o = GuiUtils.chooseOneOrNone("Pick a creature to return to hand",
graveyardCreatures.toArray());
final Card o = GuiUtils.chooseOneOrNone("Pick a creature to return to hand", graveyardCreatures);
if (o != null) {
final Card card = (Card) o;

View File

@@ -174,7 +174,7 @@ public class ComputerUtil {
if (pay.payComputerCosts()) {
AllZone.getStack().addAndUnfreeze(sa);
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;
// TODO: solve problems with TapsForMana triggers by adding

View File

@@ -696,7 +696,7 @@ public class ComputerUtilBlock {
&& ((CardFactoryUtil.evaluateCreature(blocker) + ComputerUtilBlock.getDiff()) < CardFactoryUtil
.evaluateCreature(attacker)) && CombatUtil.canBlock(attacker, blocker, combat)) {
combat.addBlocker(attacker, blocker);
ComputerUtilBlock.getBlockersLeft().removeAll(blocker);
ComputerUtilBlock.getBlockersLeft().remove(blocker);
}
}
}
@@ -903,7 +903,7 @@ public class ComputerUtilBlock {
&& (CombatUtil.mustBlockAnAttacker(blocker, combat)
|| blocker.hasKeyword("CARDNAME blocks each turn if able."))) {
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) {
int num = n;
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) {
topN.remove(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);
list = list.getValidCards(valid, sa.getSourceCard().getController(), sa.getSourceCard());
if (list.size() != 0) {
final Card disc = CardUtil.getRandom(list.toArray());
final Card disc = CardUtil.getRandom(list);
discarded.add(disc);
this.doDiscard(disc, sa);
}
@@ -1721,13 +1721,12 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
*/
public final void shuffle() {
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;
}
final ArrayList<Card> list = new ArrayList<Card>(Arrays.asList(c));
// overdone but wanted to make sure it was really random
final Random random = MyRandom.getRandom();
Collections.shuffle(list, random);

View File

@@ -1350,7 +1350,7 @@ public class MagicStack extends MyObservable {
}
else{
// 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();
for(int i = size-1; i >= 0; i--){
SpellAbility next = (SpellAbility)orderedSAs.get(i);

View File

@@ -620,7 +620,7 @@ public final class GuiDisplayUtil {
*/
public static void devModeTutor() {
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) {
return;
} else {
@@ -685,8 +685,7 @@ public final class GuiDisplayUtil {
* @since 1.0.15
*/
public static void devModeAddCounter() {
final CardList play = AllZoneUtil.getCardsIn(ZoneType.Battlefield);
final Object o = GuiUtils.chooseOneOrNone("Add counters to which card?", play.toArray());
final Card o = GuiUtils.chooseOneOrNone("Add counters to which card?", AllZoneUtil.getCardsIn(ZoneType.Battlefield));
if (null == o) {
return;
} else {
@@ -718,7 +717,7 @@ public final class GuiDisplayUtil {
*/
public static void devModeTapPerm() {
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) {
return;
} else {
@@ -736,7 +735,7 @@ public final class GuiDisplayUtil {
*/
public static void devModeUntapPerm() {
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) {
return;
} else {
@@ -765,7 +764,7 @@ public final class GuiDisplayUtil {
*/
public static void devModeSetLife() {
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) {
return;
} else {

View File

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

View File

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

View File

@@ -106,7 +106,7 @@ public class ControlWinLose {
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) {
for (Card c : o) {
hDeck.getMain().add(c);

View File

@@ -304,7 +304,7 @@ public class CField implements ICDoc {
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) {
this.doAction(choice);
}