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.Comparator;
import java.util.Iterator;
import java.util.List;
import com.google.code.jyield.Generator;
import com.google.code.jyield.Yieldable;
@@ -69,8 +67,8 @@ public class CardList implements Iterable<Card> {
* @param c
* a {@link forge.Card} object.
*/
public CardList(final Card... c) {
this.addAll(c);
public CardList(final Card c) {
this.add(c);
}
/**
@@ -81,23 +79,10 @@ public class CardList implements Iterable<Card> {
* @param al
* a {@link java.util.ArrayList} object.
*/
public CardList(final List<Card> al) {
public CardList(final Iterable<Card> 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.
*

View File

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

View File

@@ -19,6 +19,7 @@ package forge;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -2351,7 +2352,7 @@ public class CombatUtil {
// Loop through Defenders
// Append Defending Player/Planeswalker
final Combat combat = AllZone.getCombat();
final ArrayList<Object> defenders = combat.getDefenders();
final List<GameEntity> defenders = combat.getDefenders();
final CardList[] attackers = combat.sortAttackerByDefender();
// Not a big fan of the triple nested loop here
@@ -2384,7 +2385,7 @@ public class CombatUtil {
// Loop through Defenders
// Append Defending Player/Planeswalker
final Combat combat = AllZone.getCombat();
final ArrayList<Object> defenders = combat.getDefenders();
final List<GameEntity> defenders = combat.getDefenders();
final CardList[] attackers = combat.sortAttackerByDefender();
// Not a big fan of the triple nested loop here
@@ -2425,7 +2426,7 @@ public class CombatUtil {
// Loop through Defenders
// Append Defending Player/Planeswalker
final ArrayList<Object> defenders = AllZone.getCombat().getDefenders();
final List<GameEntity> defenders = AllZone.getCombat().getDefenders();
final CardList[] attackers = AllZone.getCombat().sortAttackerByDefender();
// 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.HashMap;
import java.util.List;
import java.util.Random;
import forge.Constant.Zone;
@@ -51,20 +52,6 @@ public class ComputerUtilAttack {
private int aiAggression = 0; // added by Masher, how aggressive the ai
// 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>
* Constructor for ComputerUtil_Attack2.
@@ -76,12 +63,12 @@ public class ComputerUtilAttack {
* a {@link forge.CardList} object.
*/
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.computerList = new CardList(possibleAttackers.toArray());
this.computerList = new CardList(possibleAttackers);
this.computerList = this.computerList.getType("Creature");
this.playerCreatures = new CardList(possibleBlockers.toArray());
this.playerCreatures = new CardList(possibleBlockers);
this.playerCreatures = this.playerCreatures.getType("Creature");
this.attackers = this.getPossibleAttackers(possibleAttackers);
@@ -169,7 +156,7 @@ public class ComputerUtilAttack {
* @return a {@link forge.CardList} object.
*/
public final CardList getPossibleAttackers(final CardList in) {
CardList list = new CardList(in.toArray());
CardList list = new CardList(in);
list = list.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
@@ -191,8 +178,8 @@ public class ComputerUtilAttack {
* @return a {@link forge.CardList} object.
*/
public final CardList getPossibleBlockers(final CardList blockers, final CardList attackers) {
CardList possibleBlockers = new CardList(blockers.toArray());
final CardList attackerList = new CardList(attackers.toArray());
CardList possibleBlockers = new CardList(blockers);
final CardList attackerList = new CardList(attackers);
possibleBlockers = possibleBlockers.filter(new CardListFilter() {
@Override
public boolean addCard(final Card c) {
@@ -225,7 +212,7 @@ public class ComputerUtilAttack {
* @return a {@link forge.CardList} object.
*/
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);
int blockersNeeded = attackers.size();
@@ -343,8 +330,8 @@ public class ComputerUtilAttack {
CardListUtil.sortAttack(this.attackers);
final CardList remainingAttackers = new CardList(this.attackers.toArray());
final CardList blockableAttackers = new CardList(this.attackers.toArray());
final CardList remainingAttackers = new CardList(this.attackers);
final CardList blockableAttackers = new CardList(this.attackers);
final Player human = AllZone.getHumanPlayer();
final Player computer = AllZone.getComputerPlayer();
@@ -386,7 +373,7 @@ public class ComputerUtilAttack {
public final void chooseDefender(final Combat c, final boolean bAssault) {
// TODO split attackers to different planeswalker/human
// 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
// would be better to determine more individually
@@ -394,7 +381,7 @@ public class ComputerUtilAttack {
final Object entity = AllZone.getComputerPlayer().getMustAttackEntity();
if (null != entity) {
final ArrayList<Object> defenders = AllZone.getCombat().getDefenders();
final List<GameEntity> defenders = AllZone.getCombat().getDefenders();
n = defenders.indexOf(entity);
if (-1 == n) {
System.out.println("getMustAttackEntity() returned something not in defenders.");
@@ -438,7 +425,7 @@ public class ComputerUtilAttack {
// Determine who will be attacked
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
for (final Card attacker : this.attackers) {

View File

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

View File

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

View File

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

View File

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

View File

@@ -1321,7 +1321,7 @@ public abstract class Player extends GameEntity {
* @return a CardList with all the cards currently in requested 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);
}
@@ -1342,7 +1342,7 @@ public abstract class Player extends GameEntity {
* @return the cards include phasing in
*/
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);
return new CardList(cards);
}
@@ -1712,7 +1712,7 @@ public abstract class Player extends GameEntity {
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
final Random random = MyRandom.getRandom();
Collections.shuffle(list, random);
@@ -1722,7 +1722,7 @@ public abstract class Player extends GameEntity {
Collections.shuffle(list, random);
Collections.shuffle(list, random);
Object o;
Card o;
for (int i = 0; i < list.size(); i++) {
o = list.remove(random.nextInt(list.size()));
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);
list.toArray(c);
library.setCards(c);
library.setCards(list);
// Run triggers
final HashMap<String, Object> runParams = new HashMap<String, Object>();
@@ -2304,7 +2303,7 @@ public abstract class Player extends GameEntity {
* @return a boolean.
*/
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.
*/
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;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import forge.Constant.Zone;
import forge.card.spellability.Ability;
@@ -349,25 +349,20 @@ public class PlayerZoneComesIntoPlay extends DefaultPlayerZone {
* @see forge.DefaultPlayerZone#getCards(boolean)
*/
@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
// getCards(false) to get Phased Out cards
Card[] c;
if (!filter) {
c = new Card[this.getCardList().size()];
this.getCardList().toArray(c);
} else {
final Iterator<Card> itr = this.getCardList().iterator();
final ArrayList<Card> list = new ArrayList<Card>();
while (itr.hasNext()) {
final Card crd = itr.next();
if (!crd.isPhasedOut()) {
list.add(crd);
}
if (!filter)
return new ArrayList<Card>(this.getCardList());
final ArrayList<Card> list = new ArrayList<Card>();
for(Card crd : this.getCardList())
{
if (!crd.isPhasedOut()) {
list.add(crd);
}
c = new Card[list.size()];
list.toArray(c);
}
return c;
return list;
}
}

View File

@@ -1230,7 +1230,7 @@ public class AbilityFactoryZoneAffecting {
: CardFactoryUtil.xCount(source, source.getSVar(amountString));
dPHand = AbilityFactoryReveal.getRevealedList(p, dPHand, amount);
}
CardList dPChHand = new CardList(dPHand.toArray());
CardList dPChHand = new CardList(dPHand);
if (params.containsKey("DiscardValid")) { // Restrict card choices
final String[] dValid = params.get("DiscardValid").split(",");
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() {
@Override
public boolean addCard(final Card c) {

View File

@@ -280,7 +280,7 @@ class CardFactoryLands {
if (this.player.isComputer()) {
if (land.size() > 0) {
CardList tappedLand = new CardList(land.toArray());
CardList tappedLand = new CardList(land);
tappedLand = tappedLand.filter(CardListFilter.TAPPED);
// if any are tapped, sacrifice it
// else sacrifice random
@@ -366,7 +366,7 @@ class CardFactoryLands {
if (this.player.isComputer()) {
if (plains.size() > 1) {
CardList tappedPlains = new CardList(plains.toArray());
CardList tappedPlains = new CardList(plains);
tappedPlains = tappedPlains.getType("Basic");
for (final Card c : tappedPlains) {
Singletons.getModel().getGameAction().sacrifice(c);
@@ -653,7 +653,7 @@ class CardFactoryLands {
if (player.isComputer()) {
if (land.size() > 0) {
CardList tappedLand = new CardList(land.toArray());
CardList tappedLand = new CardList(land);
tappedLand = tappedLand.filter(CardListFilter.TAPPED);
if (tappedLand.size() > 0) {
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.MouseMotionListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Observable;
import java.util.Observer;
@@ -289,7 +288,7 @@ public class ControlField {
}
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) {
@@ -318,8 +317,7 @@ public class ControlField {
@Override
public void update(final Observable a, final Object b) {
final PlayerZone pZone = (PlayerZone) a;
final Card[] c = pZone.getCards(false);
GuiDisplayUtil.setupPlayZone(ControlField.this.view.getTabletop(), c);
GuiDisplayUtil.setupPlayZone(ControlField.this.view.getTabletop(), pZone.getCards(false));
}
};
}

View File

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

View File

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

View File

@@ -1,6 +1,7 @@
package forge;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -265,7 +266,7 @@ public class RunTest {
c2.setUniqueNumber(2);
// 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("112", cardList.contains(c2));
this.check("113", cardList.containsName(c));