removed CardList constructor from array, and thus removed redundant toArray conversions (while lists were passed)

This commit is contained in:
Maxmtg
2012-02-29 07:15:20 +00:00
parent 055c6b5d2c
commit eee0d2e4bb
17 changed files with 113 additions and 164 deletions

View File

@@ -21,8 +21,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import com.google.code.jyield.Generator; import com.google.code.jyield.Generator;
import com.google.code.jyield.Yieldable; import com.google.code.jyield.Yieldable;
@@ -69,8 +67,8 @@ public class CardList implements Iterable<Card> {
* @param c * @param c
* a {@link forge.Card} object. * a {@link forge.Card} object.
*/ */
public CardList(final Card... c) { public CardList(final Card c) {
this.addAll(c); this.add(c);
} }
/** /**
@@ -81,23 +79,10 @@ public class CardList implements Iterable<Card> {
* @param al * @param al
* a {@link java.util.ArrayList} object. * a {@link java.util.ArrayList} object.
*/ */
public CardList(final List<Card> al) { public CardList(final Iterable<Card> al) {
this.addAll(al); this.addAll(al);
} }
/**
* Make a shallow copy of an Iterable's contents; this could be another
* CardList.
*
* @param iterable
* we traverse this and copy its contents into a local field.
*/
public CardList(final Iterable<Card> iterable) {
for (final Card card : iterable) {
this.add(card);
}
}
/** /**
* Create a CardList from a finite generator of Card instances. * Create a CardList from a finite generator of Card instances.
* *

View File

@@ -49,7 +49,7 @@ public class Combat {
// Defenders are the Defending Player + Each Planeswalker that player // Defenders are the Defending Player + Each Planeswalker that player
// controls // controls
private ArrayList<Object> defenders = new ArrayList<Object>(); private List<GameEntity> defenders = new ArrayList<GameEntity>();
private int currentDefender = 0; private int currentDefender = 0;
private int nextDefender = 0; private int nextDefender = 0;
@@ -159,7 +159,7 @@ public class Combat {
* *
* @return a {@link java.util.ArrayList} object. * @return a {@link java.util.ArrayList} object.
*/ */
public final ArrayList<Object> getDefenders() { public final List<GameEntity> getDefenders() {
return this.defenders; return this.defenders;
} }
@@ -171,7 +171,7 @@ public class Combat {
* @param newDef * @param newDef
* a {@link java.util.ArrayList} object. * a {@link java.util.ArrayList} object.
*/ */
public final void setDefenders(final ArrayList<Object> newDef) { public final void setDefenders(final List<GameEntity> newDef) {
this.defenders = newDef; this.defenders = newDef;
} }
@@ -182,15 +182,12 @@ public class Combat {
* *
* @return an array of {@link forge.Card} objects. * @return an array of {@link forge.Card} objects.
*/ */
public final Card[] getDefendingPlaneswalkers() { public final List<Card> getDefendingPlaneswalkers() {
final Card[] pwDefending = new Card[this.defenders.size() - 1]; final List<Card> pwDefending = new ArrayList<Card>();
int i = 0; for (final GameEntity o : this.defenders) {
for (final Object o : this.defenders) {
if (o instanceof Card) { if (o instanceof Card) {
pwDefending[i] = (Card) o; pwDefending.add((Card) o);
i++;
} }
} }
@@ -942,18 +939,14 @@ public class Combat {
* *
* @return an array of {@link forge.Card} objects. * @return an array of {@link forge.Card} objects.
*/ */
public final Card[] getUnblockedAttackers() { public final List<Card> getUnblockedAttackers() {
final CardList out = new CardList(); final List<Card> out = new ArrayList<Card>();
final Iterator<Card> it = this.unblockedMap.keySet().iterator(); for(Card c : this.unblockedMap.keySet()) {
while (it.hasNext()) { // only add creatures without firstStrike to this
// list.
final Card c = it.next();
if (!c.hasFirstStrike()) { if (!c.hasFirstStrike()) {
out.add(c); out.add(c);
} }
} }
return out;
return out.toArray();
} // getUnblockedAttackers() } // getUnblockedAttackers()
/** /**
@@ -963,18 +956,14 @@ public class Combat {
* *
* @return an array of {@link forge.Card} objects. * @return an array of {@link forge.Card} objects.
*/ */
public final Card[] getUnblockedFirstStrikeAttackers() { public final List<Card> getUnblockedFirstStrikeAttackers() {
final CardList out = new CardList(); final List<Card> out = new ArrayList<Card>();
final Iterator<Card> it = this.unblockedMap.keySet().iterator(); for(Card c : this.unblockedMap.keySet()) { // only add creatures without firstStrike to this
while (it.hasNext()) { // only add creatures without firstStrike to this
// list.
final Card c = it.next();
if (c.hasFirstStrike() || c.hasDoubleStrike()) { if (c.hasFirstStrike() || c.hasDoubleStrike()) {
out.add(c); out.add(c);
} }
} }
return out;
return out.toArray();
} // getUnblockedAttackers() } // getUnblockedAttackers()
/** /**

View File

@@ -19,6 +19,7 @@ package forge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -2351,7 +2352,7 @@ public class CombatUtil {
// Loop through Defenders // Loop through Defenders
// Append Defending Player/Planeswalker // Append Defending Player/Planeswalker
final Combat combat = AllZone.getCombat(); final Combat combat = AllZone.getCombat();
final ArrayList<Object> defenders = combat.getDefenders(); final List<GameEntity> defenders = combat.getDefenders();
final CardList[] attackers = combat.sortAttackerByDefender(); final CardList[] attackers = combat.sortAttackerByDefender();
// Not a big fan of the triple nested loop here // Not a big fan of the triple nested loop here
@@ -2384,7 +2385,7 @@ public class CombatUtil {
// Loop through Defenders // Loop through Defenders
// Append Defending Player/Planeswalker // Append Defending Player/Planeswalker
final Combat combat = AllZone.getCombat(); final Combat combat = AllZone.getCombat();
final ArrayList<Object> defenders = combat.getDefenders(); final List<GameEntity> defenders = combat.getDefenders();
final CardList[] attackers = combat.sortAttackerByDefender(); final CardList[] attackers = combat.sortAttackerByDefender();
// Not a big fan of the triple nested loop here // Not a big fan of the triple nested loop here
@@ -2425,7 +2426,7 @@ public class CombatUtil {
// Loop through Defenders // Loop through Defenders
// Append Defending Player/Planeswalker // Append Defending Player/Planeswalker
final ArrayList<Object> defenders = AllZone.getCombat().getDefenders(); final List<GameEntity> defenders = AllZone.getCombat().getDefenders();
final CardList[] attackers = AllZone.getCombat().sortAttackerByDefender(); final CardList[] attackers = AllZone.getCombat().sortAttackerByDefender();
// Not a big fan of the triple nested loop here // Not a big fan of the triple nested loop here

View File

@@ -19,6 +19,7 @@ package forge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Random; import java.util.Random;
import forge.Constant.Zone; import forge.Constant.Zone;
@@ -51,20 +52,6 @@ public class ComputerUtilAttack {
private int aiAggression = 0; // added by Masher, how aggressive the ai private int aiAggression = 0; // added by Masher, how aggressive the ai
// attack will be depending on circumstances // attack will be depending on circumstances
/**
* <p>
* Constructor for ComputerUtil_Attack2.
* </p>
*
* @param possibleAttackers
* an array of {@link forge.Card} objects.
* @param possibleBlockers
* an array of {@link forge.Card} objects.
*/
public ComputerUtilAttack(final Card[] possibleAttackers, final Card[] possibleBlockers) {
this(new CardList(possibleAttackers), new CardList(possibleBlockers));
}
/** /**
* <p> * <p>
* Constructor for ComputerUtil_Attack2. * Constructor for ComputerUtil_Attack2.
@@ -76,12 +63,12 @@ public class ComputerUtilAttack {
* a {@link forge.CardList} object. * a {@link forge.CardList} object.
*/ */
public ComputerUtilAttack(final CardList possibleAttackers, final CardList possibleBlockers) { public ComputerUtilAttack(final CardList possibleAttackers, final CardList possibleBlockers) {
this.humanList = new CardList(possibleBlockers.toArray()); this.humanList = new CardList(possibleBlockers);
this.humanList = this.humanList.getType("Creature"); this.humanList = this.humanList.getType("Creature");
this.computerList = new CardList(possibleAttackers.toArray()); this.computerList = new CardList(possibleAttackers);
this.computerList = this.computerList.getType("Creature"); this.computerList = this.computerList.getType("Creature");
this.playerCreatures = new CardList(possibleBlockers.toArray()); this.playerCreatures = new CardList(possibleBlockers);
this.playerCreatures = this.playerCreatures.getType("Creature"); this.playerCreatures = this.playerCreatures.getType("Creature");
this.attackers = this.getPossibleAttackers(possibleAttackers); this.attackers = this.getPossibleAttackers(possibleAttackers);
@@ -169,7 +156,7 @@ public class ComputerUtilAttack {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public final CardList getPossibleAttackers(final CardList in) { public final CardList getPossibleAttackers(final CardList in) {
CardList list = new CardList(in.toArray()); CardList list = new CardList(in);
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
@Override @Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
@@ -191,8 +178,8 @@ public class ComputerUtilAttack {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public final CardList getPossibleBlockers(final CardList blockers, final CardList attackers) { public final CardList getPossibleBlockers(final CardList blockers, final CardList attackers) {
CardList possibleBlockers = new CardList(blockers.toArray()); CardList possibleBlockers = new CardList(blockers);
final CardList attackerList = new CardList(attackers.toArray()); final CardList attackerList = new CardList(attackers);
possibleBlockers = possibleBlockers.filter(new CardListFilter() { possibleBlockers = possibleBlockers.filter(new CardListFilter() {
@Override @Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {
@@ -225,7 +212,7 @@ public class ComputerUtilAttack {
* @return a {@link forge.CardList} object. * @return a {@link forge.CardList} object.
*/ */
public final CardList notNeededAsBlockers(final CardList attackers, final Combat combat) { public final CardList notNeededAsBlockers(final CardList attackers, final Combat combat) {
final CardList notNeededAsBlockers = new CardList(attackers.toArray()); final CardList notNeededAsBlockers = new CardList(attackers);
CardListUtil.sortAttackLowFirst(attackers); CardListUtil.sortAttackLowFirst(attackers);
int blockersNeeded = attackers.size(); int blockersNeeded = attackers.size();
@@ -343,8 +330,8 @@ public class ComputerUtilAttack {
CardListUtil.sortAttack(this.attackers); CardListUtil.sortAttack(this.attackers);
final CardList remainingAttackers = new CardList(this.attackers.toArray()); final CardList remainingAttackers = new CardList(this.attackers);
final CardList blockableAttackers = new CardList(this.attackers.toArray()); final CardList blockableAttackers = new CardList(this.attackers);
final Player human = AllZone.getHumanPlayer(); final Player human = AllZone.getHumanPlayer();
final Player computer = AllZone.getComputerPlayer(); final Player computer = AllZone.getComputerPlayer();
@@ -386,7 +373,7 @@ public class ComputerUtilAttack {
public final void chooseDefender(final Combat c, final boolean bAssault) { public final void chooseDefender(final Combat c, final boolean bAssault) {
// TODO split attackers to different planeswalker/human // TODO split attackers to different planeswalker/human
// AI will only attack one Defender per combat for now // AI will only attack one Defender per combat for now
final ArrayList<Object> defs = c.getDefenders(); final List<GameEntity> defs = c.getDefenders();
// Randomly determine who EVERYONE is attacking // Randomly determine who EVERYONE is attacking
// would be better to determine more individually // would be better to determine more individually
@@ -394,7 +381,7 @@ public class ComputerUtilAttack {
final Object entity = AllZone.getComputerPlayer().getMustAttackEntity(); final Object entity = AllZone.getComputerPlayer().getMustAttackEntity();
if (null != entity) { if (null != entity) {
final ArrayList<Object> defenders = AllZone.getCombat().getDefenders(); final List<GameEntity> defenders = AllZone.getCombat().getDefenders();
n = defenders.indexOf(entity); n = defenders.indexOf(entity);
if (-1 == n) { if (-1 == n) {
System.out.println("getMustAttackEntity() returned something not in defenders."); System.out.println("getMustAttackEntity() returned something not in defenders.");
@@ -438,7 +425,7 @@ public class ComputerUtilAttack {
// Determine who will be attacked // Determine who will be attacked
this.chooseDefender(combat, bAssault); this.chooseDefender(combat, bAssault);
CardList attackersLeft = new CardList(this.attackers.toArray()); CardList attackersLeft = new CardList(this.attackers);
// Attackers that don't really have a choice // Attackers that don't really have a choice
for (final Card attacker : this.attackers) { for (final Card attacker : this.attackers) {

View File

@@ -17,7 +17,7 @@
*/ */
package forge; package forge;
import java.util.ArrayList; import java.util.List;
import forge.card.cardfactory.CardFactoryUtil; import forge.card.cardfactory.CardFactoryUtil;
@@ -260,7 +260,7 @@ public class ComputerUtilBlock {
final CardList[] attackerLists = combat.sortAttackerByDefender(); final CardList[] attackerLists = combat.sortAttackerByDefender();
final CardList sortedAttackers = new CardList(); final CardList sortedAttackers = new CardList();
final ArrayList<Object> defenders = combat.getDefenders(); final List<GameEntity> defenders = combat.getDefenders();
// Begin with the attackers that pose the biggest threat // Begin with the attackers that pose the biggest threat
CardListUtil.sortByEvaluateCreature(attackerLists[0]); CardListUtil.sortByEvaluateCreature(attackerLists[0]);
@@ -317,7 +317,7 @@ public class ComputerUtilBlock {
*/ */
private static Combat makeGoodBlocks(final Combat combat) { private static Combat makeGoodBlocks(final Combat combat) {
CardList currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft().toArray()); CardList currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft());
for (final Card attacker : ComputerUtilBlock.getAttackersLeft()) { for (final Card attacker : ComputerUtilBlock.getAttackersLeft()) {
@@ -364,7 +364,7 @@ public class ComputerUtilBlock {
combat.addBlocker(attacker, blocker); combat.addBlocker(attacker, blocker);
} }
} }
ComputerUtilBlock.setAttackersLeft(new CardList(currentAttackers.toArray())); ComputerUtilBlock.setAttackersLeft(new CardList(currentAttackers));
return combat; return combat;
} }
@@ -380,7 +380,7 @@ public class ComputerUtilBlock {
*/ */
private static Combat makeGangBlocks(final Combat combat) { private static Combat makeGangBlocks(final Combat combat) {
CardList currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft().toArray()); CardList currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft());
currentAttackers = currentAttackers.getKeywordsDontContain("Rampage"); currentAttackers = currentAttackers.getKeywordsDontContain("Rampage");
currentAttackers = currentAttackers currentAttackers = currentAttackers
.getKeywordsDontContain("CARDNAME can't be blocked by more than one creature."); .getKeywordsDontContain("CARDNAME can't be blocked by more than one creature.");
@@ -424,8 +424,8 @@ public class ComputerUtilBlock {
} }
} }
ComputerUtilBlock.setAttackersLeft(new CardList(currentAttackers.toArray())); ComputerUtilBlock.setAttackersLeft(new CardList(currentAttackers));
currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft().toArray()); currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft());
// Try to block an attacker with two blockers of which only one will die // Try to block an attacker with two blockers of which only one will die
for (final Card attacker : ComputerUtilBlock.getAttackersLeft()) { for (final Card attacker : ComputerUtilBlock.getAttackersLeft()) {
@@ -493,7 +493,7 @@ public class ComputerUtilBlock {
} }
} }
ComputerUtilBlock.setAttackersLeft(new CardList(currentAttackers.toArray())); ComputerUtilBlock.setAttackersLeft(new CardList(currentAttackers));
return combat; return combat;
} }
@@ -509,7 +509,7 @@ public class ComputerUtilBlock {
*/ */
private static Combat makeTradeBlocks(final Combat combat) { private static Combat makeTradeBlocks(final Combat combat) {
CardList currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft().toArray()); CardList currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft());
CardList killingBlockers; CardList killingBlockers;
for (final Card attacker : ComputerUtilBlock.getAttackersLeft()) { for (final Card attacker : ComputerUtilBlock.getAttackersLeft()) {
@@ -528,7 +528,7 @@ public class ComputerUtilBlock {
ComputerUtilBlock.getBlockersLeft().remove(blocker); ComputerUtilBlock.getBlockersLeft().remove(blocker);
} }
} }
ComputerUtilBlock.setAttackersLeft(new CardList(currentAttackers.toArray())); ComputerUtilBlock.setAttackersLeft(new CardList(currentAttackers));
return combat; return combat;
} }
@@ -544,7 +544,7 @@ public class ComputerUtilBlock {
*/ */
private static Combat makeChumpBlocks(final Combat combat) { private static Combat makeChumpBlocks(final Combat combat) {
CardList currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft().toArray()); CardList currentAttackers = new CardList(ComputerUtilBlock.getAttackersLeft());
CardList chumpBlockers; CardList chumpBlockers;
for (final Card attacker : ComputerUtilBlock.getAttackersLeft()) { for (final Card attacker : ComputerUtilBlock.getAttackersLeft()) {
@@ -564,7 +564,7 @@ public class ComputerUtilBlock {
ComputerUtilBlock.getBlockersLeft().remove(blocker); ComputerUtilBlock.getBlockersLeft().remove(blocker);
} }
} }
ComputerUtilBlock.setAttackersLeft(new CardList(currentAttackers.toArray())); ComputerUtilBlock.setAttackersLeft(new CardList(currentAttackers));
return combat; return combat;
} }
@@ -672,7 +672,7 @@ public class ComputerUtilBlock {
safeBlockers = blockers.getKeyword("First Strike"); safeBlockers = blockers.getKeyword("First Strike");
safeBlockers.addAll(blockers.getKeyword("Double Strike")); safeBlockers.addAll(blockers.getKeyword("Double Strike"));
} else { } else {
safeBlockers = new CardList(blockers.toArray()); safeBlockers = new CardList(blockers);
} }
for (final Card blocker : safeBlockers) { for (final Card blocker : safeBlockers) {
@@ -713,13 +713,13 @@ public class ComputerUtilBlock {
combat.removeFromCombat(blocker); combat.removeFromCombat(blocker);
} }
ComputerUtilBlock.setAttackersLeft(new CardList(ComputerUtilBlock.getAttackers().toArray())); // keeps ComputerUtilBlock.setAttackersLeft(new CardList(ComputerUtilBlock.getAttackers())); // keeps
// track // track
// of all // of all
// currently // currently
// unblocked // unblocked
// attackers // attackers
ComputerUtilBlock.setBlockersLeft(new CardList(possibleBlockers.toArray())); // keeps ComputerUtilBlock.setBlockersLeft(new CardList(possibleBlockers)); // keeps
// track of // track of
// all // all
// unassigned // unassigned
@@ -755,13 +755,13 @@ public class ComputerUtilBlock {
return combat; return combat;
} }
ComputerUtilBlock.setAttackersLeft(new CardList(ComputerUtilBlock.getAttackers().toArray())); // keeps ComputerUtilBlock.setAttackersLeft(new CardList(ComputerUtilBlock.getAttackers())); // keeps
// track // track
// of all // of all
// currently // currently
// unblocked // unblocked
// attackers // attackers
ComputerUtilBlock.setBlockersLeft(new CardList(possibleBlockers.toArray())); // keeps ComputerUtilBlock.setBlockersLeft(new CardList(possibleBlockers)); // keeps
// track of // track of
// all // all
// unassigned // unassigned

View File

@@ -18,7 +18,6 @@
package forge; package forge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Observable; import java.util.Observable;
@@ -198,8 +197,11 @@ public class DefaultPlayerZone extends PlayerZone implements java.io.Serializabl
* an array of {@link forge.Card} objects. * an array of {@link forge.Card} objects.
*/ */
@Override @Override
public final void setCards(final Card[] c) { public final void setCards(final Iterable<Card> cards) {
this.setCardList(new ArrayList<Card>(Arrays.asList(c))); List<Card> toSet = new ArrayList<Card>();
for(Card c : cards)
toSet.add(c);
this.setCardList( toSet );
this.update(); this.update();
} }
@@ -311,7 +313,7 @@ public class DefaultPlayerZone extends PlayerZone implements java.io.Serializabl
* @return an array of {@link forge.Card} objects. * @return an array of {@link forge.Card} objects.
*/ */
@Override @Override
public final Card[] getCards() { public final List<Card>getCards() {
return this.getCards(true); return this.getCards(true);
} }
@@ -321,11 +323,9 @@ public class DefaultPlayerZone extends PlayerZone implements java.io.Serializabl
* @see forge.IPlayerZone#getCards(boolean) * @see forge.IPlayerZone#getCards(boolean)
*/ */
@Override @Override
public Card[] getCards(final boolean filter) { public List<Card> getCards(final boolean filter) {
// Non-Battlefield PlayerZones don't care about the filter // Non-Battlefield PlayerZones don't care about the filter
final Card[] c = new Card[this.getCardList().size()]; return new ArrayList<Card>(this.getCardList());
this.getCardList().toArray(c);
return c;
} }
/* /*
@@ -334,12 +334,8 @@ public class DefaultPlayerZone extends PlayerZone implements java.io.Serializabl
* @see forge.IPlayerZone#getCards(int) * @see forge.IPlayerZone#getCards(int)
*/ */
@Override @Override
public final Card[] getCards(final int n) { public final List<Card> getCards(final int n) {
final Card[] c = new Card[Math.min(this.getCardList().size(), n)]; return this.getCardList().subList(0, Math.min(this.getCardList().size(), n));
for (int i = 0; i < c.length; i++) {
c[i] = this.getCardList().get(i);
}
return c;
} }
/* /*

View File

@@ -26,7 +26,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
@@ -1097,14 +1096,14 @@ public final class GuiDisplayUtil {
* @param c * @param c
* an array of {@link forge.Card} objects. * an array of {@link forge.Card} objects.
*/ */
public static void setupPlayZone(final PlayArea p, final Card[] c) { public static void setupPlayZone(final PlayArea p, final List<Card> c) {
List<Card> tmp, diff; List<Card> tmp, diff;
tmp = new ArrayList<Card>(); tmp = new ArrayList<Card>();
for (final arcane.ui.CardPanel cpa : p.getCardPanels()) { for (final arcane.ui.CardPanel cpa : p.getCardPanels()) {
tmp.add(cpa.getGameCard()); tmp.add(cpa.getGameCard());
} }
diff = new ArrayList<Card>(tmp); diff = new ArrayList<Card>(tmp);
diff.removeAll(Arrays.asList(c)); diff.removeAll(c);
if (diff.size() == p.getCardPanels().size()) { if (diff.size() == p.getCardPanels().size()) {
p.clear(); p.clear();
} else { } else {
@@ -1112,7 +1111,7 @@ public final class GuiDisplayUtil {
p.removeCardPanel(p.getCardPanel(card.getUniqueNumber())); p.removeCardPanel(p.getCardPanel(card.getUniqueNumber()));
} }
} }
diff = new ArrayList<Card>(Arrays.asList(c)); diff = new ArrayList<Card>(c);
diff.removeAll(tmp); diff.removeAll(tmp);
arcane.ui.CardPanel toPanel = null; arcane.ui.CardPanel toPanel = null;
@@ -1364,31 +1363,31 @@ public final class GuiDisplayUtil {
} }
if (computerDevGraveyardSetup.size() > 0) { if (computerDevGraveyardSetup.size() > 0) {
AllZone.getComputerPlayer().getZone(Zone.Graveyard).setCards(computerDevGraveyardSetup.toArray()); AllZone.getComputerPlayer().getZone(Zone.Graveyard).setCards(computerDevGraveyardSetup);
} }
if (humanDevGraveyardSetup.size() > 0) { if (humanDevGraveyardSetup.size() > 0) {
AllZone.getHumanPlayer().getZone(Zone.Graveyard).setCards(humanDevGraveyardSetup.toArray()); AllZone.getHumanPlayer().getZone(Zone.Graveyard).setCards(humanDevGraveyardSetup);
} }
if (computerDevHandSetup.size() > 0) { if (computerDevHandSetup.size() > 0) {
AllZone.getComputerPlayer().getZone(Zone.Hand).setCards(computerDevHandSetup.toArray()); AllZone.getComputerPlayer().getZone(Zone.Hand).setCards(computerDevHandSetup);
} }
if (humanDevHandSetup.size() > 0) { if (humanDevHandSetup.size() > 0) {
AllZone.getHumanPlayer().getZone(Zone.Hand).setCards(humanDevHandSetup.toArray()); AllZone.getHumanPlayer().getZone(Zone.Hand).setCards(humanDevHandSetup);
} }
if (humanDevLibrarySetup.size() > 0) { if (humanDevLibrarySetup.size() > 0) {
AllZone.getHumanPlayer().getZone(Zone.Library).setCards(humanDevLibrarySetup.toArray()); AllZone.getHumanPlayer().getZone(Zone.Library).setCards(humanDevLibrarySetup);
} }
if (computerDevLibrarySetup.size() > 0) { if (computerDevLibrarySetup.size() > 0) {
AllZone.getComputerPlayer().getZone(Zone.Library).setCards(computerDevLibrarySetup.toArray()); AllZone.getComputerPlayer().getZone(Zone.Library).setCards(computerDevLibrarySetup);
} }
if (humanDevExileSetup.size() > 0) { if (humanDevExileSetup.size() > 0) {
AllZone.getHumanPlayer().getZone(Zone.Exile).setCards(humanDevExileSetup.toArray()); AllZone.getHumanPlayer().getZone(Zone.Exile).setCards(humanDevExileSetup);
} }
if (computerDevExileSetup.size() > 0) { if (computerDevExileSetup.size() > 0) {
AllZone.getComputerPlayer().getZone(Zone.Exile).setCards(computerDevExileSetup.toArray()); AllZone.getComputerPlayer().getZone(Zone.Exile).setCards(computerDevExileSetup);
} }
AllZone.getTriggerHandler().clearSuppression("ChangesZone"); AllZone.getTriggerHandler().clearSuppression("ChangesZone");

View File

@@ -107,7 +107,7 @@ interface IPlayerZone {
* @param c * @param c
* an array of {@link forge.Card} objects. * an array of {@link forge.Card} objects.
*/ */
void setCards(Card[] c); void setCards(Iterable<Card> c);
/** /**
* <p> * <p>
@@ -118,14 +118,14 @@ interface IPlayerZone {
* the filter * the filter
* @return an array of {@link forge.Card} objects. * @return an array of {@link forge.Card} objects.
*/ */
Card[] getCards(boolean filter); List<Card> getCards(boolean filter);
/** /**
* Gets the cards. * Gets the cards.
* *
* @return the cards * @return the cards
*/ */
Card[] getCards(); List<Card> getCards();
/** /**
* Gets the cards. * Gets the cards.
@@ -134,7 +134,7 @@ interface IPlayerZone {
* the n * the n
* @return the cards * @return the cards
*/ */
Card[] getCards(int n); List<Card> getCards(int n);
/** /**
* Contains. * Contains.

View File

@@ -1321,7 +1321,7 @@ public abstract class Player extends GameEntity {
* @return a CardList with all the cards currently in requested zone * @return a CardList with all the cards currently in requested zone
*/ */
public final CardList getCardsIn(final Constant.Zone zone) { public final CardList getCardsIn(final Constant.Zone zone) {
final Card[] cards = zone == Zone.Stack ? AllZone.getStackZone().getCards() : this.getZone(zone).getCards(); final List<Card> cards = zone == Zone.Stack ? AllZone.getStackZone().getCards() : this.getZone(zone).getCards();
return new CardList(cards); return new CardList(cards);
} }
@@ -1342,7 +1342,7 @@ public abstract class Player extends GameEntity {
* @return the cards include phasing in * @return the cards include phasing in
*/ */
public final CardList getCardsIncludePhasingIn(final Constant.Zone zone) { public final CardList getCardsIncludePhasingIn(final Constant.Zone zone) {
final Card[] cards = zone == Zone.Stack ? AllZone.getStackZone().getCards() : this.getZone(zone) final List<Card> cards = zone == Zone.Stack ? AllZone.getStackZone().getCards() : this.getZone(zone)
.getCards(false); .getCards(false);
return new CardList(cards); return new CardList(cards);
} }
@@ -1712,7 +1712,7 @@ public abstract class Player extends GameEntity {
return; return;
} }
final ArrayList<Object> list = new ArrayList<Object>(Arrays.asList(c)); 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);
@@ -1722,7 +1722,7 @@ public abstract class Player extends GameEntity {
Collections.shuffle(list, random); Collections.shuffle(list, random);
Collections.shuffle(list, random); Collections.shuffle(list, random);
Object o; Card o;
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
o = list.remove(random.nextInt(list.size())); o = list.remove(random.nextInt(list.size()));
list.add(random.nextInt(list.size()), o); list.add(random.nextInt(list.size()), o);
@@ -1735,8 +1735,7 @@ public abstract class Player extends GameEntity {
Collections.shuffle(list, random); Collections.shuffle(list, random);
Collections.shuffle(list, random); Collections.shuffle(list, random);
list.toArray(c); library.setCards(list);
library.setCards(c);
// Run triggers // Run triggers
final HashMap<String, Object> runParams = new HashMap<String, Object>(); final HashMap<String, Object> runParams = new HashMap<String, Object>();
@@ -2304,7 +2303,7 @@ public abstract class Player extends GameEntity {
* @return a boolean. * @return a boolean.
*/ */
public final boolean hasThreshold() { public final boolean hasThreshold() {
return this.getZone(Zone.Graveyard).getCards().length >= 7; return this.getZone(Zone.Graveyard).getCards().size() >= 7;
} }
/** /**
@@ -2315,7 +2314,7 @@ public abstract class Player extends GameEntity {
* @return a boolean. * @return a boolean.
*/ */
public final boolean hasHellbent() { public final boolean hasHellbent() {
return this.getZone(Zone.Hand).getCards().length == 0; return this.getZone(Zone.Hand).getCards().isEmpty();
} }
/** /**

View File

@@ -18,7 +18,7 @@
package forge; package forge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.List;
import forge.Constant.Zone; import forge.Constant.Zone;
import forge.card.spellability.Ability; import forge.card.spellability.Ability;
@@ -349,25 +349,20 @@ public class PlayerZoneComesIntoPlay extends DefaultPlayerZone {
* @see forge.DefaultPlayerZone#getCards(boolean) * @see forge.DefaultPlayerZone#getCards(boolean)
*/ */
@Override @Override
public final Card[] getCards(final boolean filter) { public final List<Card> getCards(final boolean filter) {
// Battlefield filters out Phased Out cards by default. Needs to call // Battlefield filters out Phased Out cards by default. Needs to call
// getCards(false) to get Phased Out cards // getCards(false) to get Phased Out cards
Card[] c;
if (!filter) { if (!filter)
c = new Card[this.getCardList().size()]; return new ArrayList<Card>(this.getCardList());
this.getCardList().toArray(c);
} else {
final Iterator<Card> itr = this.getCardList().iterator();
final ArrayList<Card> list = new ArrayList<Card>(); final ArrayList<Card> list = new ArrayList<Card>();
while (itr.hasNext()) { for(Card crd : this.getCardList())
final Card crd = itr.next(); {
if (!crd.isPhasedOut()) { if (!crd.isPhasedOut()) {
list.add(crd); list.add(crd);
} }
} }
c = new Card[list.size()]; return list;
list.toArray(c);
}
return c;
} }
} }

View File

@@ -1230,7 +1230,7 @@ public class AbilityFactoryZoneAffecting {
: CardFactoryUtil.xCount(source, source.getSVar(amountString)); : CardFactoryUtil.xCount(source, source.getSVar(amountString));
dPHand = AbilityFactoryReveal.getRevealedList(p, dPHand, amount); dPHand = AbilityFactoryReveal.getRevealedList(p, dPHand, amount);
} }
CardList dPChHand = new CardList(dPHand.toArray()); CardList dPChHand = new CardList(dPHand);
if (params.containsKey("DiscardValid")) { // Restrict card choices if (params.containsKey("DiscardValid")) { // Restrict card choices
final String[] dValid = params.get("DiscardValid").split(","); final String[] dValid = params.get("DiscardValid").split(",");
dPChHand = dPHand.getValidCards(dValid, source.getController(), source); dPChHand = dPHand.getValidCards(dValid, source.getController(), source);

View File

@@ -404,7 +404,7 @@ public class CardFactoryCreatures {
} }
}); });
CardList list = new CardList(art.toArray()); CardList list = new CardList(art);
list = list.filter(new CardListFilter() { list = list.filter(new CardListFilter() {
@Override @Override
public boolean addCard(final Card c) { public boolean addCard(final Card c) {

View File

@@ -280,7 +280,7 @@ class CardFactoryLands {
if (this.player.isComputer()) { if (this.player.isComputer()) {
if (land.size() > 0) { if (land.size() > 0) {
CardList tappedLand = new CardList(land.toArray()); CardList tappedLand = new CardList(land);
tappedLand = tappedLand.filter(CardListFilter.TAPPED); tappedLand = tappedLand.filter(CardListFilter.TAPPED);
// if any are tapped, sacrifice it // if any are tapped, sacrifice it
// else sacrifice random // else sacrifice random
@@ -366,7 +366,7 @@ class CardFactoryLands {
if (this.player.isComputer()) { if (this.player.isComputer()) {
if (plains.size() > 1) { if (plains.size() > 1) {
CardList tappedPlains = new CardList(plains.toArray()); CardList tappedPlains = new CardList(plains);
tappedPlains = tappedPlains.getType("Basic"); tappedPlains = tappedPlains.getType("Basic");
for (final Card c : tappedPlains) { for (final Card c : tappedPlains) {
Singletons.getModel().getGameAction().sacrifice(c); Singletons.getModel().getGameAction().sacrifice(c);
@@ -653,7 +653,7 @@ class CardFactoryLands {
if (player.isComputer()) { if (player.isComputer()) {
if (land.size() > 0) { if (land.size() > 0) {
CardList tappedLand = new CardList(land.toArray()); CardList tappedLand = new CardList(land);
tappedLand = tappedLand.filter(CardListFilter.TAPPED); tappedLand = tappedLand.filter(CardListFilter.TAPPED);
if (tappedLand.size() > 0) { if (tappedLand.size() > 0) {
Singletons.getModel().getGameAction().moveToHand(CardFactoryUtil.getWorstLand(tappedLand)); Singletons.getModel().getGameAction().moveToHand(CardFactoryUtil.getWorstLand(tappedLand));

View File

@@ -24,7 +24,6 @@ import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter; import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
@@ -289,7 +288,7 @@ public class ControlField {
} }
protected Iterable<Card> getCardsAsIterable() { protected Iterable<Card> getCardsAsIterable() {
return new ImmutableIterableFrom<Card>(Arrays.asList(this.zone.getCards())); return new ImmutableIterableFrom<Card>(this.zone.getCards());
} }
protected void doAction(final Card c) { protected void doAction(final Card c) {
@@ -318,8 +317,7 @@ public class ControlField {
@Override @Override
public void update(final Observable a, final Object b) { public void update(final Observable a, final Object b) {
final PlayerZone pZone = (PlayerZone) a; final PlayerZone pZone = (PlayerZone) a;
final Card[] c = pZone.getCards(false); GuiDisplayUtil.setupPlayZone(ControlField.this.view.getTabletop(), pZone.getCards(false));
GuiDisplayUtil.setupPlayZone(ControlField.this.view.getTabletop(), c);
} }
}; };
} }

View File

@@ -25,7 +25,6 @@ import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter; import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseMotionListener; import java.awt.event.MouseMotionListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
@@ -103,7 +102,7 @@ public class ControlHand {
final Rectangle rctLibraryLabel = Singletons.getControl() final Rectangle rctLibraryLabel = Singletons.getControl()
.getControlMatch().getFieldControls().get(1) .getControlMatch().getFieldControls().get(1)
.getView().getLblLibrary().getBounds(); .getView().getLblLibrary().getBounds();
final Card[] c = pZone.getCards(); final List<Card> c = pZone.getCards();
// Animation starts from the library label. // Animation starts from the library label.
// This check prevents animation running if label hasn't been realised yet. // This check prevents animation running if label hasn't been realised yet.
@@ -117,7 +116,7 @@ public class ControlHand {
tmp.add(cpa.getGameCard()); tmp.add(cpa.getGameCard());
} }
diff = new ArrayList<Card>(tmp); diff = new ArrayList<Card>(tmp);
diff.removeAll(Arrays.asList(c)); diff.removeAll(c);
if (diff.size() == p.getCardPanels().size()) { if (diff.size() == p.getCardPanels().size()) {
p.clear(); p.clear();
} else { } else {
@@ -125,7 +124,7 @@ public class ControlHand {
p.removeCardPanel(p.getCardPanel(card.getUniqueNumber())); p.removeCardPanel(p.getCardPanel(card.getUniqueNumber()));
} }
} }
diff = new ArrayList<Card>(Arrays.asList(c)); diff = new ArrayList<Card>(c);
diff.removeAll(tmp); diff.removeAll(tmp);
JLayeredPane layeredPane = Singletons.getView().getFrame().getLayeredPane(); JLayeredPane layeredPane = Singletons.getView().getFrame().getLayeredPane();

View File

@@ -1,6 +1,7 @@
package forge.game; package forge.game;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
@@ -256,13 +257,12 @@ public class GameNew {
final boolean smoothLand = Constant.Runtime.SMOOTH[0]; final boolean smoothLand = Constant.Runtime.SMOOTH[0];
if (smoothLand) { if (smoothLand) {
final Card[] c1 = GameNew.smoothComputerManaCurve(AllZone.getComputerPlayer().getCardsIn(Zone.Library) final Iterable<Card> c1 = GameNew.smoothComputerManaCurve(AllZone.getComputerPlayer().getCardsIn(Zone.Library));
.toArray());
AllZone.getComputerPlayer().getZone(Zone.Library).setCards(c1); AllZone.getComputerPlayer().getZone(Zone.Library).setCards(c1);
} else { } else {
// WTF? (it was so before refactor) // WTF? (it was so before refactor)
AllZone.getComputerPlayer().getZone(Zone.Library) AllZone.getComputerPlayer().getZone(Zone.Library)
.setCards(AllZone.getComputerPlayer().getCardsIn(Zone.Library).toArray()); .setCards(AllZone.getComputerPlayer().getCardsIn(Zone.Library));
AllZone.getComputerPlayer().shuffle(); AllZone.getComputerPlayer().shuffle();
} }
@@ -363,7 +363,7 @@ public class GameNew {
* an array of {@link forge.Card} objects. * an array of {@link forge.Card} objects.
* @return an array of {@link forge.Card} objects. * @return an array of {@link forge.Card} objects.
*/ */
private static Card[] smoothComputerManaCurve(final Card[] in) { private static Iterable<Card> smoothComputerManaCurve(final Iterable<Card> in) {
final CardList library = new CardList(in); final CardList library = new CardList(in);
library.shuffle(); library.shuffle();
@@ -404,7 +404,7 @@ public class GameNew {
System.out.println(library.get(i)); System.out.println(library.get(i));
} }
return library.toArray(); return Arrays.asList(library.toArray());
} // 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

@@ -1,6 +1,7 @@
package forge; package forge;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
@@ -265,7 +266,7 @@ public class RunTest {
c2.setUniqueNumber(2); c2.setUniqueNumber(2);
// test CardList // test CardList
final CardList cardList = new CardList(new Card[] { c, c2 }); final CardList cardList = new CardList(Arrays.asList(new Card[] { c, c2 }));
this.check("111", cardList.contains(c)); this.check("111", cardList.contains(c));
this.check("112", cardList.contains(c2)); this.check("112", cardList.contains(c2));
this.check("113", cardList.containsName(c)); this.check("113", cardList.containsName(c));