Changed some public final static arrays into guava's ImmutableList

in Card class changed members to be just List<T> instances (instead of ArrayList)
This commit is contained in:
Maxmtg
2013-03-15 21:51:52 +00:00
parent 5f0e660d18
commit 9af799a88e
12 changed files with 51 additions and 47 deletions

View File

@@ -31,6 +31,7 @@ import java.util.Set;
import java.util.TreeMap;
import com.esotericsoftware.minlog.Log;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import forge.CardPredicates.Presets;
@@ -207,28 +208,28 @@ public class Card extends GameEntity implements Comparable<Card> {
private String miracleCost = null;
private String chosenType = "";
// private String chosenColor = "";
private ArrayList<String> chosenColor = new ArrayList<String>();
private List<String> chosenColor = new ArrayList<String>();
private String namedCard = "";
private int chosenNumber;
private Player chosenPlayer;
private ArrayList<Card> chosenCard = new ArrayList<Card>();
private List<Card> chosenCard = new ArrayList<Card>();
private Card cloneOrigin = null;
private final ArrayList<Card> clones = new ArrayList<Card>();
private final ArrayList<Card> gainControlTargets = new ArrayList<Card>();
private final ArrayList<Command> gainControlReleaseCommands = new ArrayList<Command>();
private final List<Card> clones = new ArrayList<Card>();
private final List<Card> gainControlTargets = new ArrayList<Card>();
private final List<Command> gainControlReleaseCommands = new ArrayList<Command>();
private final ArrayList<AbilityTriggered> zcTriggers = new ArrayList<AbilityTriggered>();
private final ArrayList<Command> equipCommandList = new ArrayList<Command>();
private final ArrayList<Command> unEquipCommandList = new ArrayList<Command>();
private final ArrayList<Command> enchantCommandList = new ArrayList<Command>();
private final ArrayList<Command> unEnchantCommandList = new ArrayList<Command>();
private final ArrayList<Command> untapCommandList = new ArrayList<Command>();
private final ArrayList<Command> changeControllerCommandList = new ArrayList<Command>();
private final List<AbilityTriggered> zcTriggers = new ArrayList<AbilityTriggered>();
private final List<Command> equipCommandList = new ArrayList<Command>();
private final List<Command> unEquipCommandList = new ArrayList<Command>();
private final List<Command> enchantCommandList = new ArrayList<Command>();
private final List<Command> unEnchantCommandList = new ArrayList<Command>();
private final List<Command> untapCommandList = new ArrayList<Command>();
private final List<Command> changeControllerCommandList = new ArrayList<Command>();
private static String[] storableSVars = { "ChosenX", "ChosenY" };
private final static ImmutableList<String> storableSVars = ImmutableList.of("ChosenX", "ChosenY" );
private final ArrayList<Card> hauntedBy = new ArrayList<Card>();
private final List<Card> hauntedBy = new ArrayList<Card>();
private Card haunting = null;
private Card effectSource = null;
@@ -565,7 +566,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*
* @return a String array
*/
public static String[] getStorableSVars() {
public static List<String> getStorableSVars() {
return Card.storableSVars;
}
@@ -1162,7 +1163,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*
* @return a {@link java.util.ArrayList} object.
*/
public final ArrayList<Card> getClones() {
public final List<Card> getClones() {
return this.clones;
}
@@ -1174,7 +1175,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @param c
* a {@link java.util.ArrayList} object.
*/
public final void setClones(final ArrayList<Card> c) {
public final void setClones(final Collection<Card> c) {
this.clones.clear();
this.clones.addAll(c);
}
@@ -1912,7 +1913,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*
* @return an ArrayList<String> object.
*/
public final ArrayList<String> getChosenColor() {
public final List<String> getChosenColor() {
return this.chosenColor;
}
@@ -1924,7 +1925,7 @@ public class Card extends GameEntity implements Comparable<Card> {
* @param s
* an ArrayList<String> object.
*/
public final void setChosenColor(final ArrayList<String> s) {
public final void setChosenColor(final List<String> s) {
this.chosenColor = s;
}
@@ -1935,7 +1936,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*
* @return an ArrayList<Card> object.
*/
public final ArrayList<Card> getChosenCard() {
public final List<Card> getChosenCard() {
return this.chosenCard;
}
@@ -2005,7 +2006,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*
* @return a list of cards this card has gained control of
*/
public final ArrayList<Card> getGainControlTargets() {
public final List<Card> getGainControlTargets() {
return this.gainControlTargets;
}
@@ -2039,7 +2040,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*
* @return a {@link java.util.ArrayList} object.
*/
public final ArrayList<Command> getGainControlReleaseCommands() {
public final List<Command> getGainControlReleaseCommands() {
return this.gainControlReleaseCommands;
}
@@ -6003,7 +6004,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*/
@Override
public final boolean hasKeyword(final String keyword) {
String kw = new String(keyword);
String kw = keyword;
if (kw.startsWith("HIDDEN")) {
kw = kw.substring(7);
}
@@ -8646,7 +8647,7 @@ public class Card extends GameEntity implements Comparable<Card> {
*
* @return the haunted by
*/
public final ArrayList<Card> getHauntedBy() {
public final List<Card> getHauntedBy() {
return this.hauntedBy;
}

View File

@@ -226,7 +226,7 @@ public final class CardUtil {
* a {@link java.util.ArrayList} object.
* @return a {@link java.lang.String} object.
*/
public static String getShortColorsString(final ArrayList<String> colors) {
public static String getShortColorsString(final Iterable<String> colors) {
String colorDesc = "";
for (final String col : colors) {
if (col.equalsIgnoreCase("White")) {

View File

@@ -22,6 +22,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.google.common.collect.ImmutableList;
import forge.properties.ForgeProps;
import forge.properties.NewConstants;
@@ -85,10 +87,10 @@ public final class Constant {
public static final String COLORLESS = "colorless";
// color order "wubrg"
/** The Colors. */
public static final String[] COLORS = { Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN, Color.COLORLESS };
public static final ImmutableList<String> COLORS = ImmutableList.of(Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN, Color.COLORLESS);
/** The only colors. */
public static final String[] ONLY_COLORS = { Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN };
public static final ImmutableList<String> ONLY_COLORS = ImmutableList.of(Color.WHITE, Color.BLUE, Color.BLACK, Color.RED, Color.GREEN);
/** The Snow. */
public static final String SNOW = "snow";

View File

@@ -980,7 +980,7 @@ public class AbilityUtils {
// Replace AnyColor with the 5 colors
if (choices.contains("AnyColor")) {
gains.addAll(Arrays.asList(Constant.Color.ONLY_COLORS));
gains.addAll(Constant.Color.ONLY_COLORS);
choices = choices.replaceAll("AnyColor,?", "");
}
// Add any remaining choices

View File

@@ -1,7 +1,6 @@
package forge.card.ability.ai;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.google.common.base.Predicate;
@@ -25,7 +24,7 @@ import forge.game.zone.ZoneType;
public class ProtectAi extends SpellAbilityAi {
private static boolean hasProtectionFrom(final Card card, final String color) {
final ArrayList<String> onlyColors = new ArrayList<String>(Arrays.asList(Constant.Color.ONLY_COLORS));
final ArrayList<String> onlyColors = new ArrayList<String>(Constant.Color.ONLY_COLORS);
// make sure we have a valid color
if (!onlyColors.contains(color)) {

View File

@@ -3,6 +3,8 @@ package forge.card.ability.effects;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.ImmutableList;
import forge.Card;
import forge.CardLists;
import forge.CardPredicates;
@@ -46,8 +48,8 @@ public class ChooseColorEffect extends SpellAbilityEffect {
if ((tgt == null) || p.canBeTargetedBy(sa)) {
if (sa.getActivatingPlayer().isHuman()) {
if (sa.hasParam("OrColors")) {
String[] choices = Constant.Color.ONLY_COLORS;
final List<String> o = GuiChoose.getChoices("Choose a color or colors", 1, choices.length, choices);
ImmutableList<String> choices = Constant.Color.ONLY_COLORS;
final List<String> o = GuiChoose.getChoices("Choose a color or colors", 1, choices.size(), choices);
card.setChosenColor(new ArrayList<String>(o));
} else if (sa.hasParam("TwoColors")) {
final List<String> o = GuiChoose.getChoices("Choose two colors", 2, 2, Constant.Color.ONLY_COLORS);

View File

@@ -1,5 +1,6 @@
package forge.card.ability.effects;
import java.util.ArrayList;
import java.util.List;
import forge.Card;
@@ -47,12 +48,12 @@ public class ManaEffect extends SpellAbilityEffect {
//String colorsNeeded = abMana.getExpressChoice();
String[] colorsProduced = abMana.getComboColors().split(" ");
final StringBuilder choiceString = new StringBuilder();
String[] colorMenu = null;
List<String> colorMenu = null;
if (!abMana.isAnyMana()) {
colorMenu = new String[colorsProduced.length];
colorMenu = new ArrayList<String>();
//loop through colors to make menu
for (int nColor = 0; nColor < colorsProduced.length; nColor++) {
colorMenu[nColor] = forge.card.MagicColor.toLongString(colorsProduced[nColor]);
colorMenu.add(forge.card.MagicColor.toLongString(colorsProduced[nColor]));
}
}
else {
@@ -113,12 +114,12 @@ public class ManaEffect extends SpellAbilityEffect {
choice = colorsNeeded;
}
else {
String[] colorMenu = null;
List<String> colorMenu = null;
if (colorsNeeded.length() > 1 && colorsNeeded.length() < 5) {
colorMenu = new String[colorsNeeded.length()];
colorMenu = new ArrayList<String>();
//loop through colors to make menu
for (int nChar = 0; nChar < colorsNeeded.length(); nChar++) {
colorMenu[nChar] = forge.card.MagicColor.toLongString(colorsNeeded.substring(nChar, nChar + 1));
colorMenu.add(forge.card.MagicColor.toLongString(colorsNeeded.substring(nChar, nChar + 1)));
}
}
else {

View File

@@ -337,10 +337,10 @@ public class ManaPool {
totalMana += normalMana[i];
totalMana += snowMana[i];
if (normalMana[i] > 0) {
alChoice.add(Constant.Color.COLORS[i] + "(" + normalMana[i] + ")");
alChoice.add(Constant.Color.COLORS.get(i) + "(" + normalMana[i] + ")");
}
if (snowMana[i] > 0) {
alChoice.add("{S}" + Constant.Color.COLORS[i] + "(" + snowMana[i] + ")");
alChoice.add("{S}" + Constant.Color.COLORS.get(i) + "(" + snowMana[i] + ")");
}
}

View File

@@ -145,7 +145,7 @@ public class StaticAbilityContinuous {
if (params.containsKey("AddKeyword")) {
addKeywords = params.get("AddKeyword").split(" & ");
final ArrayList<String> chosencolors = hostCard.getChosenColor();
final List<String> chosencolors = hostCard.getChosenColor();
for (final String color : chosencolors) {
for (int w = 0; w < addKeywords.length; w++) {
addKeywords[w] = addKeywords[w].replaceAll("ChosenColor", color.substring(0, 1).toUpperCase().concat(color.substring(1, color.length())));

View File

@@ -980,7 +980,7 @@ public final class GameActionUtil {
for (final Card oldman : list) {
if (!oldman.getGainControlTargets().isEmpty()) {
if (oldman.getNetAttack() < oldman.getGainControlTargets().get(0).getNetAttack()) {
final ArrayList<Command> coms = oldman.getGainControlReleaseCommands();
final List<Command> coms = oldman.getGainControlReleaseCommands();
for (int i = 0; i < coms.size(); i++) {
coms.get(i).execute();
}

View File

@@ -60,7 +60,6 @@ public class SealedDeck extends LimitedDeck {
int green = Iterables.size(Iterables.filter(rules, CardRulesPredicates.Presets.IS_GREEN));
final int[] colorCounts = { white, blue, black, red, green };
final String[] colors = Constant.Color.ONLY_COLORS;
int[] countsCopy = Arrays.copyOf(colorCounts, 5);
Arrays.sort(countsCopy);
@@ -68,9 +67,9 @@ public class SealedDeck extends LimitedDeck {
List<String> secondColors = new ArrayList<String>();
for (int i = 0; i < 5; i++) {
if (countsCopy[4] == colorCounts[i]) {
maxColors.add(colors[i]);
maxColors.add(Constant.Color.ONLY_COLORS.get(i));
} else if (countsCopy[3] == colorCounts[i]) {
secondColors.add(colors[i]);
secondColors.add(Constant.Color.ONLY_COLORS.get(i));
}
}

View File

@@ -150,7 +150,7 @@ public class Untap extends Phase {
String prompt = "Untap " + c.getName() + "?";
boolean defaultChoice = true;
if (c.getGainControlTargets().size() > 0) {
final ArrayList<Card> targets = c.getGainControlTargets();
final List<Card> targets = c.getGainControlTargets();
prompt += "\r\n" + c + " is controlling: ";
for (final Card target : targets) {
prompt += target;
@@ -167,7 +167,7 @@ public class Untap extends Phase {
// leave it tapped
// if not, untap it
if (c.getGainControlTargets().size() > 0) {
final ArrayList<Card> targets = c.getGainControlTargets();
final List<Card> targets = c.getGainControlTargets();
boolean untap = true;
for (final Card target : targets) {
if (target.isInPlay()) {