From c6fd382ae6e1d4fb5858df885cee53c834827427 Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Sun, 17 Feb 2013 13:41:12 +0000 Subject: [PATCH] Cleaning up damage dealt by myk's enforcement of sorting info GuiChoose lists --- src/main/java/forge/Card.java | 27 ------------- .../ability/effects/ChooseGenericEffect.java | 2 +- .../ability/effects/ManaReflectedEffect.java | 6 +-- .../card/replacement/ReplacementEffect.java | 23 +---------- .../forge/card/spellability/SpellAbility.java | 23 +---------- src/main/java/forge/gui/GuiChoose.java | 39 +++++-------------- 6 files changed, 16 insertions(+), 104 deletions(-) diff --git a/src/main/java/forge/Card.java b/src/main/java/forge/Card.java index 9715880b7ca..e61cb118bfb 100644 --- a/src/main/java/forge/Card.java +++ b/src/main/java/forge/Card.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Comparator; import java.util.EnumMap; import java.util.HashMap; import java.util.Iterator; @@ -5643,32 +5642,6 @@ public class Card extends GameEntity implements Comparable { return 0; } } - - private static Comparator _nameComparator = new Comparator() { - @Override - public int compare(Card me, Card other) { - if (me == other) { - return 0; - } - if (null == other) { - return 1; - } - if (me.getName() == other.getName()) { - return 0; - } - if (null == me.getName()) { - return -1; - } - return me.getName().compareTo(other.getName()); - } - }; - - /** - * For sorting lists of cards by name instead of by id - */ - public static final Comparator getNameComparator() { - return _nameComparator; - } /** {@inheritDoc} */ @Override diff --git a/src/main/java/forge/card/ability/effects/ChooseGenericEffect.java b/src/main/java/forge/card/ability/effects/ChooseGenericEffect.java index 7005d2d5360..a84fe96d718 100644 --- a/src/main/java/forge/card/ability/effects/ChooseGenericEffect.java +++ b/src/main/java/forge/card/ability/effects/ChooseGenericEffect.java @@ -51,7 +51,7 @@ public class ChooseGenericEffect extends SpellEffect { } SpellAbility chosenSA = null; if (p.isHuman()) { - String choice = GuiChoose.one("Choose one", Lists.newArrayList(choices.values())); + String choice = GuiChoose.one("Choose one", choices.values()); chosenSA = AbilityFactory.getAbility(host.getSVar(choices.inverse().get(choice)), host); } else { //Computer AI chosenSA = AbilityFactory.getAbility(host.getSVar(sa.getParam("Choices").split(",")[0]), host); diff --git a/src/main/java/forge/card/ability/effects/ManaReflectedEffect.java b/src/main/java/forge/card/ability/effects/ManaReflectedEffect.java index 1a48e32431d..780d901ae57 100644 --- a/src/main/java/forge/card/ability/effects/ManaReflectedEffect.java +++ b/src/main/java/forge/card/ability/effects/ManaReflectedEffect.java @@ -1,6 +1,7 @@ package forge.card.ability.effects; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -26,8 +27,7 @@ public class ManaReflectedEffect extends SpellEffect { AbilityManaPart ma = sa.getManaPart(); sa.setUndoable(sa.isAbility() && sa.isUndoable()); - final List colors = new ArrayList( - CardUtil.getReflectableManaColors(sa, sa, new HashSet(), new ArrayList())); + final Collection colors = CardUtil.getReflectableManaColors(sa, sa, new HashSet(), new ArrayList()); final List tgtPlayers = getTargetPlayers(sa); for (final Player player : tgtPlayers) { @@ -62,7 +62,7 @@ public class ManaReflectedEffect extends SpellEffect { * a {@link forge.game.player.Player} object. * @return a {@link java.lang.String} object. */ - private static String generatedReflectedMana(final SpellAbility sa, final List colors, final Player player) { + private static String generatedReflectedMana(final SpellAbility sa, final Collection colors, final Player player) { // Calculate generated mana here for stack description and resolving final int amount = sa.hasParam("Amount") ? AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("Amount"), sa) : 1; diff --git a/src/main/java/forge/card/replacement/ReplacementEffect.java b/src/main/java/forge/card/replacement/ReplacementEffect.java index ddb5d70bc0a..bd15431911d 100644 --- a/src/main/java/forge/card/replacement/ReplacementEffect.java +++ b/src/main/java/forge/card/replacement/ReplacementEffect.java @@ -38,7 +38,7 @@ import forge.util.Expressions; * TODO: Write javadoc for this type. * */ -public abstract class ReplacementEffect extends TriggerReplacementBase implements Comparable { +public abstract class ReplacementEffect extends TriggerReplacementBase { private ReplacementLayer layer = ReplacementLayer.None; @@ -438,25 +438,4 @@ public abstract class ReplacementEffect extends TriggerReplacementBase implement public void setLayer(ReplacementLayer layer0) { this.layer = layer0; } - - /* (non-Javadoc) - * used only for ordering, just sort by card - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ - @Override - public int compareTo(ReplacementEffect other) { - if (null == other) { - return 1; - } - if (hostCard == other.hostCard) { - return 0; - } - if (null == hostCard) { - return -1; - } - if (null == other.hostCard) { - return 1; - } - return hostCard.getName().compareTo(other.hostCard.getName()); - } } diff --git a/src/main/java/forge/card/spellability/SpellAbility.java b/src/main/java/forge/card/spellability/SpellAbility.java index 0cca398906f..d9737016c46 100644 --- a/src/main/java/forge/card/spellability/SpellAbility.java +++ b/src/main/java/forge/card/spellability/SpellAbility.java @@ -47,7 +47,7 @@ import forge.game.player.Player; * @author Forge * @version $Id$ */ -public abstract class SpellAbility implements ISpellAbility, Comparable { +public abstract class SpellAbility implements ISpellAbility { // choices for constructor isPermanent argument private String description = ""; @@ -1781,25 +1781,4 @@ public abstract class SpellAbility implements ISpellAbility, Comparable - * is automatically inferred. - * @param message - * a {@link java.lang.String} object. - * @param choices - * a T object. - * @return null if choices is missing, empty, or if the users' choices are - * empty; otherwise, returns the first item in the List returned by - * getChoices. - * @see #getChoices(String, int, int, Object...) - */ + // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine public static T sortedOneOrNone(final String message, final T[] choices, Comparator comparer) { if ((choices == null) || (choices.length == 0)) { return null; @@ -210,6 +197,7 @@ public class GuiChoose { return choice.isEmpty() ? null : choice.get(0); } // getChoiceOptional(String,T...) + // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine public static T sortedOneOrNone(final String message, final List choices, Comparator comparer) { if ((choices == null) || choices.isEmpty()) { return null; @@ -218,26 +206,15 @@ public class GuiChoose { return choice.isEmpty() ? null : choice.get(0); } // getChoiceOptional(String,T...) - // returned Object will never be null - /** - *

- * getChoice. - *

- * - * @param - * a T object. - * @param message - * a {@link java.lang.String} object. - * @param choices - * a T object. - * @return a T object. - */ + + // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine public static T sortedOne(final String message, final T[] choices, Comparator comparer) { final List choice = GuiChoose.sortedGetChoices(message, 1, 1, choices, comparer); assert choice.size() == 1; return choice.get(0); } // getChoice() + // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine public static T sortedOne(final String message, final List choices, Comparator comparer) { if ((choices == null) || (choices.size() == 0)) { return null; @@ -247,18 +224,22 @@ public class GuiChoose { return choice.get(0); } + // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine public static List sortedNoneOrMany(final String message, final List choices, Comparator comparer) { return GuiChoose.sortedGetChoices(message, 0, choices.size(), choices, comparer); } - // If comparer is NULL, T must be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine + // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine public static List sortedGetChoices(final String message, final int min, final int max, final T[] choices, Comparator comparer) { + // You may create a copy of source array if callers expect the collection to be unchanged Arrays.sort(choices, comparer); final ListChooser c = new ListChooser(message, min, max, choices); return getChoices(c); } + // If comparer is NULL, T has to be comparable. Otherwise you'll get an exception from inside the Arrays.sort() routine public static List sortedGetChoices(final String message, final int min, final int max, final List choices, Comparator comparer) { + // You may create a copy of source list if callers expect the collection to be unchanged Collections.sort(choices, comparer); final ListChooser c = new ListChooser(message, min, max, choices); return getChoices(c);