From 372584f7adfc371c1ba2dfbf4f6cd5be46805c57 Mon Sep 17 00:00:00 2001 From: ingmargoudt Date: Fri, 3 Mar 2017 17:04:32 +0100 Subject: [PATCH 1/3] changed cardtype from list to enumset --- .../client/dialog/CardInfoWindowDialog.java | 2 +- .../java/mage/client/game/PlayerPanelExt.java | 2 +- Mage.Common/src/mage/view/AbilityView.java | 4 ++- Mage.Common/src/mage/view/CardView.java | 11 ++++---- .../main/java/mage/server/UserManager.java | 2 +- .../java/mage/server/game/GameController.java | 6 ++-- .../src/mage/cards/c/CrawlingSensation.java | 3 +- .../src/mage/cards/m/MycosynthLattice.java | 3 +- .../src/mage/cards/p/PossibilityStorm.java | 3 +- Mage.Sets/src/mage/cards/p/PrimalSurge.java | 3 +- .../src/mage/cards/s/SidisiBroodTyrant.java | 3 +- .../src/mage/cards/t/TheGitrogMonster.java | 3 +- .../cards/continuous/AuratouchedMageTest.java | 26 +++++++++++++++++ Mage/src/main/java/mage/MageObject.java | 4 ++- Mage/src/main/java/mage/MageObjectImpl.java | 9 +++--- .../java/mage/cards/repository/CardInfo.java | 13 ++++----- .../java/mage/designations/Designation.java | 10 +++---- .../java/mage/game/command/Commander.java | 4 ++- .../main/java/mage/game/command/Emblem.java | 12 ++++---- Mage/src/main/java/mage/game/stack/Spell.java | 11 ++++---- .../java/mage/game/stack/StackAbility.java | 9 +++--- .../java/mage/ContinuousEffectImplTest.java | 28 +++++++++++++++++++ 22 files changed, 116 insertions(+), 55 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/continuous/AuratouchedMageTest.java create mode 100644 Mage/src/test/java/mage/ContinuousEffectImplTest.java diff --git a/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java b/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java index 4141d4832b..131e1f6976 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java @@ -205,7 +205,7 @@ public class CardInfoWindowDialog extends MageDialog { private int qtyCardTypes(mage.view.CardsView cardsView){ Set cardTypesPresent = new LinkedHashSet() {}; for (CardView card : cardsView.values()){ - List cardTypes = card.getCardTypes(); + Set cardTypes = card.getCardTypes(); for (CardType cardType : cardTypes){ cardTypesPresent.add(cardType.toString()); } diff --git a/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java b/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java index fe3ab8d668..3fea196ba7 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java @@ -869,7 +869,7 @@ public class PlayerPanelExt extends javax.swing.JPanel { Set cardTypesPresent = new LinkedHashSet() { }; for (CardView card : cardsView.values()) { - List cardTypes = card.getCardTypes(); + Set cardTypes = card.getCardTypes(); for (CardType cardType : cardTypes) { cardTypesPresent.add(cardType.toString()); } diff --git a/Mage.Common/src/mage/view/AbilityView.java b/Mage.Common/src/mage/view/AbilityView.java index 16492d7a6c..69ff1a5797 100644 --- a/Mage.Common/src/mage/view/AbilityView.java +++ b/Mage.Common/src/mage/view/AbilityView.java @@ -29,6 +29,8 @@ package mage.view; import java.util.ArrayList; +import java.util.HashSet; + import mage.ObjectColor; import mage.abilities.Ability; @@ -53,7 +55,7 @@ public class AbilityView extends CardView { this.power = ""; this.toughness = ""; this.loyalty = ""; - this.cardTypes = new ArrayList<>(); + this.cardTypes = new HashSet<>(); this.subTypes = new ArrayList<>(); this.superTypes = new ArrayList<>(); this.color = new ObjectColor(); diff --git a/Mage.Common/src/mage/view/CardView.java b/Mage.Common/src/mage/view/CardView.java index e20c27d4a1..000e6eb91d 100644 --- a/Mage.Common/src/mage/view/CardView.java +++ b/Mage.Common/src/mage/view/CardView.java @@ -27,9 +27,8 @@ */ package mage.view; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; + import mage.MageObject; import mage.ObjectColor; import mage.abilities.Mode; @@ -71,7 +70,7 @@ public class CardView extends SimpleCardView { protected String toughness; protected String loyalty; protected String startingLoyalty; - protected List cardTypes; + protected Set cardTypes; protected List subTypes; protected List superTypes; protected ObjectColor color; @@ -519,7 +518,7 @@ public class CardView extends SimpleCardView { this.toughness = ""; this.loyalty = ""; this.startingLoyalty = ""; - this.cardTypes = new ArrayList<>(); + this.cardTypes = new HashSet<>(); this.subTypes = new ArrayList<>(); this.superTypes = new ArrayList<>(); this.color = new ObjectColor(); @@ -640,7 +639,7 @@ public class CardView extends SimpleCardView { return startingLoyalty; } - public List getCardTypes() { + public Set getCardTypes() { return cardTypes; } diff --git a/Mage.Server/src/main/java/mage/server/UserManager.java b/Mage.Server/src/main/java/mage/server/UserManager.java index 45252eb034..fff58df8d9 100644 --- a/Mage.Server/src/main/java/mage/server/UserManager.java +++ b/Mage.Server/src/main/java/mage/server/UserManager.java @@ -170,7 +170,7 @@ public class UserManager { calendar.add(Calendar.MINUTE, -3); List usersToCheck = new ArrayList<>(users.values()); for (User user : usersToCheck) { - if (!user.getUserState().equals(UserState.Expired) && user.isExpired(calendar.getTime())) { + if (user.getUserState() != UserState.Expired && user.isExpired(calendar.getTime())) { removeUser(user.getId(), DisconnectReason.SessionExpired); } } diff --git a/Mage.Server/src/main/java/mage/server/game/GameController.java b/Mage.Server/src/main/java/mage/server/game/GameController.java index 908b330707..4ab7ab0c5b 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameController.java +++ b/Mage.Server/src/main/java/mage/server/game/GameController.java @@ -401,7 +401,7 @@ public class GameController implements GameCallback { return false; } } - if (player.isHuman() && gameSessions.get(player.getId()) == null) { + if (player.isHuman() && !gameSessions.containsKey(player.getId())) { return false; } } @@ -410,11 +410,11 @@ public class GameController implements GameCallback { } public void watch(UUID userId) { - if (userPlayerMap.get(userId) != null) { + if (userPlayerMap.containsKey(userId)) { // You can't watch a game if you already a player in it return; } - if (watchers.get(userId) != null) { + if (watchers.containsKey(userId)) { // You can't watch a game if you already watch it return; } diff --git a/Mage.Sets/src/mage/cards/c/CrawlingSensation.java b/Mage.Sets/src/mage/cards/c/CrawlingSensation.java index 839ae59d3f..e119d53c54 100644 --- a/Mage.Sets/src/mage/cards/c/CrawlingSensation.java +++ b/Mage.Sets/src/mage/cards/c/CrawlingSensation.java @@ -29,6 +29,7 @@ package mage.cards.c; import java.util.List; +import java.util.Set; import java.util.UUID; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.common.OnEventTriggeredAbility; @@ -95,7 +96,7 @@ class CrawlingSensationTriggeredAbility extends TriggeredAbilityImpl { for (Card card : zEvent.getCards()) { if (card != null) { UUID cardOwnerId = card.getOwnerId(); - List cardType = card.getCardType(); + Set cardType = card.getCardType(); if (cardOwnerId != null && card.getOwnerId().equals(getControllerId()) diff --git a/Mage.Sets/src/mage/cards/m/MycosynthLattice.java b/Mage.Sets/src/mage/cards/m/MycosynthLattice.java index 3cbcf4d33c..aa6cf3f4a7 100644 --- a/Mage.Sets/src/mage/cards/m/MycosynthLattice.java +++ b/Mage.Sets/src/mage/cards/m/MycosynthLattice.java @@ -28,6 +28,7 @@ package mage.cards.m; import java.util.List; +import java.util.Set; import java.util.UUID; import mage.MageObject; import mage.ObjectColor; @@ -90,7 +91,7 @@ class PermanentsAreArtifactsEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { - List cardType = perm.getCardType(); + Set cardType = perm.getCardType(); if (!cardType.contains(CardType.ARTIFACT)) { cardType.add(CardType.ARTIFACT); } diff --git a/Mage.Sets/src/mage/cards/p/PossibilityStorm.java b/Mage.Sets/src/mage/cards/p/PossibilityStorm.java index 8ebea65699..750ddee03c 100644 --- a/Mage.Sets/src/mage/cards/p/PossibilityStorm.java +++ b/Mage.Sets/src/mage/cards/p/PossibilityStorm.java @@ -28,6 +28,7 @@ package mage.cards.p; import java.util.List; +import java.util.Set; import java.util.UUID; import mage.MageObject; import mage.abilities.Ability; @@ -164,7 +165,7 @@ class PossibilityStormEffect extends OneShotEffect { return false; } - private boolean sharesType(Card card, List cardTypes) { + private boolean sharesType(Card card, Set cardTypes) { for (CardType type : card.getCardType()) { if (cardTypes.contains(type)) { return true; diff --git a/Mage.Sets/src/mage/cards/p/PrimalSurge.java b/Mage.Sets/src/mage/cards/p/PrimalSurge.java index 5e236f8044..f4814a6a6f 100644 --- a/Mage.Sets/src/mage/cards/p/PrimalSurge.java +++ b/Mage.Sets/src/mage/cards/p/PrimalSurge.java @@ -28,6 +28,7 @@ package mage.cards.p; import java.util.List; +import java.util.Set; import java.util.UUID; import mage.constants.CardType; import mage.constants.Outcome; @@ -95,7 +96,7 @@ class PrimalSurgeEffect extends OneShotEffect { Card card = player.getLibrary().removeFromTop(game); if (card != null) { card.moveToExile(null, "", source.getSourceId(), game); - List cardType = card.getCardType(); + Set cardType = card.getCardType(); if ((cardType.contains(CardType.ARTIFACT) || cardType.contains(CardType.CREATURE) || cardType.contains(CardType.ENCHANTMENT) || cardType.contains(CardType.LAND) || cardType.contains(CardType.PLANESWALKER)) diff --git a/Mage.Sets/src/mage/cards/s/SidisiBroodTyrant.java b/Mage.Sets/src/mage/cards/s/SidisiBroodTyrant.java index 62c68abedd..f5c3b4d4f7 100644 --- a/Mage.Sets/src/mage/cards/s/SidisiBroodTyrant.java +++ b/Mage.Sets/src/mage/cards/s/SidisiBroodTyrant.java @@ -28,6 +28,7 @@ package mage.cards.s; import java.util.List; +import java.util.Set; import java.util.UUID; import mage.MageInt; import mage.abilities.TriggeredAbilityImpl; @@ -99,7 +100,7 @@ class SidisiBroodTyrantTriggeredAbility extends TriggeredAbilityImpl { if (card != null) { UUID cardOwnerId = card.getOwnerId(); - List cardType = card.getCardType(); + Set cardType = card.getCardType(); if (cardOwnerId != null && card.getOwnerId().equals(getControllerId()) diff --git a/Mage.Sets/src/mage/cards/t/TheGitrogMonster.java b/Mage.Sets/src/mage/cards/t/TheGitrogMonster.java index fb4be3a9c9..96823e0cc6 100644 --- a/Mage.Sets/src/mage/cards/t/TheGitrogMonster.java +++ b/Mage.Sets/src/mage/cards/t/TheGitrogMonster.java @@ -28,6 +28,7 @@ package mage.cards.t; import java.util.List; +import java.util.Set; import java.util.UUID; import mage.MageInt; import mage.abilities.TriggeredAbilityImpl; @@ -110,7 +111,7 @@ class TheGitrogMonsterTriggeredAbility extends TriggeredAbilityImpl { for (Card card : zEvent.getCards()) { if (card != null) { UUID cardOwnerId = card.getOwnerId(); - List cardType = card.getCardType(); + Set cardType = card.getCardType(); if (cardOwnerId != null && card.getOwnerId().equals(getControllerId()) && cardType != null diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/AuratouchedMageTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/AuratouchedMageTest.java new file mode 100644 index 0000000000..387e141593 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/AuratouchedMageTest.java @@ -0,0 +1,26 @@ +package org.mage.test.cards.continuous; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * Created by IGOUDT on 23-2-2017. + */ +public class AuratouchedMageTest extends CardTestPlayerBase { + + @Test + public void testSearch() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 10); + + addCard(Zone.HAND, playerA, "Auratouched Mage"); + + castSpell(0, PhaseStep.PRECOMBAT_MAIN, playerA, "Auratouched Mage"); + addCard(Zone.LIBRARY, playerA, "White Ward", 1); + setChoice(playerA, "White ward"); + setStopAt(0, PhaseStep.PRECOMBAT_MAIN); + execute(); + } + +} diff --git a/Mage/src/main/java/mage/MageObject.java b/Mage/src/main/java/mage/MageObject.java index 33d5047f0d..be1c2045a4 100644 --- a/Mage/src/main/java/mage/MageObject.java +++ b/Mage/src/main/java/mage/MageObject.java @@ -1,7 +1,9 @@ package mage; import java.io.Serializable; +import java.util.EnumSet; import java.util.List; +import java.util.Set; import java.util.UUID; import mage.abilities.Abilities; import mage.abilities.Ability; @@ -24,7 +26,7 @@ public interface MageObject extends MageItem, Serializable { void setName(String name); - List getCardType(); + EnumSet getCardType(); List getSubtype(Game game); diff --git a/Mage/src/main/java/mage/MageObjectImpl.java b/Mage/src/main/java/mage/MageObjectImpl.java index 19f2ac9dcc..46e0dc5505 100644 --- a/Mage/src/main/java/mage/MageObjectImpl.java +++ b/Mage/src/main/java/mage/MageObjectImpl.java @@ -27,9 +27,8 @@ */ package mage; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; + import mage.abilities.Abilities; import mage.abilities.AbilitiesImpl; import mage.abilities.Ability; @@ -55,7 +54,7 @@ public abstract class MageObjectImpl implements MageObject { protected ObjectColor color; protected ObjectColor frameColor; protected FrameStyle frameStyle; - protected List cardType = new ArrayList<>(); + protected EnumSet cardType = EnumSet.noneOf(CardType.class); protected List subtype = new ArrayList<>(); protected List supertype = new ArrayList<>(); protected Abilities abilities; @@ -127,7 +126,7 @@ public abstract class MageObjectImpl implements MageObject { } @Override - public List getCardType() { + public EnumSet getCardType() { return cardType; } diff --git a/Mage/src/main/java/mage/cards/repository/CardInfo.java b/Mage/src/main/java/mage/cards/repository/CardInfo.java index 09320b0c7b..5fdf545356 100644 --- a/Mage/src/main/java/mage/cards/repository/CardInfo.java +++ b/Mage/src/main/java/mage/cards/repository/CardInfo.java @@ -30,10 +30,9 @@ package mage.cards.repository; import com.j256.ormlite.field.DataType; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; + +import java.util.*; + import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.SpellAbility; @@ -253,8 +252,8 @@ public class CardInfo { return Arrays.asList(list.split(SEPARATOR)); } - public final List getTypes() { - ArrayList list = new ArrayList<>(); + public final EnumSet getTypes() { + EnumSet list = EnumSet.noneOf(CardType.class); for (String type : this.types.split(SEPARATOR)) { try { list.add(CardType.valueOf(type)); @@ -264,7 +263,7 @@ public class CardInfo { return list; } - public final void setTypes(List types) { + public final void setTypes(Set types) { StringBuilder sb = new StringBuilder(); for (CardType item : types) { sb.append(item.name()).append(SEPARATOR); diff --git a/Mage/src/main/java/mage/designations/Designation.java b/Mage/src/main/java/mage/designations/Designation.java index 5636a0a295..5792e2b52f 100644 --- a/Mage/src/main/java/mage/designations/Designation.java +++ b/Mage/src/main/java/mage/designations/Designation.java @@ -5,9 +5,8 @@ */ package mage.designations; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; + import mage.MageInt; import mage.MageObject; import mage.ObjectColor; @@ -29,6 +28,7 @@ import mage.util.GameLog; */ public abstract class Designation implements MageObject { + private static EnumSet emptySet = EnumSet.noneOf(CardType.class); private static List emptyList = new ArrayList(); private static ObjectColor emptyColor = new ObjectColor(); private static ManaCosts emptyCost = new ManaCostsImpl(); @@ -118,8 +118,8 @@ public abstract class Designation implements MageObject { } @Override - public List getCardType() { - return emptyList; + public EnumSet getCardType() { + return emptySet; } @Override diff --git a/Mage/src/main/java/mage/game/command/Commander.java b/Mage/src/main/java/mage/game/command/Commander.java index 2c77772d72..4d8cdb7e87 100644 --- a/Mage/src/main/java/mage/game/command/Commander.java +++ b/Mage/src/main/java/mage/game/command/Commander.java @@ -27,7 +27,9 @@ */ package mage.game.command; +import java.util.EnumSet; import java.util.List; +import java.util.Set; import java.util.UUID; import mage.MageInt; import mage.ObjectColor; @@ -110,7 +112,7 @@ public class Commander implements CommandObject { } @Override - public List getCardType() { + public EnumSet getCardType() { return sourceObject.getCardType(); } diff --git a/Mage/src/main/java/mage/game/command/Emblem.java b/Mage/src/main/java/mage/game/command/Emblem.java index debb77a5bc..c49c1f28d4 100644 --- a/Mage/src/main/java/mage/game/command/Emblem.java +++ b/Mage/src/main/java/mage/game/command/Emblem.java @@ -27,9 +27,8 @@ */ package mage.game.command; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; + import mage.MageInt; import mage.MageObject; import mage.ObjectColor; @@ -51,7 +50,8 @@ import mage.util.GameLog; */ public class Emblem implements CommandObject { - private static List emptyList = new ArrayList(); + private static EnumSet emptySet = EnumSet.noneOf(CardType.class); + private static List emptyList = new ArrayList(); private static ObjectColor emptyColor = new ObjectColor(); private static ManaCosts emptyCost = new ManaCostsImpl(); @@ -148,8 +148,8 @@ public class Emblem implements CommandObject { } @Override - public List getCardType() { - return emptyList; + public EnumSet getCardType() { + return emptySet; } @Override diff --git a/Mage/src/main/java/mage/game/stack/Spell.java b/Mage/src/main/java/mage/game/stack/Spell.java index c8c2cbcc2c..77575be048 100644 --- a/Mage/src/main/java/mage/game/stack/Spell.java +++ b/Mage/src/main/java/mage/game/stack/Spell.java @@ -27,9 +27,8 @@ */ package mage.game.stack; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; + import mage.MageInt; import mage.MageObject; import mage.Mana; @@ -457,14 +456,14 @@ public class Spell extends StackObjImpl implements Card { } @Override - public List getCardType() { + public EnumSet getCardType() { if (faceDown) { - List cardTypes = new ArrayList<>(); + EnumSet cardTypes = EnumSet.noneOf(CardType.class); cardTypes.add(CardType.CREATURE); return cardTypes; } if (this.getSpellAbility() instanceof BestowAbility) { - List cardTypes = new ArrayList<>(); + EnumSet cardTypes = EnumSet.noneOf(CardType.class); cardTypes.addAll(card.getCardType()); cardTypes.remove(CardType.CREATURE); return cardTypes; diff --git a/Mage/src/main/java/mage/game/stack/StackAbility.java b/Mage/src/main/java/mage/game/stack/StackAbility.java index 430820956f..cc2dad58aa 100644 --- a/Mage/src/main/java/mage/game/stack/StackAbility.java +++ b/Mage/src/main/java/mage/game/stack/StackAbility.java @@ -27,9 +27,8 @@ */ package mage.game.stack; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; + import mage.MageInt; import mage.MageObject; import mage.ObjectColor; @@ -72,7 +71,7 @@ import mage.watchers.Watcher; */ public class StackAbility extends StackObjImpl implements Ability { - private static List emptyCardType = new ArrayList<>(); + private static EnumSet emptyCardType = EnumSet.noneOf(CardType.class); private static List emptyString = new ArrayList<>(); private static ObjectColor emptyColor = new ObjectColor(); private static ManaCosts emptyCost = new ManaCostsImpl<>(); @@ -160,7 +159,7 @@ public class StackAbility extends StackObjImpl implements Ability { } @Override - public List getCardType() { + public EnumSet getCardType() { return emptyCardType; } diff --git a/Mage/src/test/java/mage/ContinuousEffectImplTest.java b/Mage/src/test/java/mage/ContinuousEffectImplTest.java new file mode 100644 index 0000000000..603c32ad16 --- /dev/null +++ b/Mage/src/test/java/mage/ContinuousEffectImplTest.java @@ -0,0 +1,28 @@ +package mage; + +import mage.abilities.decorator.ConditionalContinuousEffect; +import mage.abilities.effects.common.continuous.BoostTargetEffect; +import mage.constants.DependencyType; +import mage.constants.Duration; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Set; +import java.util.UUID; + +import static org.hamcrest.CoreMatchers.is; + +/** + * Created by IGOUDT on 25-2-2017. + */ +public class ContinuousEffectImplTest { + + @Test + public void isDependentTo(){ + BoostTargetEffect ghe = new BoostTargetEffect(0,0, Duration.Custom); + ghe.setDependedToType(DependencyType.AuraAddingRemoving); + Set x = ghe.isDependentTo(new ArrayList<>()); + Assert.assertThat(x.size(), is(0)); + } +} From a0930e33796444a26e7864ca1c1c8376036789d5 Mon Sep 17 00:00:00 2001 From: ingmargoudt Date: Fri, 3 Mar 2017 22:14:00 +0100 Subject: [PATCH 2/3] missed 2 hashsets to enumsets --- .../client/dialog/CardInfoWindowDialog.java | 46 ++++++++++--------- Mage.Common/src/mage/view/AbilityView.java | 12 ++--- Mage.Common/src/mage/view/CardView.java | 4 +- .../src/mage/cards/p/PossibilityStorm.java | 3 +- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java b/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java index 131e1f6976..801cbc5c79 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/CardInfoWindowDialog.java @@ -44,6 +44,7 @@ import javax.swing.ImageIcon; import javax.swing.SwingUtilities; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; + import mage.client.cards.BigCard; import mage.client.util.GUISizeHelper; import mage.client.util.ImageHelper; @@ -58,7 +59,6 @@ import org.apache.log4j.Logger; import org.mage.plugins.card.utils.impl.ImageManagerImpl; /** - * * @author BetaSteward_at_googlemail.com */ public class CardInfoWindowDialog extends MageDialog { @@ -109,7 +109,7 @@ public class CardInfoWindowDialog extends MageDialog { this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getExileImage())); break; default: - // no icon yet + // no icon yet } this.setTitelBarToolTip(name); setGUISize(); @@ -202,17 +202,19 @@ public class CardInfoWindowDialog extends MageDialog { }); } - private int qtyCardTypes(mage.view.CardsView cardsView){ - Set cardTypesPresent = new LinkedHashSet() {}; - for (CardView card : cardsView.values()){ + private int qtyCardTypes(mage.view.CardsView cardsView) { + Set cardTypesPresent = new LinkedHashSet() { + }; + for (CardView card : cardsView.values()) { Set cardTypes = card.getCardTypes(); - for (CardType cardType : cardTypes){ + for (CardType cardType : cardTypes) { cardTypesPresent.add(cardType.toString()); } } if (cardTypesPresent.isEmpty()) return 0; else return cardTypesPresent.size(); } + /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always @@ -227,24 +229,24 @@ public class CardInfoWindowDialog extends MageDialog { setIconifiable(true); setResizable(true); setPreferredSize(new Dimension((int) Math.round(GUISizeHelper.otherZonesCardDimension.width * 1.3), - (int) Math.round(GUISizeHelper.otherZonesCardDimension.height * 1.2))); + (int) Math.round(GUISizeHelper.otherZonesCardDimension.height * 1.2))); - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(cards, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(0, 0, 0)) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(cards, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(0, 0, 0)) - ); + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(cards, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(0, 0, 0)) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(cards, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(0, 0, 0)) + ); - pack(); + pack(); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables diff --git a/Mage.Common/src/mage/view/AbilityView.java b/Mage.Common/src/mage/view/AbilityView.java index 69ff1a5797..2c6b61bfe8 100644 --- a/Mage.Common/src/mage/view/AbilityView.java +++ b/Mage.Common/src/mage/view/AbilityView.java @@ -28,14 +28,14 @@ package mage.view; -import java.util.ArrayList; -import java.util.HashSet; - import mage.ObjectColor; import mage.abilities.Ability; +import mage.constants.CardType; + +import java.util.ArrayList; +import java.util.EnumSet; /** - * * @author BetaSteward_at_googlemail.com */ public class AbilityView extends CardView { @@ -55,7 +55,7 @@ public class AbilityView extends CardView { this.power = ""; this.toughness = ""; this.loyalty = ""; - this.cardTypes = new HashSet<>(); + this.cardTypes = EnumSet.noneOf(CardType.class); this.subTypes = new ArrayList<>(); this.superTypes = new ArrayList<>(); this.color = new ObjectColor(); @@ -69,6 +69,6 @@ public class AbilityView extends CardView { public void setName(String name) { this.name = name; } - + } diff --git a/Mage.Common/src/mage/view/CardView.java b/Mage.Common/src/mage/view/CardView.java index 000e6eb91d..82d6c397c5 100644 --- a/Mage.Common/src/mage/view/CardView.java +++ b/Mage.Common/src/mage/view/CardView.java @@ -70,7 +70,7 @@ public class CardView extends SimpleCardView { protected String toughness; protected String loyalty; protected String startingLoyalty; - protected Set cardTypes; + protected EnumSet cardTypes; protected List subTypes; protected List superTypes; protected ObjectColor color; @@ -518,7 +518,7 @@ public class CardView extends SimpleCardView { this.toughness = ""; this.loyalty = ""; this.startingLoyalty = ""; - this.cardTypes = new HashSet<>(); + this.cardTypes = EnumSet.noneOf(CardType.class); this.subTypes = new ArrayList<>(); this.superTypes = new ArrayList<>(); this.color = new ObjectColor(); diff --git a/Mage.Sets/src/mage/cards/p/PossibilityStorm.java b/Mage.Sets/src/mage/cards/p/PossibilityStorm.java index 750ddee03c..c5d41a92fc 100644 --- a/Mage.Sets/src/mage/cards/p/PossibilityStorm.java +++ b/Mage.Sets/src/mage/cards/p/PossibilityStorm.java @@ -27,6 +27,7 @@ */ package mage.cards.p; +import java.util.EnumSet; import java.util.List; import java.util.Set; import java.util.UUID; @@ -165,7 +166,7 @@ class PossibilityStormEffect extends OneShotEffect { return false; } - private boolean sharesType(Card card, Set cardTypes) { + private boolean sharesType(Card card, EnumSet cardTypes) { for (CardType type : card.getCardType()) { if (cardTypes.contains(type)) { return true; From 6b20d352ca1560d70c15c315476d6826f5de8a9d Mon Sep 17 00:00:00 2001 From: ingmargoudt Date: Fri, 3 Mar 2017 22:28:34 +0100 Subject: [PATCH 3/3] added unit test --- .../client/deckeditor/table/TableModel.java | 2 +- .../java/mage/client/util/CardHelperTest.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 Mage.Client/src/test/java/mage/client/util/CardHelperTest.java diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java index 2291e16200..eb6dbc1fed 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java @@ -177,7 +177,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid { String key1 = cv.getName() + cv.getExpansionSetCode() + cv.getCardNumber(); for (CardView cardView : cards.values()) { String key2 = cardView.getName() + cardView.getExpansionSetCode() + cardView.getCardNumber(); - if ((key1).equals(key2)) { + if (key1.equals(key2)) { view.set(j, cardView); break; } diff --git a/Mage.Client/src/test/java/mage/client/util/CardHelperTest.java b/Mage.Client/src/test/java/mage/client/util/CardHelperTest.java new file mode 100644 index 0000000000..6e6a3b3be1 --- /dev/null +++ b/Mage.Client/src/test/java/mage/client/util/CardHelperTest.java @@ -0,0 +1,27 @@ +package mage.client.util; + +import mage.client.deckeditor.table.CardHelper; +import mage.constants.CardType; +import mage.view.CardView; +import org.junit.Assert; +import org.junit.Test; + +import static org.hamcrest.core.Is.is; + +/** + * Created by IGOUDT on 3-3-2017. + */ +public class CardHelperTest { + + @Test + public void testCardTypeOrder() { + CardView v = new CardView(true); + v.getCardTypes().add(CardType.CREATURE); + v.getCardTypes().add(CardType.ARTIFACT); + String cardtypeText = CardHelper.getType(v); + Assert.assertThat(cardtypeText, is("Artifact Creature")); + + } + + +}