From 6577e641e6da9b77bc39371def771e1efe376bdf Mon Sep 17 00:00:00 2001 From: vraskulin Date: Thu, 29 Dec 2016 14:46:34 +0300 Subject: [PATCH 1/5] Deprected methods changed with more up-to-date ones --- .../src/main/java/mage/client/dialog/PreferencesDialog.java | 4 ++-- .../src/main/java/mage/server/console/ConsoleFrame.java | 2 +- .../src/main/java/mage/server/console/ConsolePanel.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index ea503a473d..fc2fb9b769 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -2608,7 +2608,7 @@ public class PreferencesDialog extends javax.swing.JDialog { tabsPanel.addTab("Controls", tabControls); - saveButton.setLabel("Save"); + saveButton.setText("Save"); saveButton.setMaximumSize(new java.awt.Dimension(100, 30)); saveButton.setMinimumSize(new java.awt.Dimension(100, 30)); saveButton.setPreferredSize(new java.awt.Dimension(100, 30)); @@ -2619,7 +2619,7 @@ public class PreferencesDialog extends javax.swing.JDialog { } }); - exitButton.setLabel("Exit"); + exitButton.setText("Exit"); exitButton.setMaximumSize(new java.awt.Dimension(100, 30)); exitButton.setMinimumSize(new java.awt.Dimension(100, 30)); exitButton.setPreferredSize(new java.awt.Dimension(100, 30)); diff --git a/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.java b/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.java index 2c9faf2ffa..1e2a0a92e5 100644 --- a/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.java +++ b/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.java @@ -168,7 +168,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient { btnSendMessage.setEnabled(false); btnSendMessage.setFocusable(false); btnSendMessage.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnSendMessage.setLabel("Send Message"); + btnSendMessage.setText("Send Message"); btnSendMessage.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); btnSendMessage.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { diff --git a/Mage.Server.Console/src/main/java/mage/server/console/ConsolePanel.java b/Mage.Server.Console/src/main/java/mage/server/console/ConsolePanel.java index 913fe1c89e..d272053f9b 100644 --- a/Mage.Server.Console/src/main/java/mage/server/console/ConsolePanel.java +++ b/Mage.Server.Console/src/main/java/mage/server/console/ConsolePanel.java @@ -276,7 +276,7 @@ public class ConsolePanel extends javax.swing.JPanel { .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE) ); - btnRemoveTable.setLabel("Remove Table"); + btnRemoveTable.setText("Remove Table"); btnRemoveTable.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnRemoveTableActionPerformed(evt); From c526306c5bbb1372c98b5bf73f8908569d37637e Mon Sep 17 00:00:00 2001 From: vraskulin Date: Thu, 29 Dec 2016 15:26:19 +0300 Subject: [PATCH 2/5] Refactoring See github line by line comments in 'File changed' --- Mage/src/main/java/mage/cards/Card.java | 2 +- Mage/src/main/java/mage/cards/CardImpl.java | 4 ++-- Mage/src/main/java/mage/cards/LevelerCard.java | 1 - Mage/src/main/java/mage/cards/Sets.java | 10 ++++------ Mage/src/main/java/mage/cards/SplitCard.java | 1 - Mage/src/main/java/mage/cards/SplitCardHalfImpl.java | 1 - .../src/main/java/mage/cards/basiclands/BasicLand.java | 1 - Mage/src/main/java/mage/cards/decks/DeckCardInfo.java | 2 +- .../java/mage/cards/decks/importer/DeckImporter.java | 9 ++------- .../mage/cards/decks/importer/MWSDeckImporter.java | 5 ++--- .../mage/cards/repository/ExpansionRepository.java | 10 +++++++++- 11 files changed, 21 insertions(+), 25 deletions(-) diff --git a/Mage/src/main/java/mage/cards/Card.java b/Mage/src/main/java/mage/cards/Card.java index 672bdd9f4d..24d006f9ba 100644 --- a/Mage/src/main/java/mage/cards/Card.java +++ b/Mage/src/main/java/mage/cards/Card.java @@ -53,7 +53,7 @@ public interface Card extends MageObject { void setOwnerId(UUID ownerId); - public Abilities getAbilities(Game game); + Abilities getAbilities(Game game); void setSpellAbility(SpellAbility ability); diff --git a/Mage/src/main/java/mage/cards/CardImpl.java b/Mage/src/main/java/mage/cards/CardImpl.java index 9d5fed0057..f85dfb0c52 100644 --- a/Mage/src/main/java/mage/cards/CardImpl.java +++ b/Mage/src/main/java/mage/cards/CardImpl.java @@ -462,9 +462,9 @@ public abstract class CardImpl extends MageObjectImpl implements Card { } break; case COMMAND: - lkiObject = (Commander) game.getObject(objectId); + lkiObject = game.getObject(objectId); if (lkiObject != null) { - removed = game.getState().getCommand().remove((Commander) game.getObject(objectId)); + removed = game.getState().getCommand().remove(game.getObject(objectId)); } break; case OUTSIDE: diff --git a/Mage/src/main/java/mage/cards/LevelerCard.java b/Mage/src/main/java/mage/cards/LevelerCard.java index c25aff9599..bbcafa205e 100644 --- a/Mage/src/main/java/mage/cards/LevelerCard.java +++ b/Mage/src/main/java/mage/cards/LevelerCard.java @@ -30,7 +30,6 @@ package mage.cards; import java.util.UUID; import mage.constants.CardType; -import mage.constants.Rarity; /** * diff --git a/Mage/src/main/java/mage/cards/Sets.java b/Mage/src/main/java/mage/cards/Sets.java index 9e1f648aa3..4ea294f199 100644 --- a/Mage/src/main/java/mage/cards/Sets.java +++ b/Mage/src/main/java/mage/cards/Sets.java @@ -65,6 +65,7 @@ public class Sets extends HashMap { try { addSet((ExpansionSet) c.getMethod("getInstance").invoke(null)); } catch (Exception ex) { + logger.error(ex); } } } @@ -142,10 +143,9 @@ public class Sets extends HashMap { } public static void saveDeck(String file, DeckCardLists deck) throws FileNotFoundException { - PrintWriter out = new PrintWriter(file); Map deckCards = new HashMap<>(); Map sideboard = new HashMap<>(); - try { + try (PrintWriter out = new PrintWriter(file)) { if (deck.getName() != null && deck.getName().length() > 0) { out.println("NAME:" + deck.getName()); } @@ -169,10 +169,10 @@ public class Sets extends HashMap { } // Write out all of the cards - for (Map.Entry entry : deckCards.entrySet()) { + for (Entry entry : deckCards.entrySet()) { out.printf("%d [%s:%s] %s%n", entry.getValue().getQuantity(), entry.getValue().getSetCode(), entry.getValue().getCardNum(), entry.getValue().getCardName()); } - for (Map.Entry entry : sideboard.entrySet()) { + for (Entry entry : sideboard.entrySet()) { out.printf("SB: %d [%s:%s] %s%n", entry.getValue().getQuantity(), entry.getValue().getSetCode(), entry.getValue().getCardNum(), entry.getValue().getCardName()); } @@ -183,8 +183,6 @@ public class Sets extends HashMap { out.print("LAYOUT SIDEBOARD:"); writeCardLayout(out, deck.getSideboardLayout()); out.print("\n"); - } finally { - out.close(); } } diff --git a/Mage/src/main/java/mage/cards/SplitCard.java b/Mage/src/main/java/mage/cards/SplitCard.java index 67fd339042..3eefebf443 100644 --- a/Mage/src/main/java/mage/cards/SplitCard.java +++ b/Mage/src/main/java/mage/cards/SplitCard.java @@ -35,7 +35,6 @@ import mage.abilities.AbilitiesImpl; import mage.abilities.Ability; import mage.abilities.SpellAbility; import mage.constants.CardType; -import mage.constants.Rarity; import mage.constants.SpellAbilityType; import mage.constants.Zone; import mage.game.Game; diff --git a/Mage/src/main/java/mage/cards/SplitCardHalfImpl.java b/Mage/src/main/java/mage/cards/SplitCardHalfImpl.java index 2c26ac7104..0dcb22f2d6 100644 --- a/Mage/src/main/java/mage/cards/SplitCardHalfImpl.java +++ b/Mage/src/main/java/mage/cards/SplitCardHalfImpl.java @@ -8,7 +8,6 @@ package mage.cards; import java.util.ArrayList; import java.util.UUID; import mage.constants.CardType; -import mage.constants.Rarity; import mage.constants.SpellAbilityType; import mage.constants.Zone; import mage.game.Game; diff --git a/Mage/src/main/java/mage/cards/basiclands/BasicLand.java b/Mage/src/main/java/mage/cards/basiclands/BasicLand.java index 8e5ff7793d..b83da19263 100644 --- a/Mage/src/main/java/mage/cards/basiclands/BasicLand.java +++ b/Mage/src/main/java/mage/cards/basiclands/BasicLand.java @@ -32,7 +32,6 @@ import java.util.UUID; import mage.cards.CardSetInfo; import mage.constants.CardType; -import mage.constants.Rarity; import mage.abilities.mana.ActivatedManaAbilityImpl; import mage.cards.CardImpl; diff --git a/Mage/src/main/java/mage/cards/decks/DeckCardInfo.java b/Mage/src/main/java/mage/cards/decks/DeckCardInfo.java index 65a6216c35..bbde8f4443 100644 --- a/Mage/src/main/java/mage/cards/decks/DeckCardInfo.java +++ b/Mage/src/main/java/mage/cards/decks/DeckCardInfo.java @@ -74,7 +74,7 @@ public class DeckCardInfo implements Serializable { } public String getCardKey() { - return new StringBuilder(setCode).append(cardNum).toString(); + return setCode + cardNum; } } diff --git a/Mage/src/main/java/mage/cards/decks/importer/DeckImporter.java b/Mage/src/main/java/mage/cards/decks/importer/DeckImporter.java index 0f50787b9a..b33821f271 100644 --- a/Mage/src/main/java/mage/cards/decks/importer/DeckImporter.java +++ b/Mage/src/main/java/mage/cards/decks/importer/DeckImporter.java @@ -53,8 +53,7 @@ public abstract class DeckImporter { lineCount = 0; sbMessage.setLength(0); try { - Scanner scanner = new Scanner(f); - try { + try (Scanner scanner = new Scanner(f)) { while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); lineCount++; @@ -63,13 +62,9 @@ public abstract class DeckImporter { if (sbMessage.length() > 0) { logger.fatal(sbMessage); } - } - catch (Exception ex) { + } catch (Exception ex) { logger.fatal(null, ex); } - finally { - scanner.close(); - } } catch (Exception ex) { logger.fatal(null, ex); } diff --git a/Mage/src/main/java/mage/cards/decks/importer/MWSDeckImporter.java b/Mage/src/main/java/mage/cards/decks/importer/MWSDeckImporter.java index 54a9a6eb52..fed0aa179f 100644 --- a/Mage/src/main/java/mage/cards/decks/importer/MWSDeckImporter.java +++ b/Mage/src/main/java/mage/cards/decks/importer/MWSDeckImporter.java @@ -28,7 +28,7 @@ package mage.cards.decks.importer; import java.util.List; -import java.util.Random; + import mage.cards.decks.DeckCardInfo; import mage.cards.decks.DeckCardLists; import mage.cards.repository.CardCriteria; @@ -69,8 +69,7 @@ public class MWSDeckImporter extends DeckImporter { CardCriteria criteria = new CardCriteria(); criteria.name(lineName); criteria.setCodes(setCode); - List cards = null; - cards = CardRepository.instance.findCards(criteria); + List cards = CardRepository.instance.findCards(criteria); if (!cards.isEmpty()) { cardInfo = cards.get(RandomUtil.nextInt(cards.size())); } diff --git a/Mage/src/main/java/mage/cards/repository/ExpansionRepository.java b/Mage/src/main/java/mage/cards/repository/ExpansionRepository.java index b1fcecfda8..f63fce60aa 100644 --- a/Mage/src/main/java/mage/cards/repository/ExpansionRepository.java +++ b/Mage/src/main/java/mage/cards/repository/ExpansionRepository.java @@ -33,7 +33,7 @@ public enum ExpansionRepository { private Dao expansionDao; - private ExpansionRepository() { + ExpansionRepository() { File file = new File("db"); if (!file.exists()) { file.mkdirs(); @@ -57,6 +57,7 @@ public enum ExpansionRepository { try { expansionDao.create(expansion); } catch (SQLException ex) { + logger.error(ex); } } @@ -83,6 +84,7 @@ public enum ExpansionRepository { List expansions = expansionDao.query(qb.prepare()); sets = expansions.toArray(new ExpansionInfo[0]); } catch (SQLException ex) { + logger.error(ex); } return sets; } @@ -95,6 +97,7 @@ public enum ExpansionRepository { qb.where().eq("basicLands", new SelectArg(true)); sets = expansionDao.query(qb.prepare()); } catch (SQLException ex) { + logger.error(ex); } return sets; } @@ -106,6 +109,7 @@ public enum ExpansionRepository { qb.where().eq("blockName", new SelectArg(blockName)); return expansionDao.query(qb.prepare()); } catch (SQLException ex) { + logger.error(ex); } return sets; } @@ -120,6 +124,7 @@ public enum ExpansionRepository { set = expansions.get(0); } } catch (SQLException ex) { + logger.error(ex); } return set; } @@ -134,6 +139,7 @@ public enum ExpansionRepository { set = expansions.get(0); } } catch (SQLException ex) { + logger.error(ex); } return set; } @@ -144,6 +150,7 @@ public enum ExpansionRepository { qb.orderBy("releaseDate", true); return expansionDao.query(qb.prepare()); } catch (SQLException ex) { + logger.error(ex); } return Collections.emptyList(); } @@ -159,6 +166,7 @@ public enum ExpansionRepository { } return setNames; } catch (SQLException ex) { + logger.error(ex); } return Collections.emptyList(); } From 01bb9572e9932dd553adeee6a3eaed1f65ef34a9 Mon Sep 17 00:00:00 2001 From: vraskulin Date: Thu, 29 Dec 2016 15:38:22 +0300 Subject: [PATCH 3/5] Refactoring See github line by line comments in 'File changed' --- Mage/src/main/java/mage/choices/ChoiceImpl.java | 2 +- .../src/main/java/mage/constants/DependencyType.java | 2 +- Mage/src/main/java/mage/constants/ManaType.java | 2 +- .../src/main/java/mage/constants/MatchTimeLimit.java | 4 ++-- .../main/java/mage/constants/RangeOfInfluence.java | 2 +- .../main/java/mage/constants/SetTargetPointer.java | 2 +- Mage/src/main/java/mage/counters/BoostCounter.java | 4 ++-- Mage/src/main/java/mage/counters/Counter.java | 5 +---- Mage/src/main/java/mage/counters/CounterType.java | 2 +- .../src/main/java/mage/designations/Designation.java | 2 +- .../common/FilterControlledCreatureInPlay.java | 2 +- .../mage/filter/common/FilterCreatureOrPlayer.java | 2 +- .../mage/filter/common/FilterPermanentOrPlayer.java | 4 ++-- .../filter/common/FilterPlaneswalkerOrPlayer.java | 4 ++-- .../java/mage/filter/predicate/ObjectPlayer.java | 4 ++-- .../mage/filter/predicate/ObjectSourcePlayer.java | 2 +- .../main/java/mage/filter/predicate/Predicates.java | 12 ++++++------ .../predicate/mageobject/FromSetPredicate.java | 2 +- .../predicate/permanent/AttachedToPredicate.java | 2 +- .../permanent/ControllerControlsIslandPredicate.java | 2 +- .../predicate/permanent/PermanentIdPredicate.java | 2 +- 21 files changed, 31 insertions(+), 34 deletions(-) diff --git a/Mage/src/main/java/mage/choices/ChoiceImpl.java b/Mage/src/main/java/mage/choices/ChoiceImpl.java index bf8375c645..bee47239a8 100644 --- a/Mage/src/main/java/mage/choices/ChoiceImpl.java +++ b/Mage/src/main/java/mage/choices/ChoiceImpl.java @@ -41,7 +41,7 @@ import java.util.Set; public class ChoiceImpl implements Choice, Serializable { protected boolean chosen; - protected boolean required; + protected final boolean required; protected String choice; protected String choiceKey; protected Set choices = new LinkedHashSet<>(); diff --git a/Mage/src/main/java/mage/constants/DependencyType.java b/Mage/src/main/java/mage/constants/DependencyType.java index 4141c330cf..d5ada875ed 100644 --- a/Mage/src/main/java/mage/constants/DependencyType.java +++ b/Mage/src/main/java/mage/constants/DependencyType.java @@ -48,5 +48,5 @@ public enum DependencyType { BecomePlains, BecomeSwamp, EnchantmentAddingRemoving, - LooseDefenderEffect; + LooseDefenderEffect } diff --git a/Mage/src/main/java/mage/constants/ManaType.java b/Mage/src/main/java/mage/constants/ManaType.java index e4da25c96a..3539dbfd6e 100644 --- a/Mage/src/main/java/mage/constants/ManaType.java +++ b/Mage/src/main/java/mage/constants/ManaType.java @@ -24,4 +24,4 @@ public enum ManaType { public String toString() { return text; } -}; +} diff --git a/Mage/src/main/java/mage/constants/MatchTimeLimit.java b/Mage/src/main/java/mage/constants/MatchTimeLimit.java index 00fe3c3179..1d034bc3d9 100644 --- a/Mage/src/main/java/mage/constants/MatchTimeLimit.java +++ b/Mage/src/main/java/mage/constants/MatchTimeLimit.java @@ -19,8 +19,8 @@ public enum MatchTimeLimit { MIN__90(5400, "90 Minutes"), MIN_120(7200, "120 Minutes"); - private int matchSeconds; - private String name; + private final int matchSeconds; + private final String name; MatchTimeLimit(int matchSeconds, String name) { this.matchSeconds = matchSeconds; diff --git a/Mage/src/main/java/mage/constants/RangeOfInfluence.java b/Mage/src/main/java/mage/constants/RangeOfInfluence.java index 7ed7ca58c2..398c9ba921 100644 --- a/Mage/src/main/java/mage/constants/RangeOfInfluence.java +++ b/Mage/src/main/java/mage/constants/RangeOfInfluence.java @@ -9,7 +9,7 @@ public enum RangeOfInfluence { TWO(2), ALL(0); - private int range; + private final int range; RangeOfInfluence(int range) { this.range = range; diff --git a/Mage/src/main/java/mage/constants/SetTargetPointer.java b/Mage/src/main/java/mage/constants/SetTargetPointer.java index 33014b5446..04c3afb924 100644 --- a/Mage/src/main/java/mage/constants/SetTargetPointer.java +++ b/Mage/src/main/java/mage/constants/SetTargetPointer.java @@ -33,5 +33,5 @@ package mage.constants; */ public enum SetTargetPointer { - NONE, PLAYER, SPELL, CARD, PERMANENT, ATTACHED_TO_CONTROLLER; + NONE, PLAYER, SPELL, CARD, PERMANENT, ATTACHED_TO_CONTROLLER } diff --git a/Mage/src/main/java/mage/counters/BoostCounter.java b/Mage/src/main/java/mage/counters/BoostCounter.java index 8b25e647c8..70f0f99467 100644 --- a/Mage/src/main/java/mage/counters/BoostCounter.java +++ b/Mage/src/main/java/mage/counters/BoostCounter.java @@ -34,8 +34,8 @@ package mage.counters; */ public class BoostCounter extends Counter { - protected int power; - protected int toughness; + protected final int power; + protected final int toughness; public BoostCounter(int power, int toughness) { this(power, toughness, 1); diff --git a/Mage/src/main/java/mage/counters/Counter.java b/Mage/src/main/java/mage/counters/Counter.java index 67b19e08bd..53ee5c039d 100644 --- a/Mage/src/main/java/mage/counters/Counter.java +++ b/Mage/src/main/java/mage/counters/Counter.java @@ -158,10 +158,7 @@ public class Counter implements Serializable { Counter counter = (Counter) o; - if (count != counter.count) { - return false; - } - return !(name != null ? !name.equals(counter.name) : counter.name != null); + return count == counter.count && !(name != null ? !name.equals(counter.name) : counter.name != null); } diff --git a/Mage/src/main/java/mage/counters/CounterType.java b/Mage/src/main/java/mage/counters/CounterType.java index 87ddf281ad..676e812ad6 100644 --- a/Mage/src/main/java/mage/counters/CounterType.java +++ b/Mage/src/main/java/mage/counters/CounterType.java @@ -123,7 +123,7 @@ public enum CounterType { private final String name; - private CounterType(String name) { + CounterType(String name) { this.name = name; } diff --git a/Mage/src/main/java/mage/designations/Designation.java b/Mage/src/main/java/mage/designations/Designation.java index ecf203ff47..81e5682194 100644 --- a/Mage/src/main/java/mage/designations/Designation.java +++ b/Mage/src/main/java/mage/designations/Designation.java @@ -31,7 +31,7 @@ public abstract class Designation implements MageObject { private static List emptyList = new ArrayList(); private static ObjectColor emptyColor = new ObjectColor(); - private static ManaCosts emptyCost = new ManaCostsImpl(); + private static ManaCosts emptyCost = new ManaCostsImpl(); private String name; private UUID id; diff --git a/Mage/src/main/java/mage/filter/common/FilterControlledCreatureInPlay.java b/Mage/src/main/java/mage/filter/common/FilterControlledCreatureInPlay.java index e063469fc1..b25a7e7292 100644 --- a/Mage/src/main/java/mage/filter/common/FilterControlledCreatureInPlay.java +++ b/Mage/src/main/java/mage/filter/common/FilterControlledCreatureInPlay.java @@ -41,7 +41,7 @@ import mage.game.permanent.Permanent; */ public class FilterControlledCreatureInPlay extends FilterImpl implements FilterInPlay { - protected FilterCreaturePermanent creatureFilter; + protected final FilterCreaturePermanent creatureFilter; public FilterControlledCreatureInPlay() { this("creature"); diff --git a/Mage/src/main/java/mage/filter/common/FilterCreatureOrPlayer.java b/Mage/src/main/java/mage/filter/common/FilterCreatureOrPlayer.java index 80a28be2eb..865e4cc5d6 100644 --- a/Mage/src/main/java/mage/filter/common/FilterCreatureOrPlayer.java +++ b/Mage/src/main/java/mage/filter/common/FilterCreatureOrPlayer.java @@ -43,7 +43,7 @@ import mage.players.Player; public class FilterCreatureOrPlayer extends FilterImpl implements FilterInPlay { protected FilterCreaturePermanent creatureFilter; - protected FilterPlayer playerFilter; + protected final FilterPlayer playerFilter; public FilterCreatureOrPlayer() { this("creature or player"); diff --git a/Mage/src/main/java/mage/filter/common/FilterPermanentOrPlayer.java b/Mage/src/main/java/mage/filter/common/FilterPermanentOrPlayer.java index af06e5bd17..d4e024f476 100644 --- a/Mage/src/main/java/mage/filter/common/FilterPermanentOrPlayer.java +++ b/Mage/src/main/java/mage/filter/common/FilterPermanentOrPlayer.java @@ -42,8 +42,8 @@ import mage.players.Player; */ public class FilterPermanentOrPlayer extends FilterImpl implements FilterInPlay { - protected FilterPermanent permanentFilter; - protected FilterPlayer playerFilter; + protected final FilterPermanent permanentFilter; + protected final FilterPlayer playerFilter; public FilterPermanentOrPlayer() { this("player or permanent"); diff --git a/Mage/src/main/java/mage/filter/common/FilterPlaneswalkerOrPlayer.java b/Mage/src/main/java/mage/filter/common/FilterPlaneswalkerOrPlayer.java index 025ef20803..f79ed9546c 100644 --- a/Mage/src/main/java/mage/filter/common/FilterPlaneswalkerOrPlayer.java +++ b/Mage/src/main/java/mage/filter/common/FilterPlaneswalkerOrPlayer.java @@ -46,8 +46,8 @@ import mage.players.Player; */ public class FilterPlaneswalkerOrPlayer extends FilterImpl { - protected FilterPlaneswalkerPermanent planeswalkerFilter; - protected FilterPlayer playerFilter; + protected final FilterPlaneswalkerPermanent planeswalkerFilter; + protected final FilterPlayer playerFilter; public FilterPlaneswalkerOrPlayer(Set defenders) { super("planeswalker or player"); diff --git a/Mage/src/main/java/mage/filter/predicate/ObjectPlayer.java b/Mage/src/main/java/mage/filter/predicate/ObjectPlayer.java index 3d0a278f7b..0bb0c44b17 100644 --- a/Mage/src/main/java/mage/filter/predicate/ObjectPlayer.java +++ b/Mage/src/main/java/mage/filter/predicate/ObjectPlayer.java @@ -36,8 +36,8 @@ import java.util.UUID; */ public class ObjectPlayer { - protected T object; - protected UUID playerId; + protected final T object; + protected final UUID playerId; public ObjectPlayer(T object, UUID playerId) { this.object = object; diff --git a/Mage/src/main/java/mage/filter/predicate/ObjectSourcePlayer.java b/Mage/src/main/java/mage/filter/predicate/ObjectSourcePlayer.java index 176a57d698..360af49826 100644 --- a/Mage/src/main/java/mage/filter/predicate/ObjectSourcePlayer.java +++ b/Mage/src/main/java/mage/filter/predicate/ObjectSourcePlayer.java @@ -36,7 +36,7 @@ import java.util.UUID; */ public class ObjectSourcePlayer extends ObjectPlayer { - protected UUID sourceId; + protected final UUID sourceId; public ObjectSourcePlayer(T object, UUID sourceId, UUID playerId) { super(object, playerId); diff --git a/Mage/src/main/java/mage/filter/predicate/Predicates.java b/Mage/src/main/java/mage/filter/predicate/Predicates.java index 00a386a846..103217fbf8 100644 --- a/Mage/src/main/java/mage/filter/predicate/Predicates.java +++ b/Mage/src/main/java/mage/filter/predicate/Predicates.java @@ -168,8 +168,8 @@ public final class Predicates { @Override public boolean apply(T t, Game game) { - for (int i = 0; i < components.size(); i++) { - if (!components.get(i).apply(t, game)) { + for (Predicate component : components) { + if (!component.apply(t, game)) { return false; } } @@ -196,8 +196,8 @@ public final class Predicates { @Override public boolean apply(T t, Game game) { - for (int i = 0; i < components.size(); i++) { - if (components.get(i).apply(t, game)) { + for (Predicate component : components) { + if (component.apply(t, game)) { return true; } } @@ -244,8 +244,8 @@ public final class Predicates { private static String commaJoin(List components) { StringBuilder sb = new StringBuilder(); - for (int i = 0; i < components.size(); i++) { - sb.append(components.get(i).toString()); + for (Object component : components) { + sb.append(component.toString()); } sb.deleteCharAt(sb.length() - 1); return sb.toString(); diff --git a/Mage/src/main/java/mage/filter/predicate/mageobject/FromSetPredicate.java b/Mage/src/main/java/mage/filter/predicate/mageobject/FromSetPredicate.java index d330697e3d..6fc541ee58 100644 --- a/Mage/src/main/java/mage/filter/predicate/mageobject/FromSetPredicate.java +++ b/Mage/src/main/java/mage/filter/predicate/mageobject/FromSetPredicate.java @@ -38,7 +38,7 @@ import mage.game.Game; */ public class FromSetPredicate implements Predicate { - protected Set set; + protected final Set set; public FromSetPredicate(Set set) { this.set = set; diff --git a/Mage/src/main/java/mage/filter/predicate/permanent/AttachedToPredicate.java b/Mage/src/main/java/mage/filter/predicate/permanent/AttachedToPredicate.java index 7d155ffa14..a5bbe26ed4 100644 --- a/Mage/src/main/java/mage/filter/predicate/permanent/AttachedToPredicate.java +++ b/Mage/src/main/java/mage/filter/predicate/permanent/AttachedToPredicate.java @@ -39,7 +39,7 @@ import mage.game.permanent.Permanent; */ public class AttachedToPredicate implements Predicate { - private FilterPermanent filter; + private final FilterPermanent filter; public AttachedToPredicate(FilterPermanent filter) { this.filter = filter; diff --git a/Mage/src/main/java/mage/filter/predicate/permanent/ControllerControlsIslandPredicate.java b/Mage/src/main/java/mage/filter/predicate/permanent/ControllerControlsIslandPredicate.java index 7044879576..8705b89359 100644 --- a/Mage/src/main/java/mage/filter/predicate/permanent/ControllerControlsIslandPredicate.java +++ b/Mage/src/main/java/mage/filter/predicate/permanent/ControllerControlsIslandPredicate.java @@ -41,7 +41,7 @@ import mage.game.permanent.Permanent; public class ControllerControlsIslandPredicate implements Predicate { public static final FilterLandPermanent filter = new FilterLandPermanent("Island"); - { + static { filter.add(new SubtypePredicate("Island")); } diff --git a/Mage/src/main/java/mage/filter/predicate/permanent/PermanentIdPredicate.java b/Mage/src/main/java/mage/filter/predicate/permanent/PermanentIdPredicate.java index 91eb073ee9..268bcc305a 100644 --- a/Mage/src/main/java/mage/filter/predicate/permanent/PermanentIdPredicate.java +++ b/Mage/src/main/java/mage/filter/predicate/permanent/PermanentIdPredicate.java @@ -51,6 +51,6 @@ public class PermanentIdPredicate implements Predicate { @Override public String toString() { - return new StringBuilder("PermanentId(").append(permanentId).append(")").toString() ; + return "PermanentId(" + permanentId + ")"; } } From c0cf22bbf784ce726a82f59f520ee0bcd79daae3 Mon Sep 17 00:00:00 2001 From: vraskulin Date: Thu, 29 Dec 2016 16:16:08 +0300 Subject: [PATCH 4/5] Refactoring See github line by line comments in 'File changed' --- Mage/src/main/java/mage/game/Game.java | 4 ++-- Mage/src/main/java/mage/game/GameImpl.java | 17 ++++++----------- Mage/src/main/java/mage/game/Table.java | 3 +-- .../src/main/java/mage/game/ZoneChangeInfo.java | 1 - Mage/src/main/java/mage/game/ZonesHandler.java | 6 +----- Mage/src/main/java/mage/game/combat/Combat.java | 8 ++++---- .../main/java/mage/game/combat/CombatGroup.java | 2 +- .../main/java/mage/game/draft/DraftCube.java | 2 +- .../main/java/mage/game/events/GameEvent.java | 2 +- Mage/src/main/java/mage/game/match/Match.java | 2 +- .../main/java/mage/game/match/MatchImpl.java | 3 +-- .../java/mage/game/permanent/Permanent.java | 2 +- .../java/mage/game/permanent/PermanentImpl.java | 2 +- .../mage/game/permanent/token/CentaurToken.java | 1 - .../mage/game/permanent/token/DevilToken.java | 4 +++- .../mage/game/permanent/token/DroidToken.java | 4 +++- .../permanent/token/EldraziHorrorToken.java | 3 ++- .../game/permanent/token/EldraziScionToken.java | 2 +- .../game/permanent/token/EldraziSpawnToken.java | 2 +- .../mage/game/permanent/token/EwokToken.java | 4 +++- .../mage/game/permanent/token/PrismToken.java | 3 ++- .../mage/game/permanent/token/ServoToken.java | 3 ++- .../game/permanent/token/SquirrelToken.java | 3 ++- .../mage/game/permanent/token/ThrullToken.java | 3 ++- .../mage/game/permanent/token/TrooperToken.java | 4 +++- .../mage/game/permanent/token/WarriorToken.java | 2 +- .../mage/game/permanent/token/ZombieToken.java | 2 +- .../mage/game/tournament/TournamentImpl.java | 1 - .../tournament/TournamentSingleElimination.java | 1 - Mage/src/main/java/mage/game/turn/Step.java | 2 +- Mage/src/main/java/mage/game/turn/TurnMods.java | 6 +++--- 31 files changed, 51 insertions(+), 53 deletions(-) diff --git a/Mage/src/main/java/mage/game/Game.java b/Mage/src/main/java/mage/game/Game.java index 8670aab12b..e813e7becd 100644 --- a/Mage/src/main/java/mage/game/Game.java +++ b/Mage/src/main/java/mage/game/Game.java @@ -132,7 +132,7 @@ public interface Game extends MageItem, Serializable { void setZone(UUID objectId, Zone zone); - void addPlayer(Player player, Deck deck) throws GameException; + void addPlayer(Player player, Deck deck); Player getPlayer(UUID playerId); @@ -437,7 +437,7 @@ public interface Game extends MageItem, Serializable { // controlling the behaviour of replacement effects while permanents entering the battlefield void setScopeRelevant(boolean scopeRelevant); - public boolean getScopeRelevant(); + boolean getScopeRelevant(); // players' timers void initTimer(UUID playerId); diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index 56ce273b39..df59f51660 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -335,7 +335,7 @@ public abstract class GameImpl implements Game, Serializable { } @Override - public void addPlayer(Player player, Deck deck) throws GameException { + public void addPlayer(Player player, Deck deck) { player.useDeck(deck, this); state.addPlayer(player); } @@ -1937,7 +1937,7 @@ public abstract class GameImpl implements Game, Serializable { Player controller = this.getPlayer(planeswalker.getControllerId()); if (controller != null) { Target targetPlaneswalkerToKeep = new TargetPermanent(filterPlaneswalker); - targetPlaneswalkerToKeep.setTargetName(new StringBuilder(planeswalker.getName()).append(" to keep?").toString()); + targetPlaneswalkerToKeep.setTargetName(planeswalker.getName() + " to keep?"); controller.chooseTarget(Outcome.Benefit, targetPlaneswalkerToKeep, null, this); for (Permanent dupPlaneswalker : this.getBattlefield().getActivePermanents(filterPlaneswalker, planeswalker.getControllerId(), this)) { if (!targetPlaneswalkerToKeep.getTargets().contains(dupPlaneswalker.getId())) { @@ -2345,12 +2345,7 @@ public abstract class GameImpl implements Game, Serializable { } // Then, if that player controlled any objects on the stack not represented by cards, those objects cease to exist. this.getState().getContinuousEffects().removeInactiveEffects(this); - for (Iterator it = getStack().iterator(); it.hasNext();) { - StackObject object = it.next(); - if (object.getControllerId().equals(playerId)) { - it.remove(); - } - } + getStack().removeIf(object -> object.getControllerId().equals(playerId)); // Then, if there are any objects still controlled by that player, those objects are exiled. applyEffects(); // to remove control from effects removed meanwhile List permanents = this.getBattlefield().getAllActivePermanents(playerId); @@ -2594,10 +2589,10 @@ public abstract class GameImpl implements Game, Serializable { if (object instanceof Permanent) { Map lkiExtendedMap = lkiExtended.get(objectId); if (lkiExtendedMap != null) { - lkiExtendedMap.put(((Permanent) object).getZoneChangeCounter(this), copy); + lkiExtendedMap.put(object.getZoneChangeCounter(this), copy); } else { lkiExtendedMap = new HashMap<>(); - lkiExtendedMap.put(((Permanent) object).getZoneChangeCounter(this), copy); + lkiExtendedMap.put(object.getZoneChangeCounter(this), copy); lkiExtended.put(objectId, lkiExtendedMap); } } @@ -2689,7 +2684,7 @@ public abstract class GameImpl implements Game, Serializable { permanent.entersBattlefield(permanent.getId(), this, Zone.OUTSIDE, false); getBattlefield().addPermanent(permanent); getPermanentsEntering().remove(permanent.getId()); - ((PermanentImpl) permanent).removeSummoningSickness(); + permanent.removeSummoningSickness(); if (card.isTapped()) { permanent.setTapped(true); } diff --git a/Mage/src/main/java/mage/game/Table.java b/Mage/src/main/java/mage/game/Table.java index 1d2f2d0604..e9d3152841 100644 --- a/Mage/src/main/java/mage/game/Table.java +++ b/Mage/src/main/java/mage/game/Table.java @@ -64,9 +64,8 @@ public class Table implements Serializable { private TableRecorder recorder; public interface TableRecorder { - void record(Table table); - }; + } protected TableEventSource tableEventSource = new TableEventSource(); diff --git a/Mage/src/main/java/mage/game/ZoneChangeInfo.java b/Mage/src/main/java/mage/game/ZoneChangeInfo.java index 7c8936d0b1..bfbee3a722 100644 --- a/Mage/src/main/java/mage/game/ZoneChangeInfo.java +++ b/Mage/src/main/java/mage/game/ZoneChangeInfo.java @@ -1,7 +1,6 @@ package mage.game; import mage.cards.MeldCard; -import mage.constants.Zone; import mage.game.events.ZoneChangeEvent; import mage.game.stack.Spell; diff --git a/Mage/src/main/java/mage/game/ZonesHandler.java b/Mage/src/main/java/mage/game/ZonesHandler.java index ede698ad58..427095c91b 100644 --- a/Mage/src/main/java/mage/game/ZonesHandler.java +++ b/Mage/src/main/java/mage/game/ZonesHandler.java @@ -52,11 +52,7 @@ public class ZonesHandler { } } } - for (Iterator itr = zoneChangeInfos.iterator(); itr.hasNext();) { - if (!maybeRemoveFromSourceZone(itr.next(), game)) { - itr.remove(); - } - } + zoneChangeInfos.removeIf(zoneChangeInfo -> !maybeRemoveFromSourceZone(zoneChangeInfo, game)); for (ZoneChangeInfo zoneChangeInfo : zoneChangeInfos) { placeInDestinationZone(zoneChangeInfo, game); if (game.getPhase() != null) { // moving cards to zones before game started does not need events diff --git a/Mage/src/main/java/mage/game/combat/Combat.java b/Mage/src/main/java/mage/game/combat/Combat.java index 58c89c0b5b..8156532bed 100644 --- a/Mage/src/main/java/mage/game/combat/Combat.java +++ b/Mage/src/main/java/mage/game/combat/Combat.java @@ -983,7 +983,7 @@ public class Combat implements Serializable, Copyable { for (Ability ability : entry.getValue()) { if (!effect.canBlockCheckAfter(ability, game)) { if (controller.isHuman()) { - game.informPlayer(controller, new StringBuilder(blockingCreature.getLogName()).append(" can't block this way.").toString()); + game.informPlayer(controller, blockingCreature.getLogName() + " can't block this way."); return false; } else { // remove blocking creatures for AI @@ -1003,7 +1003,7 @@ public class Combat implements Serializable, Copyable { for (Ability ability : entry.getValue()) { if (!effect.canBeBlockedCheckAfter(attackingCreature, ability, game)) { if (controller.isHuman()) { - game.informPlayer(controller, new StringBuilder(attackingCreature.getLogName()).append(" can't be blocked this way.").toString()); + game.informPlayer(controller, attackingCreature.getLogName() + " can't be blocked this way."); return false; } else { // remove blocking creatures for AI @@ -1030,7 +1030,7 @@ public class Combat implements Serializable, Copyable { switch (game.getAttackOption()) { case LEFT: players = game.getState().getPlayerList(attackingPlayerId); - while (true && attackingPlayer.isInGame()) { + while (attackingPlayer.isInGame()) { Player opponent = players.getNext(game); if (attackingPlayer.hasOpponent(opponent.getId(), game)) { addDefender(opponent.getId(), game); @@ -1040,7 +1040,7 @@ public class Combat implements Serializable, Copyable { break; case RIGHT: players = game.getState().getPlayerList(attackingPlayerId); - while (true && attackingPlayer.isInGame()) { + while (attackingPlayer.isInGame()) { Player opponent = players.getPrevious(game); if (attackingPlayer.hasOpponent(opponent.getId(), game)) { addDefender(opponent.getId(), game); diff --git a/Mage/src/main/java/mage/game/combat/CombatGroup.java b/Mage/src/main/java/mage/game/combat/CombatGroup.java index c5b64a44e6..713929dcfe 100644 --- a/Mage/src/main/java/mage/game/combat/CombatGroup.java +++ b/Mage/src/main/java/mage/game/combat/CombatGroup.java @@ -457,7 +457,7 @@ public class CombatGroup implements Serializable, Copyable { Player player = game.getPlayer(playerId); List blockerList = new ArrayList<>(blockers); blockerOrder.clear(); - while (true && player.canRespond()) { + while (player.canRespond()) { if (blockerList.size() == 1) { blockerOrder.add(blockerList.get(0)); break; diff --git a/Mage/src/main/java/mage/game/draft/DraftCube.java b/Mage/src/main/java/mage/game/draft/DraftCube.java index 2e8fddc109..dc72fb3cf0 100644 --- a/Mage/src/main/java/mage/game/draft/DraftCube.java +++ b/Mage/src/main/java/mage/game/draft/DraftCube.java @@ -29,7 +29,7 @@ package mage.game.draft; import java.util.ArrayList; import java.util.List; -import java.util.Random; + import mage.cards.Card; import mage.cards.repository.CardCriteria; import mage.cards.repository.CardInfo; diff --git a/Mage/src/main/java/mage/game/events/GameEvent.java b/Mage/src/main/java/mage/game/events/GameEvent.java index ee8e2306e4..a38958c2ea 100644 --- a/Mage/src/main/java/mage/game/events/GameEvent.java +++ b/Mage/src/main/java/mage/game/events/GameEvent.java @@ -302,7 +302,7 @@ public class GameEvent implements Serializable { COMBAT_DAMAGE_APPLIED, SELECTED_ATTACKER, SELECTED_BLOCKER, //custom events - CUSTOM_EVENT; + CUSTOM_EVENT } private GameEvent(EventType type, UUID customEventType, diff --git a/Mage/src/main/java/mage/game/match/Match.java b/Mage/src/main/java/mage/game/match/Match.java index 6fc81ef884..3f0b432902 100644 --- a/Mage/src/main/java/mage/game/match/Match.java +++ b/Mage/src/main/java/mage/game/match/Match.java @@ -62,7 +62,7 @@ public interface Match { void submitDeck(UUID playerId, Deck deck); void updateDeck(UUID playerId, Deck deck); - void startMatch() throws GameException; + void startMatch(); void startGame() throws GameException; void sideboard(); void endGame(); diff --git a/Mage/src/main/java/mage/game/match/MatchImpl.java b/Mage/src/main/java/mage/game/match/MatchImpl.java index d3d4f1091a..28118e7548 100644 --- a/Mage/src/main/java/mage/game/match/MatchImpl.java +++ b/Mage/src/main/java/mage/game/match/MatchImpl.java @@ -31,7 +31,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Random; import java.util.UUID; import mage.cards.decks.Deck; import mage.game.Game; @@ -121,7 +120,7 @@ public abstract class MatchImpl implements Match { } @Override - public void startMatch() throws GameException { + public void startMatch() { this.startTime = new Date(); } diff --git a/Mage/src/main/java/mage/game/permanent/Permanent.java b/Mage/src/main/java/mage/game/permanent/Permanent.java index e97a659107..37f2a7efa2 100644 --- a/Mage/src/main/java/mage/game/permanent/Permanent.java +++ b/Mage/src/main/java/mage/game/permanent/Permanent.java @@ -174,7 +174,7 @@ public interface Permanent extends Card, Controllable { boolean canLoyaltyBeUsed(Game game); - public void resetControl(); + void resetControl(); boolean changeControllerId(UUID controllerId, Game game); diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index 6f292279d1..23f00de982 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -981,7 +981,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { moveToZone(Zone.GRAVEYARD, sourceId, game, false); Player player = game.getPlayer(getControllerId()); if (player != null && !game.isSimulation()) { - game.informPlayers(new StringBuilder(player.getLogName()).append(" sacrificed ").append(this.getLogName()).toString()); + game.informPlayers(player.getLogName() + " sacrificed " + this.getLogName()); } game.fireEvent(GameEvent.getEvent(EventType.SACRIFICED_PERMANENT, objectId, sourceId, controllerId)); return true; diff --git a/Mage/src/main/java/mage/game/permanent/token/CentaurToken.java b/Mage/src/main/java/mage/game/permanent/token/CentaurToken.java index 222201ef11..d36a2886ac 100644 --- a/Mage/src/main/java/mage/game/permanent/token/CentaurToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/CentaurToken.java @@ -28,7 +28,6 @@ package mage.game.permanent.token; -import java.util.Random; import mage.constants.CardType; import mage.MageInt; import mage.util.RandomUtil; diff --git a/Mage/src/main/java/mage/game/permanent/token/DevilToken.java b/Mage/src/main/java/mage/game/permanent/token/DevilToken.java index 5072881c9b..8b3e2cafcc 100644 --- a/Mage/src/main/java/mage/game/permanent/token/DevilToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/DevilToken.java @@ -28,6 +28,8 @@ package mage.game.permanent.token; import java.util.Arrays; +import java.util.Collections; + import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.DiesTriggeredAbility; @@ -44,7 +46,7 @@ public class DevilToken extends Token { public DevilToken() { super("Devil", "1/1 red Devil creature with \"When this creature dies, it deals 1 damage to target creature or player.\""); - availableImageSetCodes.addAll(Arrays.asList("SOI")); + availableImageSetCodes.addAll(Collections.singletonList("SOI")); cardType.add(CardType.CREATURE); subtype.add("Devil"); color.setRed(true); diff --git a/Mage/src/main/java/mage/game/permanent/token/DroidToken.java b/Mage/src/main/java/mage/game/permanent/token/DroidToken.java index 5cac7577df..d9a440efad 100644 --- a/Mage/src/main/java/mage/game/permanent/token/DroidToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/DroidToken.java @@ -28,6 +28,8 @@ package mage.game.permanent.token; import java.util.Arrays; +import java.util.Collections; + import mage.MageInt; import mage.constants.CardType; @@ -39,7 +41,7 @@ public class DroidToken extends Token { public DroidToken() { super("Droid", "1/1 colorless Droid creature token"); - availableImageSetCodes.addAll(Arrays.asList("SWS")); + availableImageSetCodes.addAll(Collections.singletonList("SWS")); cardType.add(CardType.CREATURE); cardType.add(CardType.ARTIFACT); diff --git a/Mage/src/main/java/mage/game/permanent/token/EldraziHorrorToken.java b/Mage/src/main/java/mage/game/permanent/token/EldraziHorrorToken.java index 4ee787aac2..1ec3623b87 100644 --- a/Mage/src/main/java/mage/game/permanent/token/EldraziHorrorToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/EldraziHorrorToken.java @@ -29,6 +29,7 @@ package mage.game.permanent.token; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import mage.MageInt; import mage.constants.CardType; @@ -42,7 +43,7 @@ public class EldraziHorrorToken extends Token { final static private List tokenImageSets = new ArrayList<>(); static { - tokenImageSets.addAll(Arrays.asList("EMN")); + tokenImageSets.addAll(Collections.singletonList("EMN")); } public EldraziHorrorToken() { diff --git a/Mage/src/main/java/mage/game/permanent/token/EldraziScionToken.java b/Mage/src/main/java/mage/game/permanent/token/EldraziScionToken.java index c2564d3669..550e915f11 100644 --- a/Mage/src/main/java/mage/game/permanent/token/EldraziScionToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/EldraziScionToken.java @@ -30,7 +30,7 @@ package mage.game.permanent.token; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Random; + import mage.MageInt; import mage.Mana; import mage.abilities.costs.common.SacrificeSourceCost; diff --git a/Mage/src/main/java/mage/game/permanent/token/EldraziSpawnToken.java b/Mage/src/main/java/mage/game/permanent/token/EldraziSpawnToken.java index 43956bef29..e7fab3ffbe 100644 --- a/Mage/src/main/java/mage/game/permanent/token/EldraziSpawnToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/EldraziSpawnToken.java @@ -30,7 +30,7 @@ package mage.game.permanent.token; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Random; + import mage.MageInt; import mage.Mana; import mage.abilities.costs.common.SacrificeSourceCost; diff --git a/Mage/src/main/java/mage/game/permanent/token/EwokToken.java b/Mage/src/main/java/mage/game/permanent/token/EwokToken.java index fbdaf99040..1d930992c5 100644 --- a/Mage/src/main/java/mage/game/permanent/token/EwokToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/EwokToken.java @@ -28,6 +28,8 @@ package mage.game.permanent.token; import java.util.Arrays; +import java.util.Collections; + import mage.constants.CardType; /** @@ -38,7 +40,7 @@ public class EwokToken extends Token { public EwokToken() { super("Ewok", "1/1 green Ewok creature tokens", 1, 1); - availableImageSetCodes.addAll(Arrays.asList("SWS")); + availableImageSetCodes.addAll(Collections.singletonList("SWS")); cardType.add(CardType.CREATURE); subtype.add("Ewok"); diff --git a/Mage/src/main/java/mage/game/permanent/token/PrismToken.java b/Mage/src/main/java/mage/game/permanent/token/PrismToken.java index b9dd23474a..b59ddd270f 100644 --- a/Mage/src/main/java/mage/game/permanent/token/PrismToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/PrismToken.java @@ -29,6 +29,7 @@ package mage.game.permanent.token; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import mage.MageInt; import mage.constants.CardType; @@ -42,7 +43,7 @@ public class PrismToken extends Token { final static private List tokenImageSets = new ArrayList<>(); static { - tokenImageSets.addAll(Arrays.asList("VIS")); + tokenImageSets.addAll(Collections.singletonList("VIS")); } public PrismToken() { diff --git a/Mage/src/main/java/mage/game/permanent/token/ServoToken.java b/Mage/src/main/java/mage/game/permanent/token/ServoToken.java index 961642ce4b..0c9db5b39f 100644 --- a/Mage/src/main/java/mage/game/permanent/token/ServoToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/ServoToken.java @@ -29,6 +29,7 @@ package mage.game.permanent.token; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import mage.MageInt; import mage.constants.CardType; @@ -43,7 +44,7 @@ public class ServoToken extends Token { final static private List tokenImageSets = new ArrayList<>(); static { - tokenImageSets.addAll(Arrays.asList("KLD")); + tokenImageSets.addAll(Collections.singletonList("KLD")); } public ServoToken() { diff --git a/Mage/src/main/java/mage/game/permanent/token/SquirrelToken.java b/Mage/src/main/java/mage/game/permanent/token/SquirrelToken.java index c8b5e56fdb..77dc0fdaba 100644 --- a/Mage/src/main/java/mage/game/permanent/token/SquirrelToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/SquirrelToken.java @@ -29,6 +29,7 @@ package mage.game.permanent.token; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import mage.MageInt; import mage.constants.CardType; @@ -42,7 +43,7 @@ public class SquirrelToken extends Token { final static private List tokenImageSets = new ArrayList<>(); static { - tokenImageSets.addAll(Arrays.asList("CNS")); + tokenImageSets.addAll(Collections.singletonList("CNS")); } public SquirrelToken() { diff --git a/Mage/src/main/java/mage/game/permanent/token/ThrullToken.java b/Mage/src/main/java/mage/game/permanent/token/ThrullToken.java index 3ce76ac9e2..759a93d201 100644 --- a/Mage/src/main/java/mage/game/permanent/token/ThrullToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/ThrullToken.java @@ -30,6 +30,7 @@ package mage.game.permanent.token; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import mage.MageInt; import mage.constants.CardType; @@ -43,7 +44,7 @@ public class ThrullToken extends Token { final static private List tokenImageSets = new ArrayList<>(); static { - tokenImageSets.addAll(Arrays.asList("MM2")); + tokenImageSets.addAll(Collections.singletonList("MM2")); } public ThrullToken() { diff --git a/Mage/src/main/java/mage/game/permanent/token/TrooperToken.java b/Mage/src/main/java/mage/game/permanent/token/TrooperToken.java index 6f72120ed0..00a5b43e45 100644 --- a/Mage/src/main/java/mage/game/permanent/token/TrooperToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/TrooperToken.java @@ -28,6 +28,8 @@ package mage.game.permanent.token; import java.util.Arrays; +import java.util.Collections; + import mage.MageInt; import mage.constants.CardType; @@ -39,7 +41,7 @@ public class TrooperToken extends Token { public TrooperToken() { super("Trooper", "1/1 white Trooper creature token"); - availableImageSetCodes.addAll(Arrays.asList("SWS")); + availableImageSetCodes.addAll(Collections.singletonList("SWS")); cardType.add(CardType.CREATURE); subtype.add("Trooper"); diff --git a/Mage/src/main/java/mage/game/permanent/token/WarriorToken.java b/Mage/src/main/java/mage/game/permanent/token/WarriorToken.java index 6a34f22d33..f976c9fba0 100644 --- a/Mage/src/main/java/mage/game/permanent/token/WarriorToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/WarriorToken.java @@ -29,7 +29,7 @@ package mage.game.permanent.token; import java.util.Arrays; -import java.util.Random; + import mage.MageInt; import mage.constants.CardType; import mage.util.RandomUtil; diff --git a/Mage/src/main/java/mage/game/permanent/token/ZombieToken.java b/Mage/src/main/java/mage/game/permanent/token/ZombieToken.java index 8da3f8ad3d..0cd8b1b150 100644 --- a/Mage/src/main/java/mage/game/permanent/token/ZombieToken.java +++ b/Mage/src/main/java/mage/game/permanent/token/ZombieToken.java @@ -30,7 +30,7 @@ package mage.game.permanent.token; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Random; + import mage.MageInt; import mage.constants.CardType; import mage.util.RandomUtil; diff --git a/Mage/src/main/java/mage/game/tournament/TournamentImpl.java b/Mage/src/main/java/mage/game/tournament/TournamentImpl.java index b01048d3b6..eecd485654 100644 --- a/Mage/src/main/java/mage/game/tournament/TournamentImpl.java +++ b/Mage/src/main/java/mage/game/tournament/TournamentImpl.java @@ -35,7 +35,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Random; import java.util.UUID; import java.util.concurrent.CopyOnWriteArrayList; import mage.cards.ExpansionSet; diff --git a/Mage/src/main/java/mage/game/tournament/TournamentSingleElimination.java b/Mage/src/main/java/mage/game/tournament/TournamentSingleElimination.java index 742e288ea3..e57de8b70c 100644 --- a/Mage/src/main/java/mage/game/tournament/TournamentSingleElimination.java +++ b/Mage/src/main/java/mage/game/tournament/TournamentSingleElimination.java @@ -28,7 +28,6 @@ package mage.game.tournament; -import java.util.List; import java.util.Map; import java.util.UUID; import mage.constants.MultiplayerAttackOption; diff --git a/Mage/src/main/java/mage/game/turn/Step.java b/Mage/src/main/java/mage/game/turn/Step.java index 0f646ccc69..bf4d50d48b 100644 --- a/Mage/src/main/java/mage/game/turn/Step.java +++ b/Mage/src/main/java/mage/game/turn/Step.java @@ -49,7 +49,7 @@ public abstract class Step implements Serializable { protected StepPart stepPart; public enum StepPart { - PRE, PRIORITY, POST; + PRE, PRIORITY, POST } public abstract Step copy(); diff --git a/Mage/src/main/java/mage/game/turn/TurnMods.java b/Mage/src/main/java/mage/game/turn/TurnMods.java index 947791def9..2fc1a3c1c1 100644 --- a/Mage/src/main/java/mage/game/turn/TurnMods.java +++ b/Mage/src/main/java/mage/game/turn/TurnMods.java @@ -52,7 +52,7 @@ public class TurnMods extends ArrayList { ListIterator it = this.listIterator(this.size()); while (it.hasPrevious()) { TurnMod turnMod = it.previous(); - if (turnMod.isExtraTurn() == true && turnMod.getPlayerId().equals(playerId)) { + if (turnMod.isExtraTurn() && turnMod.getPlayerId().equals(playerId)) { it.remove(); return turnMod.getId(); } @@ -64,7 +64,7 @@ public class TurnMods extends ArrayList { ListIterator it = this.listIterator(this.size()); while (it.hasPrevious()) { TurnMod turnMod = it.previous(); - if (turnMod.isExtraTurn() == true) { + if (turnMod.isExtraTurn()) { it.remove(); return turnMod; } @@ -76,7 +76,7 @@ public class TurnMods extends ArrayList { ListIterator it = this.listIterator(this.size()); while (it.hasPrevious()) { TurnMod turnMod = it.previous(); - if (turnMod.isSkipTurn() == true && turnMod.getPlayerId().equals(playerId)) { + if (turnMod.isSkipTurn() && turnMod.getPlayerId().equals(playerId)) { it.remove(); return true; } From f04ba151f71a1c112cd4fcd37013fa75a0dd8f60 Mon Sep 17 00:00:00 2001 From: vraskulin Date: Thu, 29 Dec 2016 16:49:12 +0300 Subject: [PATCH 5/5] Refactoring See github line by line comments in 'File changed' --- Mage/src/main/java/mage/ConditionalMana.java | 6 ---- Mage/src/main/java/mage/MageInt.java | 2 +- Mage/src/main/java/mage/players/Library.java | 2 +- .../main/java/mage/players/ManaPoolItem.java | 5 ---- .../main/java/mage/players/PlayerImpl.java | 29 +++++-------------- .../main/java/mage/players/net/UserData.java | 2 +- .../players/net/UserSkipPrioritySteps.java | 4 +-- .../main/java/mage/target/TargetAmount.java | 5 +--- .../src/main/java/mage/target/TargetCard.java | 7 ++--- .../src/main/java/mage/target/TargetImpl.java | 15 +++------- .../main/java/mage/target/TargetObject.java | 5 +--- .../java/mage/target/TargetPermanent.java | 5 +--- .../main/java/mage/target/TargetPlayer.java | 7 ++--- .../main/java/mage/target/TargetSource.java | 2 +- .../main/java/mage/target/TargetSpell.java | 7 ++--- .../java/mage/target/TargetStackObject.java | 7 ++--- .../mage/target/common/TargetCardInExile.java | 10 ++----- .../target/common/TargetCardInGraveyard.java | 5 +--- .../TargetCardInGraveyardOrBattlefield.java | 5 +--- .../mage/target/common/TargetCardInHand.java | 5 +--- .../target/common/TargetCardInLibrary.java | 7 ++--- .../TargetCardInOpponentsGraveyard.java | 2 +- .../TargetCreatureOrPlaneswalkerAmount.java | 7 ++--- .../target/common/TargetCreatureOrPlayer.java | 10 ++----- .../common/TargetCreatureOrPlayerAmount.java | 12 ++------ .../common/TargetCreaturePermanentAmount.java | 11 +++---- .../mage/target/common/TargetDefender.java | 9 ++---- .../mage/target/common/TargetDiscard.java | 7 ++--- .../TargetOpponentsChoicePermanent.java | 5 +--- .../common/TargetPermanentOrPlayer.java | 12 ++------ .../TargetPermanentOrPlayerWithCounter.java | 2 +- .../TargetPermanentOrSuspendedCard.java | 12 ++------ .../target/common/TargetSpellOrPermanent.java | 12 ++------ .../targetpointer/SecondTargetPointer.java | 4 +-- Mage/src/main/java/mage/util/Copier.java | 10 ++----- .../mage/util/CopierObjectInputStream.java | 2 +- .../main/java/mage/util/TournamentUtil.java | 1 - .../util/functions/CopyTokenFunction.java | 4 +-- Mage/src/main/java/mage/watchers/Watcher.java | 2 +- .../src/main/java/mage/watchers/Watchers.java | 11 ++----- .../common/AttackedThisCombatWatcher.java | 2 +- .../common/AttackedThisTurnWatcher.java | 2 +- .../common/BlockedAttackerWatcher.java | 2 +- .../watchers/common/BloodthirstWatcher.java | 2 +- .../common/CastFromGraveyardWatcher.java | 5 +--- .../watchers/common/CommanderInfoWatcher.java | 2 +- .../watchers/common/DamagedByWatcher.java | 2 +- .../mage/watchers/common/LandfallWatcher.java | 2 +- .../mage/watchers/common/MorbidWatcher.java | 2 +- .../common/PlayerCastCreatureWatcher.java | 2 +- .../mage/watchers/common/ProwlWatcher.java | 5 +--- .../common/SourceDidDamageWatcher.java | 2 +- 52 files changed, 87 insertions(+), 220 deletions(-) diff --git a/Mage/src/main/java/mage/ConditionalMana.java b/Mage/src/main/java/mage/ConditionalMana.java index f9ed230c47..3dcfec39f6 100644 --- a/Mage/src/main/java/mage/ConditionalMana.java +++ b/Mage/src/main/java/mage/ConditionalMana.java @@ -206,26 +206,20 @@ public class ConditionalMana extends Mana implements Serializable { break; case BLUE: blue += amount; - ; break; case GREEN: green += amount; - ; break; case RED: red += amount; - ; break; case WHITE: white += amount; - ; break; case COLORLESS: colorless += amount; - ; case GENERIC: generic += amount; - ; break; } } diff --git a/Mage/src/main/java/mage/MageInt.java b/Mage/src/main/java/mage/MageInt.java index 73954ede00..f931b6577d 100644 --- a/Mage/src/main/java/mage/MageInt.java +++ b/Mage/src/main/java/mage/MageInt.java @@ -32,7 +32,7 @@ import mage.util.Copyable; public class MageInt implements Serializable, Copyable { - public static MageInt EmptyMageInt = new MageInt(Integer.MIN_VALUE, "") { + public static final MageInt EmptyMageInt = new MageInt(Integer.MIN_VALUE, "") { private static final String exceptionMessage = "MageInt.EmptyMageInt can't be modified."; diff --git a/Mage/src/main/java/mage/players/Library.java b/Mage/src/main/java/mage/players/Library.java index 0723ef547d..f8a4d2bae4 100644 --- a/Mage/src/main/java/mage/players/Library.java +++ b/Mage/src/main/java/mage/players/Library.java @@ -74,7 +74,7 @@ public class Library implements Serializable { public void shuffle() { UUID[] shuffled = library.toArray(new UUID[0]); for (int n = shuffled.length - 1; n > 0; n--) { - int r = RandomUtil.nextInt(n);; + int r = RandomUtil.nextInt(n); UUID temp = shuffled[n]; shuffled[n] = shuffled[r]; shuffled[r] = temp; diff --git a/Mage/src/main/java/mage/players/ManaPoolItem.java b/Mage/src/main/java/mage/players/ManaPoolItem.java index 9e09dd60f2..b8b7a08d13 100644 --- a/Mage/src/main/java/mage/players/ManaPoolItem.java +++ b/Mage/src/main/java/mage/players/ManaPoolItem.java @@ -303,23 +303,18 @@ public class ManaPoolItem implements Serializable { break; case BLUE: blue += amount; - ; break; case GREEN: green += amount; - ; break; case RED: red += amount; - ; break; case WHITE: white += amount; - ; break; case COLORLESS: colorless += amount; - ; break; } } diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index c74ad682b1..ef8067c3ed 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -141,7 +141,7 @@ public abstract class PlayerImpl implements Player, Serializable { private static final Logger logger = Logger.getLogger(PlayerImpl.class); - private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS"); + private static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS"); /** * Used to cancel waiting requests send to the player @@ -987,7 +987,7 @@ public abstract class PlayerImpl implements Player, Serializable { } else { result = cast(card.getSpellAbility(), game, noMana); } - if (result == false) { + if (!result) { game.informPlayer(this, "You can't play " + card.getIdName() + "."); } return result; @@ -2026,7 +2026,7 @@ public abstract class PlayerImpl implements Player, Serializable { quit = true; idleTimeout = true; this.concede(game); - game.informPlayers(new StringBuilder(getLogName()).append(" was idle for too long, losing the Match.").toString()); + game.informPlayers(getLogName() + " was idle for too long, losing the Match."); } @Override @@ -2241,11 +2241,7 @@ public abstract class PlayerImpl implements Player, Serializable { @Override public boolean hasWon() { - if (!this.loses) { - return this.wins; - } else { - return false; - } + return !this.loses && this.wins; } @Override @@ -2364,20 +2360,14 @@ public abstract class PlayerImpl implements Player, Serializable { public List getAvailableAttackers(UUID defenderId, Game game) { FilterCreatureForCombat filter = new FilterCreatureForCombat(); List attackers = game.getBattlefield().getAllActivePermanents(filter, playerId, game); - for (Iterator i = attackers.iterator(); i.hasNext();) { - Permanent entry = i.next(); - if (!entry.canAttack(defenderId, game)) { - i.remove(); - } - } + attackers.removeIf(entry -> !entry.canAttack(defenderId, game)); return attackers; } @Override public List getAvailableBlockers(Game game) { FilterCreatureForCombatBlock blockFilter = new FilterCreatureForCombatBlock(); - List blockers = game.getBattlefield().getAllActivePermanents(blockFilter, playerId, game); - return blockers; + return game.getBattlefield().getAllActivePermanents(blockFilter, playerId, game); } @Override @@ -2766,8 +2756,7 @@ public abstract class PlayerImpl implements Player, Serializable { // activated abilities from stack objects for (StackObject stackObject : game.getState().getStack()) { for (ActivatedAbility ability : stackObject.getAbilities().getActivatedAbilities(Zone.STACK)) { - if (ability instanceof ActivatedAbility - && canPlay(ability, availableMana, game.getObject(ability.getSourceId()), game)) { + if (ability != null && canPlay(ability, availableMana, game.getObject(ability.getSourceId()), game)) { playableActivated.put(ability.toString(), ability); } @@ -2776,9 +2765,7 @@ public abstract class PlayerImpl implements Player, Serializable { // activated abilities from objects in the command zone (emblems or commanders) for (CommandObject commandObject : game.getState().getCommand()) { for (ActivatedAbility ability : commandObject.getAbilities().getActivatedAbilities(Zone.COMMAND)) { - if (ability.getControllerId().equals(getId()) - && ability instanceof ActivatedAbility - && canPlay(ability, availableMana, game.getObject(ability.getSourceId()), game)) { + if (ability.getControllerId().equals(getId()) && canPlay(ability, availableMana, game.getObject(ability.getSourceId()), game)) { playableActivated.put(ability.toString(), ability); } diff --git a/Mage/src/main/java/mage/players/net/UserData.java b/Mage/src/main/java/mage/players/net/UserData.java index 9174b4c3a8..b5d52c9d0a 100644 --- a/Mage/src/main/java/mage/players/net/UserData.java +++ b/Mage/src/main/java/mage/players/net/UserData.java @@ -192,7 +192,7 @@ public class UserData implements Serializable { } public String getHistory() { - if (UserGroup.COMPUTER.equals(this.groupId)) { + if (UserGroup.COMPUTER.equals(this.groupId)) { // Why we are checking UserGroup and integer equality?? return ""; } // todo: add preference to hide rating? diff --git a/Mage/src/main/java/mage/players/net/UserSkipPrioritySteps.java b/Mage/src/main/java/mage/players/net/UserSkipPrioritySteps.java index 69ced12529..9e405cc603 100644 --- a/Mage/src/main/java/mage/players/net/UserSkipPrioritySteps.java +++ b/Mage/src/main/java/mage/players/net/UserSkipPrioritySteps.java @@ -35,8 +35,8 @@ import java.io.Serializable; */ public class UserSkipPrioritySteps implements Serializable { - SkipPrioritySteps yourTurn; - SkipPrioritySteps opponentTurn; + final SkipPrioritySteps yourTurn; + final SkipPrioritySteps opponentTurn; boolean stopOnDeclareAttackersDuringSkipAction; boolean stopOnDeclareBlockerIfNoneAvailable; diff --git a/Mage/src/main/java/mage/target/TargetAmount.java b/Mage/src/main/java/mage/target/TargetAmount.java index eb80a22a07..b9f8f5fabf 100644 --- a/Mage/src/main/java/mage/target/TargetAmount.java +++ b/Mage/src/main/java/mage/target/TargetAmount.java @@ -76,10 +76,7 @@ public abstract class TargetAmount extends TargetImpl { @Override public boolean doneChosing() { - if (amountWasSet == false) { - return false; - } - return remainingAmount == 0; + return amountWasSet && remainingAmount == 0; } @Override diff --git a/Mage/src/main/java/mage/target/TargetCard.java b/Mage/src/main/java/mage/target/TargetCard.java index 04885dd42e..87b26a64e4 100644 --- a/Mage/src/main/java/mage/target/TargetCard.java +++ b/Mage/src/main/java/mage/target/TargetCard.java @@ -44,7 +44,7 @@ import mage.players.Player; */ public class TargetCard extends TargetObject { - protected FilterCard filter; + protected final FilterCard filter; protected TargetCard(Zone zone) { this(1, 1, zone, new FilterCard()); @@ -214,10 +214,7 @@ public class TargetCard extends TargetObject { public boolean canTarget(UUID id, Cards cards, Game game) { Card card = cards.get(id, game); - if (card != null) { - return filter.match(card, game); - } - return false; + return card != null && filter.match(card, game); } @Override diff --git a/Mage/src/main/java/mage/target/TargetImpl.java b/Mage/src/main/java/mage/target/TargetImpl.java index f3452954eb..1de0af8021 100644 --- a/Mage/src/main/java/mage/target/TargetImpl.java +++ b/Mage/src/main/java/mage/target/TargetImpl.java @@ -34,7 +34,6 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Random; import java.util.Set; import java.util.UUID; import mage.MageObject; @@ -55,8 +54,8 @@ import mage.util.RandomUtil; */ public abstract class TargetImpl implements Target { - protected Map targets = new LinkedHashMap<>(); - protected Map zoneChangeCounters = new HashMap<>(); + protected final Map targets = new LinkedHashMap<>(); + protected final Map zoneChangeCounters = new HashMap<>(); protected String targetName; protected Zone zone; @@ -199,18 +198,12 @@ public abstract class TargetImpl implements Target { if (getMaxNumberOfTargets() == 0 && getNumberOfTargets() == 0) { return true; } - if (getMaxNumberOfTargets() != 0 && targets.size() == getMaxNumberOfTargets()) { - return true; - } - return chosen; + return getMaxNumberOfTargets() != 0 && targets.size() == getMaxNumberOfTargets() || chosen; } @Override public boolean doneChosing() { - if (getMaxNumberOfTargets() == 0) { - return false; - } - return targets.size() == getMaxNumberOfTargets(); + return getMaxNumberOfTargets() != 0 && targets.size() == getMaxNumberOfTargets(); } @Override diff --git a/Mage/src/main/java/mage/target/TargetObject.java b/Mage/src/main/java/mage/target/TargetObject.java index 1637bf8b1e..bc34fea778 100644 --- a/Mage/src/main/java/mage/target/TargetObject.java +++ b/Mage/src/main/java/mage/target/TargetObject.java @@ -78,10 +78,7 @@ public abstract class TargetObject extends TargetImpl { @Override public boolean canTarget(UUID id, Game game) { MageObject object = game.getObject(id); - if (object != null && game.getState().getZone(id).match(zone)) { - return getFilter().match(object, game); - } - return false; + return object != null && game.getState().getZone(id).match(zone) && getFilter().match(object, game); } @Override diff --git a/Mage/src/main/java/mage/target/TargetPermanent.java b/Mage/src/main/java/mage/target/TargetPermanent.java index 068bac9f0c..32d143a04c 100644 --- a/Mage/src/main/java/mage/target/TargetPermanent.java +++ b/Mage/src/main/java/mage/target/TargetPermanent.java @@ -101,10 +101,7 @@ public class TargetPermanent extends TargetObject { public boolean canTarget(UUID controllerId, UUID id, UUID sourceId, Game game, boolean flag) { Permanent permanent = game.getPermanent(id); - if (permanent != null) { - return filter.match(permanent, sourceId, controllerId, game); - } - return false; + return permanent != null && filter.match(permanent, sourceId, controllerId, game); } @Override diff --git a/Mage/src/main/java/mage/target/TargetPlayer.java b/Mage/src/main/java/mage/target/TargetPlayer.java index 3c69dc2871..64430423e6 100644 --- a/Mage/src/main/java/mage/target/TargetPlayer.java +++ b/Mage/src/main/java/mage/target/TargetPlayer.java @@ -42,7 +42,7 @@ import mage.players.Player; */ public class TargetPlayer extends TargetImpl { - protected FilterPlayer filter; + protected final FilterPlayer filter; public TargetPlayer() { this(1, 1, false); @@ -169,10 +169,7 @@ public class TargetPlayer extends TargetImpl { @Override public boolean canTarget(UUID id, Game game) { Player player = game.getPlayer(id); - if (player != null) { - return filter.match(player, game); - } - return false; + return player != null && filter.match(player, game); } @Override diff --git a/Mage/src/main/java/mage/target/TargetSource.java b/Mage/src/main/java/mage/target/TargetSource.java index fa60757d70..54a687b79c 100644 --- a/Mage/src/main/java/mage/target/TargetSource.java +++ b/Mage/src/main/java/mage/target/TargetSource.java @@ -47,7 +47,7 @@ import mage.players.Player; */ public class TargetSource extends TargetObject { - protected FilterObject filter; + protected final FilterObject filter; public TargetSource() { this(1, 1, new FilterObject("source of your choice")); diff --git a/Mage/src/main/java/mage/target/TargetSpell.java b/Mage/src/main/java/mage/target/TargetSpell.java index 525811a24a..f679aadddc 100644 --- a/Mage/src/main/java/mage/target/TargetSpell.java +++ b/Mage/src/main/java/mage/target/TargetSpell.java @@ -43,7 +43,7 @@ import mage.game.stack.StackObject; */ public class TargetSpell extends TargetObject { - protected FilterSpell filter; + protected final FilterSpell filter; public TargetSpell() { this(1, 1, new FilterSpell()); @@ -82,10 +82,7 @@ public class TargetSpell extends TargetObject { return false; } Spell spell = game.getStack().getSpell(id); - if (spell != null) { - return filter.match(spell, source.getSourceId(), source.getControllerId(), game); - } - return false; + return spell != null && filter.match(spell, source.getSourceId(), source.getControllerId(), game); } @Override diff --git a/Mage/src/main/java/mage/target/TargetStackObject.java b/Mage/src/main/java/mage/target/TargetStackObject.java index a4033f5c5f..a1c17b1f46 100644 --- a/Mage/src/main/java/mage/target/TargetStackObject.java +++ b/Mage/src/main/java/mage/target/TargetStackObject.java @@ -44,7 +44,7 @@ import java.util.UUID; */ public class TargetStackObject extends TargetObject { - protected FilterStackObject filter; + protected final FilterStackObject filter; public TargetStackObject() { this(1, 1, new FilterStackObject()); @@ -79,10 +79,7 @@ public class TargetStackObject extends TargetObject { @Override public boolean canTarget(UUID id, Ability source, Game game) { StackObject stackObject = game.getStack().getStackObject(id); - if (stackObject != null) { - return filter.match(stackObject, source.getSourceId(), source.getControllerId(), game); - } - return false; + return stackObject != null && filter.match(stackObject, source.getSourceId(), source.getControllerId(), game); } @Override diff --git a/Mage/src/main/java/mage/target/common/TargetCardInExile.java b/Mage/src/main/java/mage/target/common/TargetCardInExile.java index 7867f8729c..cce2aca70b 100644 --- a/Mage/src/main/java/mage/target/common/TargetCardInExile.java +++ b/Mage/src/main/java/mage/target/common/TargetCardInExile.java @@ -45,8 +45,8 @@ import mage.target.TargetCard; */ public class TargetCardInExile extends TargetCard { - private UUID zoneId; - private boolean allExileZones; + private final UUID zoneId; + private final boolean allExileZones; public TargetCardInExile(FilterCard filter) { this(1, 1, filter, null); @@ -68,11 +68,7 @@ public class TargetCardInExile extends TargetCard { public TargetCardInExile(int minNumTargets, int maxNumTargets, FilterCard filter, UUID zoneId, boolean allExileZones) { super(minNumTargets, maxNumTargets, Zone.EXILED, filter); this.zoneId = zoneId; - if (zoneId == null) { - this.allExileZones = true; - } else { - this.allExileZones = allExileZones; - } + this.allExileZones = zoneId == null || allExileZones; } public TargetCardInExile(final TargetCardInExile target) { diff --git a/Mage/src/main/java/mage/target/common/TargetCardInGraveyard.java b/Mage/src/main/java/mage/target/common/TargetCardInGraveyard.java index 9b6ea9694b..70d2071ff3 100644 --- a/Mage/src/main/java/mage/target/common/TargetCardInGraveyard.java +++ b/Mage/src/main/java/mage/target/common/TargetCardInGraveyard.java @@ -65,10 +65,7 @@ public class TargetCardInGraveyard extends TargetCard { @Override public boolean canTarget(UUID id, Ability source, Game game) { Card card = game.getCard(id); - if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) { - return filter.match(card, game); - } - return false; + return card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD && filter.match(card, game); } @Override diff --git a/Mage/src/main/java/mage/target/common/TargetCardInGraveyardOrBattlefield.java b/Mage/src/main/java/mage/target/common/TargetCardInGraveyardOrBattlefield.java index afa4eac6f1..e6ccb15a7e 100644 --- a/Mage/src/main/java/mage/target/common/TargetCardInGraveyardOrBattlefield.java +++ b/Mage/src/main/java/mage/target/common/TargetCardInGraveyardOrBattlefield.java @@ -89,10 +89,7 @@ public class TargetCardInGraveyardOrBattlefield extends TargetCard { return filter.match(permanent, game); } Card card = game.getCard(id); - if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) { - return filter.match(card, game); - } - return false; + return card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD && filter.match(card, game); } @Override diff --git a/Mage/src/main/java/mage/target/common/TargetCardInHand.java b/Mage/src/main/java/mage/target/common/TargetCardInHand.java index 7a545c7ae4..51a0ad4180 100644 --- a/Mage/src/main/java/mage/target/common/TargetCardInHand.java +++ b/Mage/src/main/java/mage/target/common/TargetCardInHand.java @@ -69,10 +69,7 @@ public class TargetCardInHand extends TargetCard { @Override public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) { Card card = game.getPlayer(playerId).getHand().get(id, game); - if (card != null) { - return filter.match(card, source.getSourceId(), playerId, game); - } - return false; + return card != null && filter.match(card, source.getSourceId(), playerId, game); } @Override diff --git a/Mage/src/main/java/mage/target/common/TargetCardInLibrary.java b/Mage/src/main/java/mage/target/common/TargetCardInLibrary.java index ac22810bb8..699f7278b6 100644 --- a/Mage/src/main/java/mage/target/common/TargetCardInLibrary.java +++ b/Mage/src/main/java/mage/target/common/TargetCardInLibrary.java @@ -92,7 +92,7 @@ public class TargetCardInLibrary extends TargetCard { } else { cards = new ArrayList<>(targetPlayer.getLibrary().getTopCards(game, librarySearchLimit)); } - Collections.sort(cards, new CardNameComparator()); + cards.sort(new CardNameComparator()); Cards cardsId = new CardsImpl(); for (Card card : cards) { cardsId.add(card); @@ -111,10 +111,7 @@ public class TargetCardInLibrary extends TargetCard { @Override public boolean canTarget(UUID id, Ability source, Game game) { Card card = game.getPlayer(source.getControllerId()).getLibrary().getCard(id, game); - if (card != null) { - return filter.match(card, game); - } - return false; + return card != null && filter.match(card, game); } @Override diff --git a/Mage/src/main/java/mage/target/common/TargetCardInOpponentsGraveyard.java b/Mage/src/main/java/mage/target/common/TargetCardInOpponentsGraveyard.java index 7358fa163b..232881a0c2 100644 --- a/Mage/src/main/java/mage/target/common/TargetCardInOpponentsGraveyard.java +++ b/Mage/src/main/java/mage/target/common/TargetCardInOpponentsGraveyard.java @@ -14,7 +14,7 @@ import mage.players.Player; public class TargetCardInOpponentsGraveyard extends TargetCard { - protected boolean allFromOneOpponent; + protected final boolean allFromOneOpponent; public TargetCardInOpponentsGraveyard(FilterCard filter) { this(1, 1, filter, false); diff --git a/Mage/src/main/java/mage/target/common/TargetCreatureOrPlaneswalkerAmount.java b/Mage/src/main/java/mage/target/common/TargetCreatureOrPlaneswalkerAmount.java index 6837535111..1cefb2098f 100644 --- a/Mage/src/main/java/mage/target/common/TargetCreatureOrPlaneswalkerAmount.java +++ b/Mage/src/main/java/mage/target/common/TargetCreatureOrPlaneswalkerAmount.java @@ -47,7 +47,7 @@ */ public class TargetCreatureOrPlaneswalkerAmount extends TargetAmount { - protected FilterCreatureOrPlaneswalkerPermanent filter; + protected final FilterCreatureOrPlaneswalkerPermanent filter; public TargetCreatureOrPlaneswalkerAmount(int amount) { // 107.1c If a rule or ability instructs a player to choose “any number,” that player may choose @@ -85,10 +85,7 @@ @Override public boolean canTarget(UUID objectId, Game game) { Permanent permanent = game.getPermanent(objectId); - if (permanent != null) { - return filter.match(permanent, game); - } - return false; + return permanent != null && filter.match(permanent, game); } @Override diff --git a/Mage/src/main/java/mage/target/common/TargetCreatureOrPlayer.java b/Mage/src/main/java/mage/target/common/TargetCreatureOrPlayer.java index 8d0aa4f767..a7a3b87318 100644 --- a/Mage/src/main/java/mage/target/common/TargetCreatureOrPlayer.java +++ b/Mage/src/main/java/mage/target/common/TargetCreatureOrPlayer.java @@ -90,10 +90,7 @@ public class TargetCreatureOrPlayer extends TargetImpl { return filter.match(permanent, game); } Player player = game.getPlayer(id); - if (player != null) { - return filter.match(player, game); - } - return false; + return player != null && filter.match(player, game); } @Override @@ -119,10 +116,7 @@ public class TargetCreatureOrPlayer extends TargetImpl { if (permanent != null) { return filter.match(permanent, game); } - if (player != null) { - return filter.match(player, game); - } - return false; + return player != null && filter.match(player, game); } /** diff --git a/Mage/src/main/java/mage/target/common/TargetCreatureOrPlayerAmount.java b/Mage/src/main/java/mage/target/common/TargetCreatureOrPlayerAmount.java index 25b1c076ff..1c7d8b970e 100644 --- a/Mage/src/main/java/mage/target/common/TargetCreatureOrPlayerAmount.java +++ b/Mage/src/main/java/mage/target/common/TargetCreatureOrPlayerAmount.java @@ -49,7 +49,7 @@ import mage.target.TargetAmount; */ public class TargetCreatureOrPlayerAmount extends TargetAmount { - protected FilterCreatureOrPlayer filter; + protected final FilterCreatureOrPlayer filter; public TargetCreatureOrPlayerAmount(int amount) { // 107.1c If a rule or ability instructs a player to choose “any number,” that player may choose @@ -84,10 +84,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount { return filter.match(permanent, game); } Player player = game.getPlayer(objectId); - if (player != null) { - return filter.match(player, game); - } - return false; + return player != null && filter.match(player, game); } @Override @@ -108,10 +105,7 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount { if (permanent != null) { return filter.match(permanent, game); } - if (player != null) { - return filter.match(player, game); - } - return false; + return player != null && filter.match(player, game); } @Override diff --git a/Mage/src/main/java/mage/target/common/TargetCreaturePermanentAmount.java b/Mage/src/main/java/mage/target/common/TargetCreaturePermanentAmount.java index 98f71ffcf4..430126b7db 100644 --- a/Mage/src/main/java/mage/target/common/TargetCreaturePermanentAmount.java +++ b/Mage/src/main/java/mage/target/common/TargetCreaturePermanentAmount.java @@ -49,7 +49,7 @@ import java.util.UUID; */ public class TargetCreaturePermanentAmount extends TargetAmount { - protected FilterCreaturePermanent filter; + protected final FilterCreaturePermanent filter; public TargetCreaturePermanentAmount(int amount) { this(amount, new FilterCreaturePermanent()); @@ -83,10 +83,7 @@ public class TargetCreaturePermanentAmount extends TargetAmount { @Override public boolean canTarget(UUID id, Game game) { Permanent permanent = game.getPermanent(id); - if (permanent != null) { - return filter.match(permanent, game); - } - return false; + return permanent != null && filter.match(permanent, game); } @Override @@ -139,7 +136,7 @@ public class TargetCreaturePermanentAmount extends TargetAmount { @Override public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { - Set possibleTargets = new HashSet(); + Set possibleTargets = new HashSet<>(); MageObject targetSource = game.getObject(sourceId); for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) { if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { @@ -151,7 +148,7 @@ public class TargetCreaturePermanentAmount extends TargetAmount { @Override public Set possibleTargets(UUID sourceControllerId, Game game) { - Set possibleTargets = new HashSet(); + Set possibleTargets = new HashSet<>(); for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), sourceControllerId, game)) { if (filter.match(permanent, null, sourceControllerId, game)) { possibleTargets.add(permanent.getId()); diff --git a/Mage/src/main/java/mage/target/common/TargetDefender.java b/Mage/src/main/java/mage/target/common/TargetDefender.java index 55dcfec22b..55717c19ac 100644 --- a/Mage/src/main/java/mage/target/common/TargetDefender.java +++ b/Mage/src/main/java/mage/target/common/TargetDefender.java @@ -49,8 +49,8 @@ import java.util.UUID; */ public class TargetDefender extends TargetImpl { - protected FilterPlaneswalkerOrPlayer filter; - protected UUID attackerId; + protected final FilterPlaneswalkerOrPlayer filter; + protected final UUID attackerId; public TargetDefender(Set defenders, UUID attackerId) { this(1, 1, defenders, attackerId); @@ -187,10 +187,7 @@ public class TargetDefender extends TargetImpl { return filter.match(player, game); } Permanent permanent = game.getPermanent(id); - if (permanent != null) { - return filter.match(permanent, game); - } - return false; + return permanent != null && filter.match(permanent, game); } @Override diff --git a/Mage/src/main/java/mage/target/common/TargetDiscard.java b/Mage/src/main/java/mage/target/common/TargetDiscard.java index 08de102e08..8d14aefd6e 100644 --- a/Mage/src/main/java/mage/target/common/TargetDiscard.java +++ b/Mage/src/main/java/mage/target/common/TargetDiscard.java @@ -44,7 +44,7 @@ import mage.filter.predicate.other.OwnerIdPredicate; */ public class TargetDiscard extends TargetCard { - private UUID playerId; + private final UUID playerId; public TargetDiscard(UUID playerId) { this(1, 1, new FilterCard(), playerId); @@ -73,10 +73,7 @@ public class TargetDiscard extends TargetCard { @Override public boolean canTarget(UUID id, Ability source, Game game) { Card card = game.getPlayer(playerId).getHand().get(id, game); - if (card != null) { - return filter.match(card, source.getControllerId(), game); - } - return false; + return card != null && filter.match(card, source.getControllerId(), game); } @Override diff --git a/Mage/src/main/java/mage/target/common/TargetOpponentsChoicePermanent.java b/Mage/src/main/java/mage/target/common/TargetOpponentsChoicePermanent.java index b9db4fdccc..813ae0951d 100644 --- a/Mage/src/main/java/mage/target/common/TargetOpponentsChoicePermanent.java +++ b/Mage/src/main/java/mage/target/common/TargetOpponentsChoicePermanent.java @@ -40,10 +40,7 @@ public class TargetOpponentsChoicePermanent extends TargetPermanent { @Override public boolean canTarget(UUID controllerId, UUID id, UUID sourceId, Game game, boolean flag) { - if (opponentId != null) { - return super.canTarget(opponentId, id, sourceId, game, flag); - } - return false; + return opponentId != null && super.canTarget(opponentId, id, sourceId, game, flag); } @Override diff --git a/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayer.java b/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayer.java index e2b8175b34..c7317b02c4 100644 --- a/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayer.java +++ b/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayer.java @@ -97,10 +97,7 @@ public class TargetPermanentOrPlayer extends TargetImpl { return filter.match(permanent, game); } Player player = game.getPlayer(id); - if (player != null) { - return filter.match(player, game); - } - return false; + return player != null && filter.match(player, game); } @Override @@ -118,7 +115,7 @@ public class TargetPermanentOrPlayer extends TargetImpl { if (permanent != null) { if (!isNotTarget()) { if (!permanent.canBeTargetedBy(game.getObject(source.getId()), source.getControllerId(), game) || - !permanent.canBeTargetedBy(game.getObject(source.getSourceId()), source.getControllerId(), game)) { + !permanent.canBeTargetedBy(game.getObject(source.getSourceId()), source.getControllerId(), game)) { return false; } } @@ -137,10 +134,7 @@ public class TargetPermanentOrPlayer extends TargetImpl { if (permanent != null) { return filter.match(permanent, game); } - if (player != null) { - return filter.match(player, game); - } - return false; + return player != null && filter.match(player, game); } /** diff --git a/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayerWithCounter.java b/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayerWithCounter.java index c8f0497e31..372d1fc5e2 100644 --- a/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayerWithCounter.java +++ b/Mage/src/main/java/mage/target/common/TargetPermanentOrPlayerWithCounter.java @@ -43,7 +43,7 @@ import mage.filter.predicate.permanent.CounterPredicate; */ public class TargetPermanentOrPlayerWithCounter extends TargetPermanentOrPlayer { - protected FilterPermanentOrPlayerWithCounter filter; + protected final FilterPermanentOrPlayerWithCounter filter; public TargetPermanentOrPlayerWithCounter() { this(1, 1); diff --git a/Mage/src/main/java/mage/target/common/TargetPermanentOrSuspendedCard.java b/Mage/src/main/java/mage/target/common/TargetPermanentOrSuspendedCard.java index eb036c7c86..40022b8909 100644 --- a/Mage/src/main/java/mage/target/common/TargetPermanentOrSuspendedCard.java +++ b/Mage/src/main/java/mage/target/common/TargetPermanentOrSuspendedCard.java @@ -48,7 +48,7 @@ import mage.target.TargetImpl; */ public class TargetPermanentOrSuspendedCard extends TargetImpl { - protected FilterPermanentOrSuspendedCard filter; + protected final FilterPermanentOrSuspendedCard filter; public TargetPermanentOrSuspendedCard() { this(new FilterPermanentOrSuspendedCard(), false); @@ -118,10 +118,7 @@ public class TargetPermanentOrSuspendedCard extends TargetImpl { return filter.match(permanent, game); } Card card = game.getExile().getCard(id, game); - if (card != null) { - return filter.match(card, game); - } - return false; + return card != null && filter.match(card, game); } @Override @@ -137,10 +134,7 @@ public class TargetPermanentOrSuspendedCard extends TargetImpl { } } Card card = game.getExile().getCard(id, game); - if (card != null) { - return filter.match(card, game); - } - return false; + return card != null && filter.match(card, game); } @Override diff --git a/Mage/src/main/java/mage/target/common/TargetSpellOrPermanent.java b/Mage/src/main/java/mage/target/common/TargetSpellOrPermanent.java index cc03cc5a0f..95e612cd82 100644 --- a/Mage/src/main/java/mage/target/common/TargetSpellOrPermanent.java +++ b/Mage/src/main/java/mage/target/common/TargetSpellOrPermanent.java @@ -105,10 +105,7 @@ public class TargetSpellOrPermanent extends TargetImpl { return filter.match(permanent, game); } Spell spell = game.getStack().getSpell(id); - if (spell != null) { - return filter.match(spell, game); - } - return false; + return spell != null && filter.match(spell, game); } @Override @@ -124,11 +121,8 @@ public class TargetSpellOrPermanent extends TargetImpl { } } Spell spell = game.getStack().getSpell(id); - if (spell != null - && !source.getSourceId().equals(id)) { // 114.4. A spell or ability on the stack is an illegal target for itself. - return filter.match(spell, game); - } - return false; + // 114.4. A spell or ability on the stack is an illegal target for itself. + return spell != null && !source.getSourceId().equals(id) && filter.match(spell, game); } @Override diff --git a/Mage/src/main/java/mage/target/targetpointer/SecondTargetPointer.java b/Mage/src/main/java/mage/target/targetpointer/SecondTargetPointer.java index 666796976c..0e097f16cb 100644 --- a/Mage/src/main/java/mage/target/targetpointer/SecondTargetPointer.java +++ b/Mage/src/main/java/mage/target/targetpointer/SecondTargetPointer.java @@ -11,7 +11,7 @@ import mage.game.Game; public class SecondTargetPointer implements TargetPointer { - private Map zoneChangeCounter = new HashMap(); + private Map zoneChangeCounter = new HashMap<>(); public static SecondTargetPointer getInstance() { return new SecondTargetPointer(); @@ -41,7 +41,7 @@ public class SecondTargetPointer implements TargetPointer { @Override public List getTargets(Game game, Ability source) { - ArrayList target = new ArrayList(); + ArrayList target = new ArrayList<>(); if (source.getTargets().size() > 1) { for (UUID targetId : source.getTargets().get(1).getTargets()) { Card card = game.getCard(targetId); diff --git a/Mage/src/main/java/mage/util/Copier.java b/Mage/src/main/java/mage/util/Copier.java index 4830d61bf2..e6b7aa4b49 100644 --- a/Mage/src/main/java/mage/util/Copier.java +++ b/Mage/src/main/java/mage/util/Copier.java @@ -64,12 +64,9 @@ public class Copier { ObjectInputStream in = new CopierObjectInputStream(loader, fbos.getInputStream()); copy = (T) in.readObject(); } - catch(IOException e) { + catch(IOException | ClassNotFoundException e) { e.printStackTrace(); } - catch(ClassNotFoundException cnfe) { - cnfe.printStackTrace(); - } return copy; } @@ -99,12 +96,9 @@ public class Copier { try (ObjectInputStream in = new CopierObjectInputStream(loader, new GZIPInputStream(new ByteArrayInputStream(buffer)))) { copy = (T) in.readObject(); } - catch(IOException e) { + catch(IOException | ClassNotFoundException e) { e.printStackTrace(); } - catch(ClassNotFoundException cnfe) { - cnfe.printStackTrace(); - } return copy; } } diff --git a/Mage/src/main/java/mage/util/CopierObjectInputStream.java b/Mage/src/main/java/mage/util/CopierObjectInputStream.java index cb906e4f5c..72189f7b76 100644 --- a/Mage/src/main/java/mage/util/CopierObjectInputStream.java +++ b/Mage/src/main/java/mage/util/CopierObjectInputStream.java @@ -41,7 +41,7 @@ import java.io.StreamCorruptedException; public class CopierObjectInputStream extends ObjectInputStream { ClassLoader myLoader = null; - public CopierObjectInputStream(ClassLoader newLoader, InputStream theStream) throws IOException, StreamCorruptedException { + public CopierObjectInputStream(ClassLoader newLoader, InputStream theStream) throws IOException { super(theStream); myLoader = newLoader; } diff --git a/Mage/src/main/java/mage/util/TournamentUtil.java b/Mage/src/main/java/mage/util/TournamentUtil.java index c4f8ab2d1e..2448a3277a 100644 --- a/Mage/src/main/java/mage/util/TournamentUtil.java +++ b/Mage/src/main/java/mage/util/TournamentUtil.java @@ -10,7 +10,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Random; import java.util.Set; import mage.cards.Card; diff --git a/Mage/src/main/java/mage/util/functions/CopyTokenFunction.java b/Mage/src/main/java/mage/util/functions/CopyTokenFunction.java index 28be2fb7b9..d6e9c2e91b 100644 --- a/Mage/src/main/java/mage/util/functions/CopyTokenFunction.java +++ b/Mage/src/main/java/mage/util/functions/CopyTokenFunction.java @@ -83,9 +83,7 @@ public class CopyTokenFunction implements Function { } else { target.setOriginalExpansionSetCode(source.getExpansionSetCode()); target.setOriginalCardNumber(source.getCardNumber()); - if (source instanceof Card) { - target.setCopySourceCard(source); - } + target.setCopySourceCard(source); } target.setName(sourceObj.getName()); diff --git a/Mage/src/main/java/mage/watchers/Watcher.java b/Mage/src/main/java/mage/watchers/Watcher.java index f00e3354a0..0ab4efc754 100644 --- a/Mage/src/main/java/mage/watchers/Watcher.java +++ b/Mage/src/main/java/mage/watchers/Watcher.java @@ -45,7 +45,7 @@ public abstract class Watcher implements Serializable { protected UUID controllerId; protected UUID sourceId; protected boolean condition; - protected WatcherScope scope; + protected final WatcherScope scope; public Watcher(String basicKey, WatcherScope scope) { this.basicKey = basicKey; diff --git a/Mage/src/main/java/mage/watchers/Watchers.java b/Mage/src/main/java/mage/watchers/Watchers.java index e0dbe5e03a..70227e9d2d 100644 --- a/Mage/src/main/java/mage/watchers/Watchers.java +++ b/Mage/src/main/java/mage/watchers/Watchers.java @@ -43,9 +43,7 @@ public class Watchers extends HashMap { } public Watchers(final Watchers watchers) { - watchers.entrySet().stream().forEach((entry) -> { - this.put(entry.getKey(), entry.getValue().copy()); - }); + watchers.entrySet().stream().forEach((entry) -> this.put(entry.getKey(), entry.getValue().copy())); } public Watchers copy() { @@ -59,16 +57,13 @@ public class Watchers extends HashMap { } public void watch(GameEvent event, Game game) { - for (Iterator it = this.values().iterator(); it.hasNext();) { - Watcher watcher = it.next(); + for (Watcher watcher : this.values()) { watcher.watch(event, game); } } public void reset() { - this.values().stream().forEach((watcher) -> { - watcher.reset(); - }); + this.values().stream().forEach(Watcher::reset); } public Watcher get(String key, UUID id) { diff --git a/Mage/src/main/java/mage/watchers/common/AttackedThisCombatWatcher.java b/Mage/src/main/java/mage/watchers/common/AttackedThisCombatWatcher.java index 9593e0d91c..0fa57f1277 100644 --- a/Mage/src/main/java/mage/watchers/common/AttackedThisCombatWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/AttackedThisCombatWatcher.java @@ -20,7 +20,7 @@ import mage.watchers.Watcher; public class AttackedThisCombatWatcher extends Watcher { - public Set attackedThisTurnCreatures = new HashSet<>(); + public final Set attackedThisTurnCreatures = new HashSet<>(); public AttackedThisCombatWatcher() { super("AttackedThisCombat", WatcherScope.GAME); diff --git a/Mage/src/main/java/mage/watchers/common/AttackedThisTurnWatcher.java b/Mage/src/main/java/mage/watchers/common/AttackedThisTurnWatcher.java index febd9d3eaa..67313929df 100644 --- a/Mage/src/main/java/mage/watchers/common/AttackedThisTurnWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/AttackedThisTurnWatcher.java @@ -41,7 +41,7 @@ import mage.watchers.Watcher; public class AttackedThisTurnWatcher extends Watcher { // TODO: use MageObjectReference instead of UUID - public Set attackedThisTurnCreatures = new HashSet<>(); + public final Set attackedThisTurnCreatures = new HashSet<>(); public AttackedThisTurnWatcher() { super("AttackedThisTurn", WatcherScope.GAME); diff --git a/Mage/src/main/java/mage/watchers/common/BlockedAttackerWatcher.java b/Mage/src/main/java/mage/watchers/common/BlockedAttackerWatcher.java index 8bda50563f..1a9aaccc35 100644 --- a/Mage/src/main/java/mage/watchers/common/BlockedAttackerWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/BlockedAttackerWatcher.java @@ -44,7 +44,7 @@ import mage.watchers.Watcher; */ public class BlockedAttackerWatcher extends Watcher { - public HashMap> blockData = new HashMap<>(); + public final HashMap> blockData = new HashMap<>(); public BlockedAttackerWatcher() { super("BlockedAttackerWatcher", WatcherScope.GAME); diff --git a/Mage/src/main/java/mage/watchers/common/BloodthirstWatcher.java b/Mage/src/main/java/mage/watchers/common/BloodthirstWatcher.java index 2040cc8371..b49a62f629 100644 --- a/Mage/src/main/java/mage/watchers/common/BloodthirstWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/BloodthirstWatcher.java @@ -51,7 +51,7 @@ public class BloodthirstWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { - if (condition == true) { //no need to check - condition has already occured + if (condition) { //no need to check - condition has already occured return; } if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER) { diff --git a/Mage/src/main/java/mage/watchers/common/CastFromGraveyardWatcher.java b/Mage/src/main/java/mage/watchers/common/CastFromGraveyardWatcher.java index 697cfb6f0d..41d07639af 100644 --- a/Mage/src/main/java/mage/watchers/common/CastFromGraveyardWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/CastFromGraveyardWatcher.java @@ -79,10 +79,7 @@ public class CastFromGraveyardWatcher extends Watcher { public boolean spellWasCastFromGraveyard(UUID sourceId, int zcc) { Set zccSet = spellsCastFromGraveyard.get(sourceId); - if (zccSet != null) { - return zccSet.contains(zcc); - } - return false; + return zccSet != null && zccSet.contains(zcc); } diff --git a/Mage/src/main/java/mage/watchers/common/CommanderInfoWatcher.java b/Mage/src/main/java/mage/watchers/common/CommanderInfoWatcher.java index b2ffe68f4d..e458b1d756 100644 --- a/Mage/src/main/java/mage/watchers/common/CommanderInfoWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/CommanderInfoWatcher.java @@ -51,7 +51,7 @@ import mage.watchers.Watcher; public class CommanderInfoWatcher extends Watcher { public final Map damageToPlayer = new HashMap<>(); - public boolean checkCommanderDamage; + public final boolean checkCommanderDamage; public CommanderInfoWatcher(UUID commander, boolean checkCommanderDamage) { super("CommanderCombatDamageWatcher", WatcherScope.CARD); diff --git a/Mage/src/main/java/mage/watchers/common/DamagedByWatcher.java b/Mage/src/main/java/mage/watchers/common/DamagedByWatcher.java index ed6bd2efdc..0043bc03de 100644 --- a/Mage/src/main/java/mage/watchers/common/DamagedByWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/DamagedByWatcher.java @@ -45,7 +45,7 @@ import mage.watchers.Watcher; */ public class DamagedByWatcher extends Watcher { - public Set damagedBySource = new HashSet<>(); + public final Set damagedBySource = new HashSet<>(); private final boolean watchPlaneswalkers; diff --git a/Mage/src/main/java/mage/watchers/common/LandfallWatcher.java b/Mage/src/main/java/mage/watchers/common/LandfallWatcher.java index b10338f3bd..4767cb7553 100644 --- a/Mage/src/main/java/mage/watchers/common/LandfallWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/LandfallWatcher.java @@ -16,7 +16,7 @@ import mage.watchers.Watcher; */ public class LandfallWatcher extends Watcher { - Set playerPlayedLand = new HashSet<>(); + final Set playerPlayedLand = new HashSet<>(); public LandfallWatcher() { super("LandPlayed", WatcherScope.GAME); diff --git a/Mage/src/main/java/mage/watchers/common/MorbidWatcher.java b/Mage/src/main/java/mage/watchers/common/MorbidWatcher.java index 14220eed22..f0e7fe0659 100644 --- a/Mage/src/main/java/mage/watchers/common/MorbidWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/MorbidWatcher.java @@ -53,7 +53,7 @@ public class MorbidWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { - if (condition == true) { + if (condition) { return; } if (event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).isDiesEvent()) { diff --git a/Mage/src/main/java/mage/watchers/common/PlayerCastCreatureWatcher.java b/Mage/src/main/java/mage/watchers/common/PlayerCastCreatureWatcher.java index ec3c0add73..b9af874ca3 100644 --- a/Mage/src/main/java/mage/watchers/common/PlayerCastCreatureWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/PlayerCastCreatureWatcher.java @@ -43,7 +43,7 @@ import mage.watchers.Watcher; */ public class PlayerCastCreatureWatcher extends Watcher { - Set playerIds = new HashSet<>(); + final Set playerIds = new HashSet<>(); public PlayerCastCreatureWatcher() { super("PlayerCastCreature", WatcherScope.GAME); diff --git a/Mage/src/main/java/mage/watchers/common/ProwlWatcher.java b/Mage/src/main/java/mage/watchers/common/ProwlWatcher.java index 40469145d1..ab3a4c0e66 100644 --- a/Mage/src/main/java/mage/watchers/common/ProwlWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/ProwlWatcher.java @@ -104,10 +104,7 @@ public class ProwlWatcher extends Watcher { return true; } Set subtypes = damagingSubtypes.get(playerId); - if (subtypes != null) { - return subtypes.contains(subtype); - } - return false; + return subtypes != null && subtypes.contains(subtype); } } diff --git a/Mage/src/main/java/mage/watchers/common/SourceDidDamageWatcher.java b/Mage/src/main/java/mage/watchers/common/SourceDidDamageWatcher.java index 4c9ad73f3a..7e01b65dd1 100644 --- a/Mage/src/main/java/mage/watchers/common/SourceDidDamageWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/SourceDidDamageWatcher.java @@ -44,7 +44,7 @@ import java.util.UUID; */ public class SourceDidDamageWatcher extends Watcher { - public List damageSources = new ArrayList<>(); + public final List damageSources = new ArrayList<>(); public SourceDidDamageWatcher() { super("SourceDidDamageWatcher", WatcherScope.GAME);