From d42b2a6d378260f7771f194c6bece21fb59027ef Mon Sep 17 00:00:00 2001 From: igoudt Date: Sun, 4 Jun 2017 17:12:08 +0200 Subject: [PATCH 1/2] change text for cycling to this card, rather than referring the name --- .../costs/common/DiscardSourceCost.java | 17 +++++++++++++++-- .../mage/abilities/keyword/CyclingAbility.java | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/costs/common/DiscardSourceCost.java b/Mage/src/main/java/mage/abilities/costs/common/DiscardSourceCost.java index ecdca74662..9ef2d9114b 100644 --- a/Mage/src/main/java/mage/abilities/costs/common/DiscardSourceCost.java +++ b/Mage/src/main/java/mage/abilities/costs/common/DiscardSourceCost.java @@ -28,7 +28,6 @@ package mage.abilities.costs.common; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.costs.Cost; import mage.abilities.costs.CostImpl; @@ -36,16 +35,25 @@ import mage.cards.Card; import mage.game.Game; import mage.players.Player; +import java.util.UUID; + /** * * @author BetaSteward_at_googlemail.com */ public class DiscardSourceCost extends CostImpl { + private boolean nameCard = true; + public DiscardSourceCost() {} + public DiscardSourceCost(boolean nameCard){ + this.nameCard = nameCard; + } + public DiscardSourceCost(DiscardSourceCost cost) { super(cost); + nameCard = cost.nameCard; } @Override @@ -67,7 +75,12 @@ public class DiscardSourceCost extends CostImpl { @Override public String getText() { - return "Discard {this}"; + if(nameCard) { + return "Discard {this}"; + } + else{ + return "Discard this card"; + } } @Override diff --git a/Mage/src/main/java/mage/abilities/keyword/CyclingAbility.java b/Mage/src/main/java/mage/abilities/keyword/CyclingAbility.java index b348fe58a2..a8e42850ed 100644 --- a/Mage/src/main/java/mage/abilities/keyword/CyclingAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/CyclingAbility.java @@ -48,14 +48,14 @@ public class CyclingAbility extends ActivatedAbilityImpl { public CyclingAbility(Cost cost) { super(Zone.HAND, new DrawCardSourceControllerEffect(1), cost); - this.addCost(new DiscardSourceCost()); + this.addCost(new DiscardSourceCost(false)); this.cost = cost; this.text = "Cycling"; } public CyclingAbility(Cost cost, FilterCard filter, String text) { super(Zone.HAND, new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true), cost); - this.addCost(new DiscardSourceCost()); + this.addCost(new DiscardSourceCost(false)); this.cost = cost; this.text = text; } From 0cb7d8aab625295f476b3fc885e91843de291b56 Mon Sep 17 00:00:00 2001 From: igoudt Date: Tue, 6 Jun 2017 09:31:41 +0200 Subject: [PATCH 2/2] loop to streams --- .../java/mage/abilities/AbilitiesImpl.java | 115 ++++++++---------- .../condition/CompoundCondition.java | 12 +- Mage/src/main/java/mage/choices/Choices.java | 16 ++- Mage/src/main/java/mage/util/CardUtil.java | 14 +-- 4 files changed, 67 insertions(+), 90 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/AbilitiesImpl.java b/Mage/src/main/java/mage/abilities/AbilitiesImpl.java index 3e54960d5b..9f2fba4438 100644 --- a/Mage/src/main/java/mage/abilities/AbilitiesImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilitiesImpl.java @@ -38,6 +38,7 @@ import mage.util.ThreadLocalStringBuilder; import org.apache.log4j.Logger; import java.util.*; +import java.util.stream.Collectors; /** * @param @@ -117,82 +118,72 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public Abilities getActivatedAbilities(Zone zone) { - Abilities zonedAbilities = new AbilitiesImpl<>(); - for (T ability : this) { - if (ability instanceof ActivatedAbility && ability.getZone().match(zone)) { - zonedAbilities.add((ActivatedAbility) ability); - } - } - return zonedAbilities; + return stream() + .filter(ability -> ability instanceof ActivatedAbility) + .filter(ability -> ability.getZone().match(zone)) + .map(ability -> (ActivatedAbility) ability) + .collect(Collectors.toCollection(AbilitiesImpl::new)); + } @Override public Abilities getPlayableAbilities(Zone zone) { - Abilities zonedAbilities = new AbilitiesImpl<>(); - for (T ability : this) { - if ((ability instanceof ActivatedAbility || (ability instanceof PlayLandAbility)) - && ability.getZone().match(zone)) { - zonedAbilities.add((ActivatedAbility) ability); - } - } - return zonedAbilities; + return stream() + .filter(ability -> (ability instanceof ActivatedAbility)) + .filter(ability -> ability.getZone().match(zone)) + .map(ability -> (ActivatedAbility) ability) + .collect(Collectors.toCollection(AbilitiesImpl::new)); + } @Override public Abilities getActivatedManaAbilities(Zone zone) { - Abilities abilities = new AbilitiesImpl<>(); - for (T ability : this) { - if (ability instanceof ActivatedManaAbilityImpl && ability.getZone().match(zone)) { - abilities.add((ActivatedManaAbilityImpl) ability); - } - } - return abilities; + return stream() + .filter(ability -> ability instanceof ActivatedManaAbilityImpl) + .filter(ability -> ability.getZone().match(zone)) + .map(ability -> (ActivatedManaAbilityImpl) ability) + .collect(Collectors.toCollection(AbilitiesImpl::new)); + } @Override public Abilities getAvailableActivatedManaAbilities(Zone zone, Game game) { - Abilities abilities = new AbilitiesImpl<>(); - for (T ability : this) { - if (ability instanceof ActivatedManaAbilityImpl && ability.getZone().match(zone)) { - if ((((ActivatedManaAbilityImpl) ability).canActivate(ability.getControllerId(), game))) { - abilities.add((ActivatedManaAbilityImpl) ability); - } - } - } - return abilities; + return stream() + .filter(ability -> ability instanceof ActivatedManaAbilityImpl) + .filter(ability -> ability.getZone().match(zone)) + .filter(ability -> (((ActivatedManaAbilityImpl) ability).canActivate(ability.getControllerId(), game))) + .map(ability -> (ActivatedManaAbilityImpl) ability) + .collect(Collectors.toCollection(AbilitiesImpl::new)); + } @Override public Abilities getManaAbilities(Zone zone) { - Abilities abilities = new AbilitiesImpl<>(); - for (T ability : this) { - if (ability.getAbilityType() == AbilityType.MANA && ability.getZone().match(zone)) { - abilities.add(ability); - } - } - return abilities; + return stream() + .filter(ability -> ability.getAbilityType() == AbilityType.MANA) + .filter(ability -> ability.getZone().match(zone)) + .collect(Collectors.toCollection(AbilitiesImpl::new)); + + } @Override public Abilities getEvasionAbilities() { - Abilities abilities = new AbilitiesImpl<>(); - for (T ability : this) { - if (ability instanceof EvasionAbility) { - abilities.add((EvasionAbility) ability); - } - } - return abilities; + return stream() + .filter(ability -> ability instanceof EvasionAbility) + .map(ability -> (EvasionAbility) ability) + .collect(Collectors.toCollection(AbilitiesImpl::new)); + } @Override public Abilities getStaticAbilities(Zone zone) { - Abilities zonedAbilities = new AbilitiesImpl<>(); - for (T ability : this) { - if (ability instanceof StaticAbility && ability.getZone().match(zone)) { - zonedAbilities.add((StaticAbility) ability); - } - } - return zonedAbilities; + return stream() + .filter(ability -> ability instanceof StaticAbility) + .filter(ability -> ability.getZone().match(zone)) + .map(ability -> (StaticAbility) ability) + .collect(Collectors.toCollection(AbilitiesImpl::new)); + } @Override @@ -213,13 +204,11 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public Abilities getProtectionAbilities() { - Abilities abilities = new AbilitiesImpl<>(); - for (T ability : this) { - if (ability instanceof ProtectionAbility) { - abilities.add((ProtectionAbility) ability); - } - } - return abilities; + return stream() + .filter(ability -> ability instanceof ProtectionAbility) + .map(ability -> (ProtectionAbility) ability) + .collect(Collectors.toCollection(AbilitiesImpl::new)); + } @Override @@ -305,12 +294,8 @@ public class AbilitiesImpl extends ArrayList implements Ab @Override public int getOutcomeTotal() { - int total = 0; - for (T ability : this) { - total += ability.getEffects().getOutcomeTotal(); - } - return total; - } + return stream().mapToInt(ability -> ability.getEffects().getOutcomeTotal()).sum(); + } @Override public String getValue() { diff --git a/Mage/src/main/java/mage/abilities/condition/CompoundCondition.java b/Mage/src/main/java/mage/abilities/condition/CompoundCondition.java index b5c076be86..c51167db0f 100644 --- a/Mage/src/main/java/mage/abilities/condition/CompoundCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/CompoundCondition.java @@ -27,11 +27,12 @@ */ package mage.abilities.condition; -import java.util.ArrayList; -import java.util.Arrays; import mage.abilities.Ability; import mage.game.Game; +import java.util.ArrayList; +import java.util.Arrays; + /** * Combines conditions to one compound conditon, all single conditons must be * true to return true for the compound condtion. @@ -55,12 +56,7 @@ public class CompoundCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - for (Condition condition : conditions) { - if (!condition.apply(game, source)) { - return false; - } - } - return true; + return conditions.stream().allMatch(condition -> condition.apply(game, source)); } @Override diff --git a/Mage/src/main/java/mage/choices/Choices.java b/Mage/src/main/java/mage/choices/Choices.java index 66d769fcdc..fd8ce20fc3 100644 --- a/Mage/src/main/java/mage/choices/Choices.java +++ b/Mage/src/main/java/mage/choices/Choices.java @@ -27,13 +27,15 @@ */ package mage.choices; -import java.util.ArrayList; -import java.util.List; import mage.abilities.Ability; import mage.constants.Outcome; import mage.game.Game; import mage.players.Player; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + /** * * @author BetaSteward_at_googlemail.com @@ -57,13 +59,9 @@ public class Choices extends ArrayList { } public List getUnchosen() { - List unchosen = new ArrayList<>(); - for (Choice choice : this) { - if (!choice.isChosen()) { - unchosen.add(choice); - } - } - return unchosen; + return stream() + .filter(choice -> !choice.isChosen()) + .collect(Collectors.toList()); } public void clearChosen() { diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 673d9cb0d9..3155da8ae2 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -27,27 +27,24 @@ */ package mage.util; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; -import java.util.UUID; - import mage.MageObject; import mage.Mana; -import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.ActivatedAbility; import mage.abilities.SpellAbility; import mage.abilities.costs.VariableCost; import mage.abilities.costs.mana.*; import mage.cards.Card; -import mage.filter.FilterMana; import mage.game.Game; import mage.game.permanent.Permanent; import mage.game.permanent.token.Token; -import mage.game.stack.Spell; import mage.util.functions.CopyTokenFunction; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + /** * @author nantuko */ @@ -396,6 +393,7 @@ public final class CardUtil { } public static boolean checkNumeric(String s) { + for (int i = 0; i < s.length(); i++) { if (!Character.isDigit(s.charAt(i))) { return false;