From 1bc8e2248bc32cf71bd4c340a951830ed1a69019 Mon Sep 17 00:00:00 2001 From: ingmargoudt Date: Tue, 7 Mar 2017 21:47:11 +0100 Subject: [PATCH 1/5] changed enum equals to ==, removed contains check for set --- Mage.Common/src/mage/view/RevealedView.java | 4 +-- Mage.Common/src/mage/view/RoundView.java | 8 ++--- Mage/src/main/java/mage/ConditionalMana.java | 6 ++-- .../abilities/abilityword/KinshipAbility.java | 2 +- .../AfterBlockersAreDeclaredCondition.java | 5 +-- .../condition/common/IsPhaseCondition.java | 5 ++- .../common/ManaWasSpentCondition.java | 2 +- ...yTurnBeforeAttackersDeclaredCondition.java | 4 +-- .../SourceTappedBeforeUntapStepCondition.java | 4 +-- .../condition/common/SurgedCondition.java | 2 +- ...nControllersNextUntapStepSourceEffect.java | 2 +- .../continuous/AddCardTypeSourceEffect.java | 2 +- .../continuous/BecomesColorTargetEffect.java | 2 +- .../BecomesCreatureAttachedEffect.java | 36 ++++++++----------- .../continuous/SetToughnessSourceEffect.java | 2 +- .../mage/abilities/keyword/EchoAbility.java | 2 +- .../abilities/keyword/SuspendAbility.java | 2 +- Mage/src/main/java/mage/game/Table.java | 2 +- 18 files changed, 42 insertions(+), 50 deletions(-) diff --git a/Mage.Common/src/mage/view/RevealedView.java b/Mage.Common/src/mage/view/RevealedView.java index d5f086e410..b2f79d67fa 100644 --- a/Mage.Common/src/mage/view/RevealedView.java +++ b/Mage.Common/src/mage/view/RevealedView.java @@ -29,12 +29,12 @@ package mage.view; import java.io.Serializable; + import mage.cards.Card; import mage.cards.Cards; import mage.game.Game; /** - * * @author BetaSteward_at_googlemail.com */ public class RevealedView implements Serializable { @@ -44,7 +44,7 @@ public class RevealedView implements Serializable { public RevealedView(String name, Cards cards, Game game) { this.name = name; - for (Card card: cards.getCards(game)) { + for (Card card : cards.getCards(game)) { this.cards.put(card.getId(), new CardView(card, game, card.getId())); } } diff --git a/Mage.Common/src/mage/view/RoundView.java b/Mage.Common/src/mage/view/RoundView.java index b34b5b89ee..fc8297b9c3 100644 --- a/Mage.Common/src/mage/view/RoundView.java +++ b/Mage.Common/src/mage/view/RoundView.java @@ -31,13 +31,13 @@ package mage.view; import java.io.Serializable; import java.util.ArrayList; import java.util.List; + import mage.game.Game; import mage.game.GameInfo; import mage.game.tournament.Round; import mage.game.tournament.TournamentPairing; /** - * * @author BetaSteward_at_googlemail.com */ public class RoundView implements Serializable { @@ -47,17 +47,17 @@ public class RoundView implements Serializable { public RoundView(Round round) { try { - for (TournamentPairing pair: round.getPairs()) { + for (TournamentPairing pair : round.getPairs()) { // get info of finished games from match if (pair.getMatch() != null) { - for (GameInfo gameInfo: pair.getMatch().getGamesInfo()) { + for (GameInfo gameInfo : pair.getMatch().getGamesInfo()) { games.add(new TournamentGameView(round.getRoundNumber(), gameInfo.getMatchId(), gameInfo.getGameId(), gameInfo.getState(), gameInfo.getResult(), gameInfo.getPlayers(), gameInfo.getTableId())); } if (!pair.getMatch().hasEnded()) { int numberSavedGames = pair.getMatch().getGamesInfo().size(); if (pair.getMatch() != null) { int gameCount = 0; - for (Game game: pair.getMatch().getGames()) { + for (Game game : pair.getMatch().getGames()) { gameCount++; if (gameCount > numberSavedGames) { // only unfinished game info directly from game diff --git a/Mage/src/main/java/mage/ConditionalMana.java b/Mage/src/main/java/mage/ConditionalMana.java index 3dcfec39f6..825ec5d541 100644 --- a/Mage/src/main/java/mage/ConditionalMana.java +++ b/Mage/src/main/java/mage/ConditionalMana.java @@ -104,13 +104,13 @@ public class ConditionalMana extends Mana implements Serializable { if (!applied) { // if one condition fails, return false only if All conditions should be met // otherwise it may happen that Any other condition will be ok - if (scope.equals(Filter.ComparisonScope.All)) { + if (scope == Filter.ComparisonScope.All) { return false; } } else { // if one condition succeeded, return true only if Any conditions should be met // otherwise it may happen that any other condition will fail - if (scope.equals(Filter.ComparisonScope.Any)) { + if (scope == Filter.ComparisonScope.Any) { return true; } } @@ -118,7 +118,7 @@ public class ConditionalMana extends Mana implements Serializable { // we are here // if All conditions should be met, then it's Ok (return true) // if Any, then it should have already returned true, so returning false here - return scope.equals(Filter.ComparisonScope.All); + return scope == Filter.ComparisonScope.All; } @Override diff --git a/Mage/src/main/java/mage/abilities/abilityword/KinshipAbility.java b/Mage/src/main/java/mage/abilities/abilityword/KinshipAbility.java index 6670a61c99..ccf9cffce7 100644 --- a/Mage/src/main/java/mage/abilities/abilityword/KinshipAbility.java +++ b/Mage/src/main/java/mage/abilities/abilityword/KinshipAbility.java @@ -131,7 +131,7 @@ class KinshipBaseEffect extends OneShotEffect { controller.revealCards(sourcePermanent.getName(), cards, game); for (Effect effect: kinshipEffects) { effect.setTargetPointer(new FixedTarget(card.getId())); - if (effect.getEffectType().equals(EffectType.ONESHOT)) { + if (effect.getEffectType() == EffectType.ONESHOT) { effect.apply(game, source); } else { if (effect instanceof ContinuousEffect) { diff --git a/Mage/src/main/java/mage/abilities/condition/common/AfterBlockersAreDeclaredCondition.java b/Mage/src/main/java/mage/abilities/condition/common/AfterBlockersAreDeclaredCondition.java index 84086f7a4a..46118efa63 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/AfterBlockersAreDeclaredCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/AfterBlockersAreDeclaredCondition.java @@ -26,8 +26,9 @@ public class AfterBlockersAreDeclaredCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - return !(game.getStep().getType().equals(PhaseStep.BEGIN_COMBAT) - || game.getStep().getType().equals(PhaseStep.DECLARE_ATTACKERS)); + + return !(game.getStep().getType() == PhaseStep.BEGIN_COMBAT + || game.getStep().getType() == PhaseStep.DECLARE_ATTACKERS); } @Override diff --git a/Mage/src/main/java/mage/abilities/condition/common/IsPhaseCondition.java b/Mage/src/main/java/mage/abilities/condition/common/IsPhaseCondition.java index 7c133182f7..93fb6632dd 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/IsPhaseCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/IsPhaseCondition.java @@ -34,20 +34,19 @@ import mage.constants.TurnPhase; import mage.game.Game; /** - * * @author LevelX2 */ public class IsPhaseCondition implements Condition { protected TurnPhase turnPhase; - public IsPhaseCondition(TurnPhase turnPhase) { + public IsPhaseCondition(TurnPhase turnPhase) { this.turnPhase = turnPhase; } @Override public boolean apply(Game game, Ability source) { - return turnPhase.equals(game.getTurn().getPhaseType()); + return turnPhase == game.getTurn().getPhaseType(); } @Override diff --git a/Mage/src/main/java/mage/abilities/condition/common/ManaWasSpentCondition.java b/Mage/src/main/java/mage/abilities/condition/common/ManaWasSpentCondition.java index 93244ebb33..be0984f282 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/ManaWasSpentCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/ManaWasSpentCondition.java @@ -53,7 +53,7 @@ public class ManaWasSpentCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - if (source.getAbilityType().equals(AbilityType.SPELL)) { + if (source.getAbilityType() == AbilityType.SPELL) { return (source.getManaCostsToPay().getPayment().getColor(coloredManaSymbol) > 0); } ManaSpentToCastWatcher watcher = (ManaSpentToCastWatcher) game.getState().getWatchers().get("ManaSpentToCast", source.getSourceId()); diff --git a/Mage/src/main/java/mage/abilities/condition/common/MyTurnBeforeAttackersDeclaredCondition.java b/Mage/src/main/java/mage/abilities/condition/common/MyTurnBeforeAttackersDeclaredCondition.java index 8b531ad885..cb5d6b37f8 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/MyTurnBeforeAttackersDeclaredCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/MyTurnBeforeAttackersDeclaredCondition.java @@ -48,10 +48,10 @@ public class MyTurnBeforeAttackersDeclaredCondition implements Condition { public boolean apply(Game game, Ability source) { if (game.getActivePlayerId().equals(source.getControllerId())) { TurnPhase turnPhase = game.getTurn().getPhase().getType(); - if (turnPhase.equals(TurnPhase.BEGINNING) || turnPhase.equals(TurnPhase.PRECOMBAT_MAIN)) { + if (turnPhase == TurnPhase.BEGINNING || turnPhase == TurnPhase.PRECOMBAT_MAIN) { return true; } - if (turnPhase.equals(TurnPhase.COMBAT)) { + if (turnPhase == TurnPhase.COMBAT) { return !game.getTurn().isDeclareAttackersStepStarted(); } } diff --git a/Mage/src/main/java/mage/abilities/condition/common/SourceTappedBeforeUntapStepCondition.java b/Mage/src/main/java/mage/abilities/condition/common/SourceTappedBeforeUntapStepCondition.java index 0f64617d05..6a6f28bfe5 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/SourceTappedBeforeUntapStepCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/SourceTappedBeforeUntapStepCondition.java @@ -65,12 +65,12 @@ public class SourceTappedBeforeUntapStepCondition implements Condition { Permanent permanent = game.getBattlefield().getPermanent(permanentId); if (permanent != null) { - if (lastTurnNum != game.getTurnNum() && turnPhase.equals(TurnPhase.BEGINNING)) { + if (lastTurnNum != game.getTurnNum() && turnPhase == TurnPhase.BEGINNING) { lastTurnNum = game.getTurnNum(); permanentWasTappedBeforeUntapStep = permanent.isTapped(); } - if (step.getType().equals(PhaseStep.UNTAP)) { + if (step.getType() == PhaseStep.UNTAP) { return permanentWasTappedBeforeUntapStep; } else { return permanent.isTapped(); diff --git a/Mage/src/main/java/mage/abilities/condition/common/SurgedCondition.java b/Mage/src/main/java/mage/abilities/condition/common/SurgedCondition.java index 76d3d3a4b1..609b14dd82 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/SurgedCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/SurgedCondition.java @@ -54,7 +54,7 @@ public class SurgedCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - if (source.getAbilityType().equals(AbilityType.TRIGGERED)) { + if (source.getAbilityType() == AbilityType.TRIGGERED) { @SuppressWarnings("unchecked") ArrayList surgeActivations = (ArrayList) game.getState().getValue(SurgeAbility.SURGE_ACTIVATION_VALUE_KEY + source.getSourceId()); if (surgeActivations != null) { diff --git a/Mage/src/main/java/mage/abilities/effects/common/DontUntapInControllersNextUntapStepSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/DontUntapInControllersNextUntapStepSourceEffect.java index 666aa0a08b..7ce2f8b92a 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/DontUntapInControllersNextUntapStepSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/DontUntapInControllersNextUntapStepSourceEffect.java @@ -59,7 +59,7 @@ public class DontUntapInControllersNextUntapStepSourceEffect extends ContinuousR return false; } // remember the turn of the untap step the effect has to be applied - if (GameEvent.EventType.UNTAP_STEP.equals(event.getType()) + if (event.getType() == GameEvent.EventType.UNTAP_STEP && game.getActivePlayerId().equals(source.getControllerId())) { if (validForTurnNum == game.getTurnNum()) { // the turn has a second untap step but the effect is already related to the first untap step discard(); diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/AddCardTypeSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/AddCardTypeSourceEffect.java index 0fa2451938..35ee7f03fd 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/AddCardTypeSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/AddCardTypeSourceEffect.java @@ -63,7 +63,7 @@ public class AddCardTypeSourceEffect extends ContinuousEffectImpl { @Override public void init(Ability source, Game game) { super.init(source, game); - if (Duration.Custom.equals(this.duration) || this.duration.toString().startsWith("End")) { + if (this.duration == Duration.Custom || this.duration.toString().startsWith("End")) { affectedObjectList.add(new MageObjectReference(source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()), game)); if (affectedObjectList.isEmpty()) { this.discard(); diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesColorTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesColorTargetEffect.java index 12675f6798..abf36d2d3a 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesColorTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesColorTargetEffect.java @@ -116,7 +116,7 @@ public class BecomesColorTargetEffect extends ContinuousEffectImpl { targetObject.getColor(game).setColor(setColor); } } - if (!objectFound && this.getDuration().equals(Duration.Custom)) { + if (!objectFound && this.getDuration() == Duration.Custom) { this.discard(); } return true; diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesCreatureAttachedEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesCreatureAttachedEffect.java index d946b6869f..5386d56ed5 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesCreatureAttachedEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/BecomesCreatureAttachedEffect.java @@ -40,7 +40,6 @@ import mage.game.permanent.Permanent; import mage.game.permanent.token.Token; /** - * * @author jeff */ public class BecomesCreatureAttachedEffect extends ContinuousEffectImpl { @@ -86,11 +85,9 @@ public class BecomesCreatureAttachedEffect extends ContinuousEffectImpl { switch (layer) { case TypeChangingEffects_4: if (sublayer == SubLayer.NA) { - if (!token.getSupertype().isEmpty()) { - for (String t : token.getSupertype()) { - if (!permanent.getSupertype().contains(t)) { - permanent.getSupertype().add(t); - } + for (String t : token.getSupertype()) { + if (!permanent.getSupertype().contains(t)) { + permanent.getSupertype().add(t); } } // card type @@ -100,13 +97,10 @@ public class BecomesCreatureAttachedEffect extends ContinuousEffectImpl { permanent.getCardType().clear(); break; } - if (!token.getCardType().isEmpty()) { - for (CardType t : token.getCardType()) { - if (!permanent.getCardType().contains(t)) { - permanent.getCardType().add(t); - } - } + for (CardType t : token.getCardType()) { + permanent.getCardType().add(t); } + // sub type switch (loseType) { case ALL: @@ -115,18 +109,17 @@ public class BecomesCreatureAttachedEffect extends ContinuousEffectImpl { permanent.getSubtype(game).retainAll(CardRepository.instance.getLandTypes()); break; } - if (!token.getSubtype(game).isEmpty()) { - for (String t : token.getSubtype(game)) { - if (!permanent.getSubtype(game).contains(t)) { - permanent.getSubtype(game).add(t); - } + for (String t : token.getSubtype(game)) { + if (!permanent.getSubtype(game).contains(t)) { + permanent.getSubtype(game).add(t); } } + } break; case ColorChangingEffects_5: if (sublayer == SubLayer.NA) { - if (loseType.equals(LoseType.ALL)) { + if (loseType == LoseType.ALL) { permanent.getColor(game).setBlack(false); permanent.getColor(game).setGreen(false); permanent.getColor(game).setBlue(false); @@ -148,11 +141,10 @@ public class BecomesCreatureAttachedEffect extends ContinuousEffectImpl { permanent.removeAllAbilities(source.getSourceId(), game); break; } - if (!token.getAbilities().isEmpty()) { - for (Ability ability : token.getAbilities()) { - permanent.addAbility(ability, source.getSourceId(), game); - } + for (Ability ability : token.getAbilities()) { + permanent.addAbility(ability, source.getSourceId(), game); } + } break; case PTChangingEffects_7: diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/SetToughnessSourceEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/SetToughnessSourceEffect.java index 09e4b0febf..af48b2b92c 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/SetToughnessSourceEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/SetToughnessSourceEffect.java @@ -69,7 +69,7 @@ public class SetToughnessSourceEffect extends ContinuousEffectImpl { mageObject.getToughness().setValue(value); return true; } else { - if (Duration.Custom.equals(duration)) { + if (duration == Duration.Custom) { discard(); } } diff --git a/Mage/src/main/java/mage/abilities/keyword/EchoAbility.java b/Mage/src/main/java/mage/abilities/keyword/EchoAbility.java index 8b28bb0e00..a98f93567f 100644 --- a/Mage/src/main/java/mage/abilities/keyword/EchoAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/EchoAbility.java @@ -91,7 +91,7 @@ public class EchoAbility extends TriggeredAbilityImpl { @Override public boolean checkTrigger(GameEvent event, Game game) { // reset the echo paid state back, if creature enteres the battlefield - if (event.getType().equals(GameEvent.EventType.ENTERS_THE_BATTLEFIELD) + if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD && event.getTargetId().equals(this.getSourceId())) { this.echoPaid = false; diff --git a/Mage/src/main/java/mage/abilities/keyword/SuspendAbility.java b/Mage/src/main/java/mage/abilities/keyword/SuspendAbility.java index da004d5b75..a273bd123f 100644 --- a/Mage/src/main/java/mage/abilities/keyword/SuspendAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/SuspendAbility.java @@ -236,7 +236,7 @@ public class SuspendAbility extends SpecialAction { @Override public boolean canActivate(UUID playerId, Game game) { - if (!game.getState().getZone(getSourceId()).equals(Zone.HAND)) { + if (game.getState().getZone(getSourceId()) != Zone.HAND) { // Supend can only be activated from hand return false; } diff --git a/Mage/src/main/java/mage/game/Table.java b/Mage/src/main/java/mage/game/Table.java index 44b04c1205..aa779be8fa 100644 --- a/Mage/src/main/java/mage/game/Table.java +++ b/Mage/src/main/java/mage/game/Table.java @@ -148,7 +148,7 @@ public class Table implements Serializable { * */ public void closeTable() { - if (!getState().equals(TableState.WAITING) && !getState().equals(TableState.READY_TO_START)) { + if (getState() != TableState.WAITING && getState() != TableState.READY_TO_START) { setState(TableState.FINISHED); // otherwise the table can be removed completely } this.validator = null; From c5002983e351f13ced58189a6fcb25284e6e8b75 Mon Sep 17 00:00:00 2001 From: ingmargoudt Date: Tue, 7 Mar 2017 22:02:15 +0100 Subject: [PATCH 2/5] changed static zone function to enum method --- Mage.Sets/src/mage/cards/g/GhostlyFlicker.java | 3 ++- Mage/src/main/java/mage/constants/Zone.java | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Mage.Sets/src/mage/cards/g/GhostlyFlicker.java b/Mage.Sets/src/mage/cards/g/GhostlyFlicker.java index 1838010f4b..f213a2cf40 100644 --- a/Mage.Sets/src/mage/cards/g/GhostlyFlicker.java +++ b/Mage.Sets/src/mage/cards/g/GhostlyFlicker.java @@ -30,6 +30,7 @@ package mage.cards.g; import java.util.HashSet; import java.util.Set; import java.util.UUID; + import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; @@ -112,7 +113,7 @@ class GhostlyFlickerEffect extends OneShotEffect { Set toBattlefield = new HashSet<>(); for (Card card : toExile) { Zone currentZone = game.getState().getZone(card.getId()); - if (!(Zone.BATTLEFIELD == currentZone) && Zone.isPublicZone(currentZone)) { + if (Zone.BATTLEFIELD != currentZone && currentZone.isPublicZone()) { toBattlefield.add(game.getCard(card.getId())); } } diff --git a/Mage/src/main/java/mage/constants/Zone.java b/Mage/src/main/java/mage/constants/Zone.java index 73b2d4743c..f9a2474761 100644 --- a/Mage/src/main/java/mage/constants/Zone.java +++ b/Mage/src/main/java/mage/constants/Zone.java @@ -33,7 +33,13 @@ package mage.constants; */ public enum Zone { - HAND, GRAVEYARD, LIBRARY, BATTLEFIELD, STACK, EXILED, ALL, OUTSIDE, COMMAND; + HAND(false), GRAVEYARD(true), LIBRARY(false), BATTLEFIELD(true), STACK(true), EXILED(true), ALL(false), OUTSIDE(false), COMMAND(false); + + private boolean isPublic; + + Zone(boolean isPublic){ + this.isPublic = isPublic; + } public boolean match(Zone zone) { return (this == zone || this == ALL || zone == ALL); @@ -47,7 +53,7 @@ public enum Zone { return super.toString(); } - public static boolean isPublicZone(Zone zone) { - return GRAVEYARD.equals(zone) || BATTLEFIELD.equals(zone) || STACK.equals(zone) || EXILED.equals(zone) || COMMAND.equals(zone); + public boolean isPublicZone(){ + return isPublic; } } From daed944eb645efb7f36084d42646b89eb9621a12 Mon Sep 17 00:00:00 2001 From: ingmargoudt Date: Tue, 7 Mar 2017 22:06:44 +0100 Subject: [PATCH 3/5] refactored the SortBy.getByString --- .../java/mage/client/constants/Constants.java | 21 +++++-------------- .../mage/client/deckeditor/SortSetting.java | 11 +++++----- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/constants/Constants.java b/Mage.Client/src/main/java/mage/client/constants/Constants.java index 4401592754..a71ccc5750 100644 --- a/Mage.Client/src/main/java/mage/client/constants/Constants.java +++ b/Mage.Client/src/main/java/mage/client/constants/Constants.java @@ -32,7 +32,6 @@ import javax.swing.BorderFactory; import javax.swing.border.Border; /** - * * @author BetaSteward_at_googlemail.com */ public final class Constants { @@ -116,22 +115,12 @@ public final class Constants { } public static SortBy getByString(String text) { - switch (text) { - case "Card Type": - return CARD_TYPE; - case "Casting Cost": - return CASTING_COST; - case "Rarity": - return RARITY; - case "Color": - return COLOR; - case "Color Identity": - return COLOR_IDENTITY; - case "Name": - return NAME; - default: - return UNSORTED; + for (SortBy sortBy : values()) { + if (sortBy.text.equals(text)) { + return sortBy; + } } + return UNSORTED; } } diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/SortSetting.java b/Mage.Client/src/main/java/mage/client/deckeditor/SortSetting.java index 3301cc9039..ed08c68931 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/SortSetting.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/SortSetting.java @@ -31,16 +31,15 @@ import mage.client.constants.Constants.SortBy; import mage.client.dialog.PreferencesDialog; /** - * * @author LevelX2 */ public abstract class SortSetting { - + SortBy sortBy; int sortIndex; boolean ascending; boolean pilesToggle; - + final String prefSortBy; final String prefSortIndex; final String prefSortAscending; @@ -60,7 +59,7 @@ public abstract class SortSetting { this.ascending = PreferencesDialog.getCachedValue(this.prefSortAscending, "1").equals("1"); this.pilesToggle = PreferencesDialog.getCachedValue(this.prefPilesToggle, "true").equals("true"); } - + public void setSortBy(SortBy sortBy) { this.sortBy = sortBy; PreferencesDialog.saveValue(prefSortBy, sortBy.toString()); @@ -73,12 +72,12 @@ public abstract class SortSetting { public void setAscending(boolean ascending) { this.ascending = ascending; - PreferencesDialog.saveValue(this.prefSortAscending, this.ascending ? "1":"0"); + PreferencesDialog.saveValue(this.prefSortAscending, this.ascending ? "1" : "0"); } public void setPilesToggle(boolean pileToggle) { this.pilesToggle = pileToggle; - PreferencesDialog.saveValue(this.prefSortAscending, this.pilesToggle ? "true":"false"); + PreferencesDialog.saveValue(this.prefSortAscending, this.pilesToggle ? "true" : "false"); } public SortBy getSortBy() { From 0a77c186be352f1abca65820fb51c41eb9c96268 Mon Sep 17 00:00:00 2001 From: ingmargoudt Date: Tue, 7 Mar 2017 22:15:58 +0100 Subject: [PATCH 4/5] moved sessionstate enum to sessionImpl --- Mage.Common/src/mage/constants/Constants.java | 3 - Mage.Common/src/mage/remote/SessionImpl.java | 63 ++++++++++--------- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/Mage.Common/src/mage/constants/Constants.java b/Mage.Common/src/mage/constants/Constants.java index c2617b522b..8573459d7b 100644 --- a/Mage.Common/src/mage/constants/Constants.java +++ b/Mage.Common/src/mage/constants/Constants.java @@ -76,10 +76,7 @@ public final class Constants { */ public static final int PRIORITY_TIME_SEC = 1200; - public enum SessionState { - DISCONNECTED, CONNECTED, CONNECTING, DISCONNECTING, SERVER_STARTING - } public enum Option { diff --git a/Mage.Common/src/mage/remote/SessionImpl.java b/Mage.Common/src/mage/remote/SessionImpl.java index 3549dcd0c5..1fb7a8dfe2 100644 --- a/Mage.Common/src/mage/remote/SessionImpl.java +++ b/Mage.Common/src/mage/remote/SessionImpl.java @@ -33,6 +33,7 @@ import java.net.*; import java.util.*; import java.util.concurrent.TimeUnit; import javax.swing.JOptionPane; + import mage.MageException; import mage.cards.decks.DeckCardLists; import mage.cards.decks.InvalidDeckException; @@ -40,7 +41,6 @@ import mage.cards.repository.CardInfo; import mage.cards.repository.CardRepository; import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionRepository; -import mage.constants.Constants.SessionState; import mage.constants.ManaType; import mage.constants.PlayerAction; import mage.game.GameException; @@ -63,11 +63,14 @@ import org.jboss.remoting.transport.socket.SocketWrapper; import org.jboss.remoting.transporter.TransporterClient; /** - * * @author BetaSteward_at_googlemail.com */ public class SessionImpl implements Session { + private enum SessionState { + DISCONNECTED, CONNECTED, CONNECTING, DISCONNECTING, SERVER_STARTING + } + private static final Logger logger = Logger.getLogger(SessionImpl.class); private final MageClient client; @@ -216,32 +219,32 @@ public class SessionImpl implements Session { public synchronized boolean connect(final Connection connection) { return establishJBossRemotingConnection(connection) && handleRemotingTaskExceptions(new RemotingTask() { - @Override - public boolean run() throws Throwable { - logger.info("Trying to log-in as " + getUserName() + " to XMAGE server at " + connection.getHost() + ':' + connection.getPort()); - boolean registerResult; - if (connection.getAdminPassword() == null) { - // for backward compatibility. don't remove twice call - first one does nothing but for version checking - registerResult = server.connectUser(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion(), connection.getUserIdStr()); - if (registerResult) { - server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString(), connection.getUserIdStr()); - } - } else { - registerResult = server.connectAdmin(connection.getAdminPassword(), sessionId, client.getVersion()); - } - if (registerResult) { - serverState = server.getServerState(); - if (!connection.getUsername().equals("Admin")) { - updateDatabase(connection.isForceDBComparison(), serverState); - } - logger.info("Logged-in as " + getUserName() + " to MAGE server at " + connection.getHost() + ':' + connection.getPort()); - client.connected(getUserName() + '@' + connection.getHost() + ':' + connection.getPort() + ' '); - return true; - } - disconnect(false); - return false; + @Override + public boolean run() throws Throwable { + logger.info("Trying to log-in as " + getUserName() + " to XMAGE server at " + connection.getHost() + ':' + connection.getPort()); + boolean registerResult; + if (connection.getAdminPassword() == null) { + // for backward compatibility. don't remove twice call - first one does nothing but for version checking + registerResult = server.connectUser(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion(), connection.getUserIdStr()); + if (registerResult) { + server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString(), connection.getUserIdStr()); } - }); + } else { + registerResult = server.connectAdmin(connection.getAdminPassword(), sessionId, client.getVersion()); + } + if (registerResult) { + serverState = server.getServerState(); + if (!connection.getUsername().equals("Admin")) { + updateDatabase(connection.isForceDBComparison(), serverState); + } + logger.info("Logged-in as " + getUserName() + " to MAGE server at " + connection.getHost() + ':' + connection.getPort()); + client.connected(getUserName() + '@' + connection.getHost() + ':' + connection.getPort() + ' '); + return true; + } + disconnect(false); + return false; + } + }); } public Optional getServerHostname() { @@ -468,9 +471,8 @@ public class SessionImpl implements Session { } /** - * * @param askForReconnect - true = connection was lost because of error and - * ask the user if he want to try to reconnect + * ask the user if he want to try to reconnect */ @Override public synchronized void disconnect(boolean askForReconnect) { @@ -965,7 +967,6 @@ public class SessionImpl implements Session { } - @Override public boolean joinGame(UUID gameId) { try { @@ -1175,7 +1176,7 @@ public class SessionImpl implements Session { return false; } -// @Override + // @Override // public boolean startChallenge(UUID roomId, UUID tableId, UUID challengeId) { // try { // if (isConnected()) { From 4aaf73e0d238b3b73f0c159931de7b7ed5cbb13e Mon Sep 17 00:00:00 2001 From: ingmargoudt Date: Tue, 7 Mar 2017 22:28:10 +0100 Subject: [PATCH 5/5] changed the type used in ImagePanel from an int to an enum --- .../src/main/java/mage/client/MageFrame.java | 3 +- .../collection/viewer/MageBook.java | 9 +++--- .../java/mage/client/game/PlayerPanelExt.java | 11 ++++--- .../card/arcane/CardPanelComponentImpl.java | 3 +- .../mage/plugins/theme/ThemePluginImpl.java | 5 +-- .../src/mage/cards/CardDimensions.java | 27 ++++++++-------- .../src/mage/components/ImagePanel.java | 32 ++++++++----------- .../src/mage/components/ImagePanelStyle.java | 8 +++++ .../src/mage/interfaces/ServerState.java | 19 +++++------ 9 files changed, 61 insertions(+), 56 deletions(-) create mode 100644 Mage.Common/src/mage/components/ImagePanelStyle.java diff --git a/Mage.Client/src/main/java/mage/client/MageFrame.java b/Mage.Client/src/main/java/mage/client/MageFrame.java index bec3728b3d..22bcd2c147 100644 --- a/Mage.Client/src/main/java/mage/client/MageFrame.java +++ b/Mage.Client/src/main/java/mage/client/MageFrame.java @@ -55,6 +55,7 @@ import mage.client.util.gui.ArrowBuilder; import mage.client.util.gui.countryBox.CountryUtil; import mage.client.util.stats.UpdateMemUsageTask; import mage.components.ImagePanel; +import mage.components.ImagePanelStyle; import mage.constants.PlayerAction; import mage.interfaces.MageClient; import mage.interfaces.callback.CallbackClient; @@ -426,7 +427,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } else { InputStream is = this.getClass().getResourceAsStream(filename); BufferedImage background = ImageIO.read(is); - backgroundPane = new ImagePanel(background, ImagePanel.SCALED); + backgroundPane = new ImagePanel(background, ImagePanelStyle.SCALED); } backgroundPane.setSize(1024, 768); desktopPane.add(backgroundPane, JLayeredPane.DEFAULT_LAYER); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java index 53283cffab..5bbb699088 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/collection/viewer/MageBook.java @@ -44,6 +44,7 @@ import mage.client.util.NaturalOrderCardNumberComparator; import mage.client.util.audio.AudioManager; import mage.client.util.sets.ConstructedFormats; import mage.components.ImagePanel; +import mage.components.ImagePanelStyle; import mage.constants.Rarity; import mage.view.CardView; import org.apache.log4j.Logger; @@ -89,12 +90,12 @@ public class MageBook extends JComponent { setMinimumSize(new Dimension(conf.WIDTH, conf.HEIGHT)); //setBorder(BorderFactory.createLineBorder(Color.green)); - jPanelLeft = getImagePanel(LEFT_PANEL_IMAGE_PATH, ImagePanel.TILED); + jPanelLeft = getImagePanel(LEFT_PANEL_IMAGE_PATH, ImagePanelStyle.TILED); jPanelLeft.setPreferredSize(new Dimension(LEFT_RIGHT_PAGES_WIDTH, 0)); jPanelLeft.setLayout(null); - jPanelCenter = getImagePanel(CENTER_PANEL_IMAGE_PATH, ImagePanel.SCALED); + jPanelCenter = getImagePanel(CENTER_PANEL_IMAGE_PATH, ImagePanelStyle.SCALED); jPanelCenter.setLayout(new BorderLayout()); - jPanelRight = getImagePanel(RIGHT_PANEL_IMAGE_PATH, ImagePanel.TILED); + jPanelRight = getImagePanel(RIGHT_PANEL_IMAGE_PATH, ImagePanelStyle.TILED); jPanelRight.setPreferredSize(new Dimension(LEFT_RIGHT_PAGES_WIDTH, 0)); jPanelRight.setLayout(null); @@ -267,7 +268,7 @@ public class MageBook extends JComponent { return cards.subList(start, end); } - private ImagePanel getImagePanel(String filename, int type) { + private ImagePanel getImagePanel(String filename, ImagePanelStyle type) { try { InputStream is = this.getClass().getResourceAsStream(filename); 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 3fea196ba7..f8cd746698 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java @@ -70,6 +70,7 @@ import mage.client.util.ImageHelper; import mage.client.util.gui.BufferedImageBuilder; import mage.client.util.gui.countryBox.CountryUtil; import mage.components.ImagePanel; +import mage.components.ImagePanelStyle; import mage.constants.CardType; import static mage.constants.Constants.DEFAULT_AVATAR_ID; import static mage.constants.Constants.MAX_AVATAR_ID; @@ -417,7 +418,7 @@ public class PlayerPanelExt extends javax.swing.JPanel { lifeLabel.setToolTipText("Life"); Image imageLife = ImageHelper.getImageFromResources("/info/life.png"); BufferedImage resizedLife = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageLife, BufferedImage.TYPE_INT_ARGB), r); - life = new ImagePanel(resizedLife, ImagePanel.ACTUAL); + life = new ImagePanel(resizedLife, ImagePanelStyle.ACTUAL); life.setToolTipText("Life"); life.setOpaque(false); // hand area @@ -425,7 +426,7 @@ public class PlayerPanelExt extends javax.swing.JPanel { handLabel.setToolTipText("Hand"); Image imageHand = ImageHelper.getImageFromResources("/info/hand.png"); BufferedImage resizedHand = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageHand, BufferedImage.TYPE_INT_ARGB), r); - hand = new ImagePanel(resizedHand, ImagePanel.ACTUAL); + hand = new ImagePanel(resizedHand, ImagePanelStyle.ACTUAL); hand.setToolTipText("Hand"); hand.setOpaque(false); @@ -435,7 +436,7 @@ public class PlayerPanelExt extends javax.swing.JPanel { poisonLabel.setToolTipText("Poison"); Image imagePoison = ImageHelper.getImageFromResources("/info/poison.png"); BufferedImage resizedPoison = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imagePoison, BufferedImage.TYPE_INT_ARGB), r); - poison = new ImagePanel(resizedPoison, ImagePanel.ACTUAL); + poison = new ImagePanel(resizedPoison, ImagePanelStyle.ACTUAL); poison.setToolTipText("Poison"); poison.setOpaque(false); @@ -512,7 +513,7 @@ public class PlayerPanelExt extends javax.swing.JPanel { energyLabel.setToolTipText("Energy"); Image imageEnergy = ImageHelper.getImageFromResources("/info/energy.png"); BufferedImage resizedEnergy = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageEnergy, BufferedImage.TYPE_INT_ARGB), r); - energy = new ImagePanel(resizedEnergy, ImagePanel.ACTUAL); + energy = new ImagePanel(resizedEnergy, ImagePanelStyle.ACTUAL); energy.setToolTipText("Energy"); energy.setOpaque(false); @@ -522,7 +523,7 @@ public class PlayerPanelExt extends javax.swing.JPanel { experienceLabel.setToolTipText("Experience"); Image imageExperience = ImageHelper.getImageFromResources("/info/experience.png"); BufferedImage resizedExperience = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(imageExperience, BufferedImage.TYPE_INT_ARGB), r); - experience = new ImagePanel(resizedExperience, ImagePanel.ACTUAL); + experience = new ImagePanel(resizedExperience, ImagePanelStyle.ACTUAL); experience.setToolTipText("Experience"); experience.setOpaque(false); diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelComponentImpl.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelComponentImpl.java index cbd208feab..1e9e227f62 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelComponentImpl.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardPanelComponentImpl.java @@ -7,6 +7,7 @@ import mage.client.dialog.PreferencesDialog; import mage.client.util.ImageCaches; import mage.client.util.ImageHelper; import mage.components.ImagePanel; +import mage.components.ImagePanelStyle; import mage.constants.AbilityType; import mage.utils.CardUtil; import mage.view.CardView; @@ -243,7 +244,7 @@ public class CardPanelComponentImpl extends CardPanel { // Sickness overlay BufferedImage sickness = ImageManagerImpl.getInstance().getSicknessImage(); - overlayPanel = new ImagePanel(sickness, ImagePanel.SCALED); + overlayPanel = new ImagePanel(sickness, ImagePanelStyle.SCALED); overlayPanel.setOpaque(false); add(overlayPanel); diff --git a/Mage.Client/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java b/Mage.Client/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java index f51fe8b54f..f5a6a60138 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java +++ b/Mage.Client/src/main/java/org/mage/plugins/theme/ThemePluginImpl.java @@ -8,6 +8,7 @@ import javax.imageio.ImageIO; import javax.swing.*; import mage.client.dialog.PreferencesDialog; import mage.components.ImagePanel; +import mage.components.ImagePanelStyle; import mage.interfaces.plugin.ThemePlugin; import net.xeoh.plugins.base.annotations.PluginImplementation; import net.xeoh.plugins.base.annotations.events.Init; @@ -82,7 +83,7 @@ public class ThemePluginImpl implements ThemePlugin { } if (ui.containsKey("gamePanel") && ui.containsKey("jLayeredPane")) { - ImagePanel bgPanel = new ImagePanel(backgroundImage, ImagePanel.TILED); + ImagePanel bgPanel = new ImagePanel(backgroundImage, ImagePanelStyle.TILED); unsetOpaque(ui.get("jSplitPane1")); unsetOpaque(ui.get("pnlBattlefield")); @@ -190,7 +191,7 @@ public class ThemePluginImpl implements ThemePlugin { } } } - return new ImagePanel(background, ImagePanel.SCALED); + return new ImagePanel(background, ImagePanelStyle.SCALED); } private void unsetOpaque(JComponent c) { diff --git a/Mage.Common/src/mage/cards/CardDimensions.java b/Mage.Common/src/mage/cards/CardDimensions.java index 746f6a0042..f1d2e29b5f 100644 --- a/Mage.Common/src/mage/cards/CardDimensions.java +++ b/Mage.Common/src/mage/cards/CardDimensions.java @@ -31,7 +31,6 @@ package mage.cards; import static mage.constants.Constants.*; /** - * * @author BetaSteward_at_googlemail.com */ public class CardDimensions { @@ -51,19 +50,19 @@ public class CardDimensions { public int nameFontSize; public CardDimensions(double scaleFactor) { - frameHeight = (int)(FRAME_MAX_HEIGHT * scaleFactor); - frameWidth = (int)(FRAME_MAX_WIDTH * scaleFactor); - symbolHeight = (int)(SYMBOL_MAX_HEIGHT * scaleFactor); - symbolWidth = (int)(SYMBOL_MAX_WIDTH * scaleFactor); - contentXOffset = (int)(CONTENT_MAX_XOFFSET * scaleFactor); - nameYOffset = (int)(NAME_MAX_YOFFSET * scaleFactor); - typeYOffset = (int)(TYPE_MAX_YOFFSET * scaleFactor); - textYOffset = (int)(TEXT_MAX_YOFFSET * scaleFactor); - textWidth = (int)(TEXT_MAX_WIDTH * scaleFactor); - textHeight = (int)(TEXT_MAX_HEIGHT * scaleFactor); - powBoxTextTop = (int)(POWBOX_TEXT_MAX_TOP * scaleFactor); - powBoxTextLeft = (int)(POWBOX_TEXT_MAX_LEFT * scaleFactor); - nameFontSize = Math.max(9, (int)(NAME_FONT_MAX_SIZE * scaleFactor)); + frameHeight = (int) (FRAME_MAX_HEIGHT * scaleFactor); + frameWidth = (int) (FRAME_MAX_WIDTH * scaleFactor); + symbolHeight = (int) (SYMBOL_MAX_HEIGHT * scaleFactor); + symbolWidth = (int) (SYMBOL_MAX_WIDTH * scaleFactor); + contentXOffset = (int) (CONTENT_MAX_XOFFSET * scaleFactor); + nameYOffset = (int) (NAME_MAX_YOFFSET * scaleFactor); + typeYOffset = (int) (TYPE_MAX_YOFFSET * scaleFactor); + textYOffset = (int) (TEXT_MAX_YOFFSET * scaleFactor); + textWidth = (int) (TEXT_MAX_WIDTH * scaleFactor); + textHeight = (int) (TEXT_MAX_HEIGHT * scaleFactor); + powBoxTextTop = (int) (POWBOX_TEXT_MAX_TOP * scaleFactor); + powBoxTextLeft = (int) (POWBOX_TEXT_MAX_LEFT * scaleFactor); + nameFontSize = Math.max(9, (int) (NAME_FONT_MAX_SIZE * scaleFactor)); } } diff --git a/Mage.Common/src/mage/components/ImagePanel.java b/Mage.Common/src/mage/components/ImagePanel.java index f6263e6c04..c71e0dd654 100644 --- a/Mage.Common/src/mage/components/ImagePanel.java +++ b/Mage.Common/src/mage/components/ImagePanel.java @@ -9,20 +9,18 @@ import javax.swing.JViewport; @SuppressWarnings("serial") public class ImagePanel extends JPanel { - public static final int TILED = 0; - public static final int SCALED = 1; - public static final int ACTUAL = 2; + private BufferedImage image; - private int style; + private ImagePanelStyle style; private float alignmentX = 0.5f; private float alignmentY = 0.5f; public ImagePanel(BufferedImage image) { - this(image, TILED); + this(image, ImagePanelStyle.TILED); } - public ImagePanel(BufferedImage image, int style) { + public ImagePanel(BufferedImage image, ImagePanelStyle style) { this.image = image; this.style = style; setLayout(new BorderLayout()); @@ -65,18 +63,16 @@ public class ImagePanel extends JPanel { return; switch (style) { - case TILED: - drawTiled(g); - break; - - case SCALED: - Dimension d = getSize(); - g.drawImage(image, 0, 0, d.width, d.height, null); - break; - - case ACTUAL: - drawActual(g); - break; + case TILED: + drawTiled(g); + break; + case SCALED: + Dimension d = getSize(); + g.drawImage(image, 0, 0, d.width, d.height, null); + break; + case ACTUAL: + drawActual(g); + break; } } diff --git a/Mage.Common/src/mage/components/ImagePanelStyle.java b/Mage.Common/src/mage/components/ImagePanelStyle.java new file mode 100644 index 0000000000..01e1b4557b --- /dev/null +++ b/Mage.Common/src/mage/components/ImagePanelStyle.java @@ -0,0 +1,8 @@ +package mage.components; + +/** + * Created by IGOUDT on 7-3-2017. + */ +public enum ImagePanelStyle { + TILED, SCALED, ACTUAL +} diff --git a/Mage.Common/src/mage/interfaces/ServerState.java b/Mage.Common/src/mage/interfaces/ServerState.java index 83e0ddbbf4..8208b44f03 100644 --- a/Mage.Common/src/mage/interfaces/ServerState.java +++ b/Mage.Common/src/mage/interfaces/ServerState.java @@ -31,12 +31,13 @@ package mage.interfaces; import java.io.Serializable; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; + import mage.utils.MageVersion; import mage.view.GameTypeView; import mage.view.TournamentTypeView; /** - * * @author BetaSteward_at_googlemail.com */ public class ServerState implements Serializable { @@ -52,8 +53,8 @@ public class ServerState implements Serializable { private final long expansionsContentVersion; public ServerState(List gameTypes, List tournamentTypes, - String[] playerTypes, String[] deckTypes, String[] draftCubes, boolean testMode, - MageVersion version, long cardsContentVersion, long expansionsContentVersion) { + String[] playerTypes, String[] deckTypes, String[] draftCubes, boolean testMode, + MageVersion version, long cardsContentVersion, long expansionsContentVersion) { this.gameTypes = gameTypes; this.tournamentTypes = tournamentTypes; this.playerTypes = playerTypes; @@ -71,13 +72,9 @@ public class ServerState implements Serializable { } public List getTournamentGameTypes() { - List tournamentGameTypes = new ArrayList<>(); - for(GameTypeView gameTypeView: gameTypes) { - if (gameTypeView.getMinPlayers() == 2 && gameTypeView.getMaxPlayers() == 2) { - tournamentGameTypes.add(gameTypeView); - } - } - return tournamentGameTypes; + return gameTypes.stream() + .filter(gameTypeView -> gameTypeView.getMinPlayers() == 2 && gameTypeView.getMaxPlayers() == 2) + .collect(Collectors.toList()); } public List getTournamentTypes() { @@ -111,5 +108,5 @@ public class ServerState implements Serializable { public long getExpansionsContentVersion() { return expansionsContentVersion; } - + }