Few lambda's and removed explicit type from creating lists and hashmaps

This commit is contained in:
vraskulin 2017-02-28 13:46:54 +03:00
parent 0a3c95dde5
commit 11dc1e10f1
130 changed files with 725 additions and 1105 deletions

View file

@ -212,7 +212,7 @@ public class ContinuousEffects implements Serializable {
updateTimestamps(layerEffects);
Collections.sort(layerEffects, sorter);
layerEffects.sort(sorter);
return layerEffects;
}

View file

@ -27,14 +27,6 @@
*/
package mage.abilities.effects.common;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.MageItem;
import mage.MageObject;
import mage.abilities.Ability;
@ -51,6 +43,8 @@ import mage.target.Target;
import mage.target.TargetImpl;
import mage.util.TargetAddress;
import java.util.*;
/**
* @author duncant
* @param <T>
@ -158,7 +152,7 @@ public abstract class CopySpellForEachItCouldTargetEffect<T extends MageItem> ex
targetInstance.add(objId, game);
}
if (!playerTargetCopyMap.containsKey(copy.getControllerId())) {
playerTargetCopyMap.put(copy.getControllerId(), new HashMap<UUID, Spell>());
playerTargetCopyMap.put(copy.getControllerId(), new HashMap<>());
}
playerTargetCopyMap.get(copy.getControllerId()).put(objId, copy);
}

View file

@ -27,13 +27,6 @@
*/
package mage.cards;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.EnumMap;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
@ -41,6 +34,9 @@ import mage.constants.Rarity;
import mage.constants.SetType;
import mage.util.RandomUtil;
import java.io.Serializable;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -403,13 +399,7 @@ public abstract class ExpansionSet implements Serializable {
savedCardsInfos = CardRepository.instance.findCards(criteria);
// Workaround after card number is numeric
if (maxCardNumberInBooster != Integer.MAX_VALUE) {
Iterator<CardInfo> iterator = savedCardsInfos.iterator();
while (iterator.hasNext()) {
CardInfo next = iterator.next();
if (Integer.valueOf(next.getCardNumber()) > maxCardNumberInBooster && !rarity.equals(Rarity.LAND)) {
iterator.remove();
}
}
savedCardsInfos.removeIf(next -> Integer.valueOf(next.getCardNumber()) > maxCardNumberInBooster && !rarity.equals(Rarity.LAND));
}
savedCards.put(rarity, savedCardsInfos);

View file

@ -5,11 +5,12 @@
*/
package mage.game;
import mage.ObjectColor;
import mage.cards.Card;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import mage.ObjectColor;
import mage.cards.Card;
/**
* This class saves changed attributes of cards (e.g. in graveyard, exile or player hands or libraries).
@ -23,7 +24,7 @@ public class CardAttribute implements Serializable {
public CardAttribute(Card card) {
color = card.getColor(null).copy();
subtype = new ArrayList<String>(card.getSubtype(null));
subtype = new ArrayList<>(card.getSubtype(null));
}
public CardAttribute(CardAttribute cardAttribute) {

View file

@ -27,17 +27,14 @@
*/
package mage.game;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.constants.MultiplayerAttackOption;
import mage.constants.PhaseStep;
import mage.constants.RangeOfInfluence;
import mage.game.turn.TurnMod;
import mage.players.Player;
import java.util.*;
public abstract class GameCanadianHighlanderImpl extends GameImpl {
protected boolean startingPlayerSkipsDraw = true;
@ -58,59 +55,61 @@ public abstract class GameCanadianHighlanderImpl extends GameImpl {
}
private String getNextMulligan(String mulligan) {
if (mulligan.equals("7")) {
return "6a";
} else if (mulligan.equals("6a")) {
return "6b";
} else if (mulligan.equals("6b")) {
return "5a";
} else if (mulligan.equals("5a")) {
return "5b";
} else if (mulligan.equals("5b")) {
return "4a";
} else if (mulligan.equals("4a")) {
return "4b";
} else if (mulligan.equals("4b")) {
return "3a";
} else if (mulligan.equals("3a")) {
return "3b";
} else if (mulligan.equals("3b")) {
return "2a";
} else if (mulligan.equals("2a")) {
return "2b";
} else if (mulligan.equals("2b")) {
return "1a";
} else if (mulligan.equals("1a")) {
return "1b";
switch (mulligan) {
case "7":
return "6a";
case "6a":
return "6b";
case "6b":
return "5a";
case "5a":
return "5b";
case "5b":
return "4a";
case "4a":
return "4b";
case "4b":
return "3a";
case "3a":
return "3b";
case "3b":
return "2a";
case "2a":
return "2b";
case "2b":
return "1a";
case "1a":
return "1b";
}
return "0";
}
private int getNextMulliganNum(String mulligan) {
if (mulligan.equals("7")) {
return 6;
} else if (mulligan.equals("6a")) {
return 6;
} else if (mulligan.equals("6b")) {
return 5;
} else if (mulligan.equals("5a")) {
return 5;
} else if (mulligan.equals("5b")) {
return 4;
} else if (mulligan.equals("4a")) {
return 4;
} else if (mulligan.equals("4b")) {
return 3;
} else if (mulligan.equals("3a")) {
return 3;
} else if (mulligan.equals("3b")) {
return 2;
} else if (mulligan.equals("2a")) {
return 2;
} else if (mulligan.equals("2b")) {
return 1;
} else if (mulligan.equals("1a")) {
return 1;
switch (mulligan) {
case "7":
return 6;
case "6a":
return 6;
case "6b":
return 5;
case "5a":
return 5;
case "5b":
return 4;
case "4a":
return 4;
case "4b":
return 3;
case "3a":
return 3;
case "3b":
return 2;
case "2a":
return 2;
case "2b":
return 1;
case "1a":
return 1;
}
return 0;
}

View file

@ -27,19 +27,9 @@
*/
package mage.game;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import java.util.Map.Entry;
import mage.MageException;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.OpeningHandAction;
import mage.abilities.SpellAbility;
import mage.abilities.TriggeredAbility;
import mage.abilities.*;
import mage.abilities.common.AttachableToRestrictedAbility;
import mage.abilities.common.CantHaveMoreThanAmountCountersSourceAbility;
import mage.abilities.effects.ContinuousEffect;
@ -53,24 +43,10 @@ import mage.abilities.keyword.TransformAbility;
import mage.abilities.mana.DelayedTriggeredManaAbility;
import mage.abilities.mana.TriggeredManaAbility;
import mage.actions.impl.MageAction;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.cards.MeldCard;
import mage.cards.SplitCard;
import mage.cards.SplitCardHalf;
import mage.cards.*;
import mage.cards.decks.Deck;
import mage.choices.Choice;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.MultiplayerAttackOption;
import mage.constants.Outcome;
import mage.constants.PhaseStep;
import mage.constants.PlayerAction;
import mage.constants.RangeOfInfluence;
import mage.constants.SpellAbilityType;
import mage.constants.Zone;
import mage.constants.*;
import mage.counters.CounterType;
import mage.counters.Counters;
import mage.designations.Designation;
@ -89,14 +65,8 @@ import mage.game.combat.Combat;
import mage.game.command.CommandObject;
import mage.game.command.Commander;
import mage.game.command.Emblem;
import mage.game.events.DamageEvent;
import mage.game.events.GameEvent;
import mage.game.events.Listener;
import mage.game.events.PlayerQueryEvent;
import mage.game.events.PlayerQueryEventSource;
import mage.game.events.TableEvent;
import mage.game.events.*;
import mage.game.events.TableEvent.EventType;
import mage.game.events.TableEventSource;
import mage.game.permanent.Battlefield;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentCard;
@ -119,15 +89,14 @@ import mage.util.MessageToClient;
import mage.util.RandomUtil;
import mage.util.functions.ApplyToPermanent;
import mage.watchers.Watchers;
import mage.watchers.common.BlockedAttackerWatcher;
import mage.watchers.common.BloodthirstWatcher;
import mage.watchers.common.CastSpellLastTurnWatcher;
import mage.watchers.common.DamageDoneWatcher;
import mage.watchers.common.MorbidWatcher;
import mage.watchers.common.PlayerDamagedBySourceWatcher;
import mage.watchers.common.PlayerLostLifeWatcher;
import mage.watchers.common.*;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import java.util.Map.Entry;
public abstract class GameImpl implements Game, Serializable {
private static final int ROLLBACK_TURNS_MAX = 4;
@ -2584,11 +2553,7 @@ public abstract class GameImpl implements Game, Serializable {
// remembers if a object was in a zone during the resolution of an effect
// e.g. Wrath destroys all and you the question is is the replacement effect to apply because the source was also moved by the same effect
// because it ahppens all at the same time the replcaement effect has still to be applied
Set<UUID> idSet = shortLivingLKI.get(zone);
if (idSet == null) {
idSet = new HashSet<>();
shortLivingLKI.put(zone, idSet);
}
Set<UUID> idSet = shortLivingLKI.computeIfAbsent(zone, k -> new HashSet<>());
idSet.add(objectId);
if (object instanceof Permanent) {
Map<Integer, MageObject> lkiExtendedMap = lkiExtended.get(objectId);

View file

@ -27,21 +27,8 @@
*/
package mage.game;
import java.io.Serializable;
import java.util.*;
import mage.MageObject;
import mage.abilities.Abilities;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.DelayedTriggeredAbilities;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.MageSingleton;
import mage.abilities.Mode;
import mage.abilities.SpecialActions;
import mage.abilities.StaticAbility;
import mage.abilities.TriggeredAbilities;
import mage.abilities.TriggeredAbility;
import mage.abilities.*;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.ContinuousEffects;
import mage.abilities.effects.Effect;
@ -71,6 +58,9 @@ import mage.util.ThreadLocalStringBuilder;
import mage.watchers.Watcher;
import mage.watchers.Watchers;
import java.io.Serializable;
import java.util.*;
/**
*
* @author BetaSteward_at_googlemail.com
@ -1091,11 +1081,7 @@ public class GameState implements Serializable, Copyable<GameState> {
}
public CardAttribute getCreateCardAttribute(Card card) {
CardAttribute cardAtt = cardAttribute.get(card.getId());
if (cardAtt == null) {
cardAtt = new CardAttribute(card);
cardAttribute.put(card.getId(), cardAtt);
}
CardAttribute cardAtt = cardAttribute.computeIfAbsent(card.getId(), k -> new CardAttribute(card));
return cardAtt;
}

View file

@ -27,7 +27,6 @@
*/
package mage.game.permanent;
import java.util.*;
import mage.MageObject;
import mage.MageObjectReference;
import mage.ObjectColor;
@ -36,25 +35,10 @@ import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.Effect;
import mage.abilities.effects.RestrictionEffect;
import mage.abilities.keyword.DeathtouchAbility;
import mage.abilities.keyword.DefenderAbility;
import mage.abilities.keyword.HasteAbility;
import mage.abilities.keyword.HexproofAbility;
import mage.abilities.keyword.IndestructibleAbility;
import mage.abilities.keyword.InfectAbility;
import mage.abilities.keyword.LifelinkAbility;
import mage.abilities.keyword.MorphAbility;
import mage.abilities.keyword.ProtectionAbility;
import mage.abilities.keyword.ShroudAbility;
import mage.abilities.keyword.WitherAbility;
import mage.abilities.keyword.*;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.constants.AsThoughEffectType;
import mage.constants.CardType;
import mage.constants.EffectType;
import mage.constants.EnterEventType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.constants.*;
import mage.counters.Counter;
import mage.counters.CounterType;
import mage.counters.Counters;
@ -71,6 +55,8 @@ import mage.players.Player;
import mage.util.GameLog;
import mage.util.ThreadLocalStringBuilder;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -1216,7 +1202,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public boolean clearImprinted(Game game) {
this.connectedCards.put("imprint", new ArrayList<UUID>());
this.connectedCards.put("imprint", new ArrayList<>());
return true;
}

View file

@ -27,38 +27,23 @@
*/
package mage.game.tournament;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
import mage.cards.ExpansionSet;
import mage.cards.decks.Deck;
import mage.constants.TournamentPlayerState;
import mage.game.draft.Draft;
import mage.game.draft.DraftCube;
import mage.game.events.Listener;
import mage.game.events.PlayerQueryEvent;
import mage.game.events.PlayerQueryEventSource;
import mage.game.events.TableEvent;
import mage.game.events.*;
import mage.game.events.TableEvent.EventType;
import mage.game.events.TableEventSource;
import mage.game.match.Match;
import mage.game.match.MatchPlayer;
import mage.game.result.ResultProtos.MatchPlayerProto;
import mage.game.result.ResultProtos.MatchProto;
import mage.game.result.ResultProtos.MatchQuitStatus;
import mage.game.result.ResultProtos.TourneyProto;
import mage.game.result.ResultProtos.TourneyRoundProto;
import mage.game.result.ResultProtos.*;
import mage.players.Player;
import mage.util.RandomUtil;
import org.apache.log4j.Logger;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
/**
*
* @author BetaSteward_at_googlemail.com
@ -404,12 +389,7 @@ public abstract class TournamentImpl implements Tournament {
player.setConstructing();
new Thread(
new Runnable() {
@Override
public void run() {
player.getPlayer().construct(TournamentImpl.this, player.getDeck());
}
}
() -> player.getPlayer().construct(TournamentImpl.this, player.getDeck())
).start();
}
// add autosubmit trigger

View file

@ -41,7 +41,7 @@ import java.util.List;
public class RoundPairings {
public RoundPairings() {
this(new ArrayList<TournamentPairing>(), new ArrayList<TournamentPlayer>());
this(new ArrayList<>(), new ArrayList<>());
}
public RoundPairings(List<TournamentPairing> pairings, List<TournamentPlayer> playerByes) {

View file

@ -60,7 +60,7 @@ public class SwissPairingMinimalWeightMatching {
public SwissPairingMinimalWeightMatching(List<TournamentPlayer> players, List<Round> rounds, boolean isLastRound) {
playersCount = players.size();
swissPlayers = new ArrayList<PlayerInfo>();
swissPlayers = new ArrayList<>();
for (TournamentPlayer tournamentPlayer : players) {
PlayerInfo swissPlayer = new PlayerInfo();
swissPlayer.tournamentPlayer = tournamentPlayer;
@ -98,15 +98,12 @@ public class SwissPairingMinimalWeightMatching {
}
// sort by points and then by sos points
Collections.sort(swissPlayers, new Comparator<PlayerInfo>() {
@Override
public int compare(PlayerInfo p1, PlayerInfo p2) {
int result = p2.points - p1.points;
if (result != 0) {
return result;
}
return p2.sosPoints - p1.sosPoints;
swissPlayers.sort((p1, p2) -> {
int result = p2.points - p1.points;
if (result != 0) {
return result;
}
return p2.sosPoints - p1.sosPoints;
});
// order could be changed, update ids and mapping

View file

@ -33,8 +33,6 @@ import mage.game.tournament.TournamentPairing;
import mage.game.tournament.TournamentPlayer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
@ -59,13 +57,7 @@ public class SwissPairingSimple {
List<TournamentPlayer> playerByes = new ArrayList<>();
// sort players by tournament points
Collections.sort(players, new Comparator<TournamentPlayer>() {
@Override
public int compare(TournamentPlayer p1, TournamentPlayer p2) {
return p2.getPoints() - p1.getPoints();
}
});
players.sort((p1, p2) -> p2.getPoints() - p1.getPoints());
// create pairings
while (!players.isEmpty()) {
TournamentPlayer player1 = players.get(0);

View file

@ -1,14 +1,11 @@
package mage.target.targetpointer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.abilities.Ability;
import mage.cards.Card;
import mage.game.Game;
import java.util.*;
public class SecondTargetPointer implements TargetPointer {
private Map<UUID, Integer> zoneChangeCounter = new HashMap<>();
@ -21,7 +18,7 @@ public class SecondTargetPointer implements TargetPointer {
}
public SecondTargetPointer(SecondTargetPointer firstTargetPointer) {
this.zoneChangeCounter = new HashMap<UUID, Integer>();
this.zoneChangeCounter = new HashMap<>();
for (Map.Entry<UUID, Integer> entry : firstTargetPointer.zoneChangeCounter.entrySet()) {
this.zoneChangeCounter.put(entry.getKey(), entry.getValue());
}