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

@ -28,15 +28,16 @@
package mage.player.ai;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import mage.abilities.keyword.DoubleStrikeAbility;
import mage.abilities.keyword.FirstStrikeAbility;
import mage.abilities.keyword.TrampleAbility;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -44,7 +45,7 @@ import mage.game.permanent.Permanent;
public class CombatEvaluator {
//preserve calculations for efficiency
private Map<UUID, Integer> values = new HashMap<UUID, Integer>();
private Map<UUID, Integer> values = new HashMap<>();
public int evaluate(Permanent creature, Game game) {
if (!values.containsKey(creature.getId())) {

View file

@ -617,9 +617,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
}
if (target.getOriginalTarget() instanceof TargetSpell) {
if (!game.getStack().isEmpty()) {
Iterator<StackObject> it = game.getStack().iterator();
while (it.hasNext()) {
StackObject o = it.next();
for (StackObject o : game.getStack()) {
if (o instanceof Spell && !source.getId().equals(o.getStackAbility().getId())) {
target.addTarget(o.getId(), source, game);
return true;
@ -651,9 +649,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
}
}
if (!game.getStack().isEmpty()) {
Iterator<StackObject> it = game.getStack().iterator();
while (it.hasNext()) {
StackObject stackObject = it.next();
for (StackObject stackObject : game.getStack()) {
if (stackObject instanceof Spell && source != null && !source.getId().equals(stackObject.getStackAbility().getId())) {
if (((TargetSpellOrPermanent) target).getFilter().match(stackObject, game)) {
target.addTarget(stackObject.getId(), source, game);

View file

@ -28,8 +28,6 @@
package mage.player.ai.simulators;
import java.util.ArrayList;
import java.util.List;
import mage.abilities.ActivatedAbility;
import mage.cards.Card;
import mage.game.Game;
@ -38,6 +36,9 @@ import mage.player.ai.ComputerPlayer;
import mage.player.ai.PermanentEvaluator;
import mage.players.Player;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author BetaSteward_at_googlemail.com
@ -45,8 +46,8 @@ import mage.players.Player;
public class ActionSimulator {
private ComputerPlayer player;
private List<Card> playableInstants = new ArrayList<Card>();
private List<ActivatedAbility> playableAbilities = new ArrayList<ActivatedAbility>();
private List<Card> playableInstants = new ArrayList<>();
private List<ActivatedAbility> playableAbilities = new ArrayList<>();
private Game game;

View file

@ -28,20 +28,21 @@
package mage.player.ai.simulators;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class CombatGroupSimulator implements Serializable {
public List<CreatureSimulator> attackers = new ArrayList<CreatureSimulator>();
public List<CreatureSimulator> blockers = new ArrayList<CreatureSimulator>();
public List<CreatureSimulator> attackers = new ArrayList<>();
public List<CreatureSimulator> blockers = new ArrayList<>();
public UUID defenderId;
public boolean defenderIsPlaneswalker;
public int unblockedDamage;

View file

@ -28,30 +28,26 @@
package mage.player.ai.simulators;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import mage.counters.CounterType;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.permanent.Permanent;
import mage.players.Player;
import java.io.Serializable;
import java.util.*;
import java.util.Map.Entry;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class CombatSimulator implements Serializable {
public List<CombatGroupSimulator> groups = new ArrayList<CombatGroupSimulator>();
public List<UUID> defenders = new ArrayList<UUID>();
public Map<UUID, Integer> playersLife = new HashMap<UUID, Integer>();
public Map<UUID, Integer> planeswalkerLoyalty = new HashMap<UUID, Integer>();
public List<CombatGroupSimulator> groups = new ArrayList<>();
public List<UUID> defenders = new ArrayList<>();
public Map<UUID, Integer> playersLife = new HashMap<>();
public Map<UUID, Integer> planeswalkerLoyalty = new HashMap<>();
public UUID attackerId;
public int rating = 0;
@ -89,7 +85,7 @@ public class CombatSimulator implements Serializable {
}
public int evaluate() {
Map<UUID, Integer> damage = new HashMap<UUID, Integer>();
Map<UUID, Integer> damage = new HashMap<>();
int result = 0;
for (CombatGroupSimulator group: groups) {
if (!damage.containsKey(group.defenderId)) {

View file

@ -191,7 +191,7 @@ public final class RateCard {
}
return 2 * (converted - colorPenalty + 1);
}
final Map<String, Integer> singleCount = new HashMap<String, Integer>();
final Map<String, Integer> singleCount = new HashMap<>();
int maxSingleCount = 0;
for (String symbol : card.getManaCost().getSymbols()) {
int count = 0;
@ -257,7 +257,7 @@ public final class RateCard {
* @return
*/
public static int getDifferentColorManaCount(Card card) {
Set<String> symbols = new HashSet<String>();
Set<String> symbols = new HashSet<>();
for (String symbol : card.getManaCost().getSymbols()) {
if (isColoredMana(symbol)) {
symbols.add(symbol);