loop to streams

This commit is contained in:
igoudt 2017-07-08 10:57:36 +02:00
parent 6eba170e3c
commit a167122459
10 changed files with 38 additions and 81 deletions

View file

@ -129,9 +129,7 @@ public class ChatSession {
clientsToRemove.add(userId); clientsToRemove.add(userId);
} }
} }
for (UUID userIdToRemove : clientsToRemove) { clients.keySet().removeAll(clientsToRemove);
clients.remove(userIdToRemove);
}
} }
} }

View file

@ -46,6 +46,7 @@ import mage.game.Table;
import mage.game.events.Listener; import mage.game.events.Listener;
import mage.game.events.PlayerQueryEvent; import mage.game.events.PlayerQueryEvent;
import mage.game.events.TableEvent; import mage.game.events.TableEvent;
import mage.game.match.MatchPlayer;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.interfaces.Action; import mage.interfaces.Action;
import mage.players.Player; import mage.players.Player;
@ -65,7 +66,6 @@ import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.zip.GZIPOutputStream; import java.util.zip.GZIPOutputStream;
import mage.game.match.MatchPlayer;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -108,12 +108,7 @@ public class GameController implements GameCallback {
this.tableId = tableId; this.tableId = tableId;
this.choosingPlayerId = choosingPlayerId; this.choosingPlayerId = choosingPlayerId;
this.gameOptions = gameOptions; this.gameOptions = gameOptions;
for (Player player : game.getPlayers().values()) { useTimeout = game.getPlayers().values().stream().allMatch(Player::isHuman);
if (!player.isHuman()) {
useTimeout = false; // no timeout for AI players because of beeing idle
break;
}
}
init(); init();
} }
@ -832,13 +827,8 @@ public class GameController implements GameCallback {
} }
final String message = new StringBuilder(game.getStep().getType().toString()).append(" - Waiting for ").append(controller.getName()).toString(); final String message = new StringBuilder(game.getStep().getType().toString()).append(" - Waiting for ").append(controller.getName()).toString();
for (final Entry<UUID, GameSessionPlayer> entry : gameSessions.entrySet()) { for (final Entry<UUID, GameSessionPlayer> entry : gameSessions.entrySet()) {
boolean skip = false; boolean skip = players.stream().anyMatch(playerId -> entry.getKey().equals(playerId));
for (UUID uuid : players) {
if (entry.getKey().equals(uuid)) {
skip = true;
break;
}
}
if (!skip) { if (!skip) {
entry.getValue().inform(message); entry.getValue().inform(message);
} }

View file

@ -45,13 +45,10 @@ public enum DashedCondition implements Condition {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId()); Card card = game.getCard(source.getSourceId());
if (card != null) { if (card != null) {
for (Ability ability : card.getAbilities()) { return card.getAbilities().stream()
if (ability instanceof DashAbility) { .filter(a -> a instanceof DashAbility)
if (((DashAbility) ability).isActivated(source, game)) { .anyMatch(d -> ((DashAbility)d).isActivated(source, game));
return true;
}
}
}
} }
return false; return false;
} }

View file

@ -48,13 +48,9 @@ public enum EvokedCondition implements Condition {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId()); Card card = game.getCard(source.getSourceId());
if (card != null) { if (card != null) {
for (Ability ability: card.getAbilities()) { return card.getAbilities().stream()
if (ability instanceof EvokeAbility) { .filter(ab -> ab instanceof EvokeAbility)
if(((EvokeAbility) ability).isActivated(source, game)) { .anyMatch(evoke -> ((EvokeAbility) evoke).isActivated(source, game));
return true;
}
}
}
} }
return false; return false;
} }

View file

@ -27,13 +27,15 @@
*/ */
package mage.abilities.costs.mana; package mage.abilities.costs.mana;
import java.util.List;
import java.util.UUID;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.VariableCost; import mage.abilities.costs.VariableCost;
import mage.game.Game; import mage.game.Game;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -63,14 +65,10 @@ public interface ManaCosts<T extends ManaCost> extends List<T>, ManaCost {
static ManaCosts<ManaCost> removeVariableManaCost(ManaCosts<ManaCost> m) { static ManaCosts<ManaCost> removeVariableManaCost(ManaCosts<ManaCost> m) {
ManaCosts<ManaCost> manaCosts = new ManaCostsImpl<>(); return m.stream()
for(ManaCost manaCost : m){ .filter(mc -> !(mc instanceof VariableManaCost))
if(!(manaCost instanceof VariableManaCost)){ .collect(Collectors.toCollection(ManaCostsImpl<ManaCost>::new));
manaCosts.add(manaCost);
}
}
return manaCosts;
} }
} }

View file

@ -18,11 +18,7 @@ public class DiscardCostCardConvertedMana implements DynamicValue {
for (Cost cost : sourceAbility.getCosts()) { for (Cost cost : sourceAbility.getCosts()) {
if (cost instanceof DiscardTargetCost) { if (cost instanceof DiscardTargetCost) {
DiscardTargetCost discardCost = (DiscardTargetCost) cost; DiscardTargetCost discardCost = (DiscardTargetCost) cost;
int cmc = 0; return discardCost.getCards().stream().mapToInt(Card::getConvertedManaCost).sum();
for (Card card : discardCost.getCards()) {
cmc += card.getConvertedManaCost();
}
return cmc;
} }
} }
return 0; return 0;

View file

@ -6,7 +6,6 @@ import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
/** /**
* @author LevelX2 * @author LevelX2
@ -18,11 +17,8 @@ public class SacrificeCostCreaturesPower implements DynamicValue {
for (Cost cost : sourceAbility.getCosts()) { for (Cost cost : sourceAbility.getCosts()) {
if (cost instanceof SacrificeTargetCost) { if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost; SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
int powerSum = 0; return sacrificeCost.getPermanents()
for (Permanent permanent : sacrificeCost.getPermanents()) { .stream().mapToInt(p -> p.getPower().getValue()).sum();
powerSum += permanent.getPower().getValue();
}
return powerSum;
} }
} }
return 0; return 0;

View file

@ -6,7 +6,6 @@ import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
/** /**
* @author LevelX2 * @author LevelX2
@ -18,11 +17,7 @@ public class SacrificeCostCreaturesToughness implements DynamicValue {
for (Cost cost : sourceAbility.getCosts()) { for (Cost cost : sourceAbility.getCosts()) {
if (cost instanceof SacrificeTargetCost) { if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost; SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost;
int toughnessSum = 0; return sacrificeCost.getPermanents().stream().mapToInt(p -> p.getToughness().getValue()).sum();
for (Permanent permanent : sacrificeCost.getPermanents()) {
toughnessSum += permanent.getToughness().getValue();
}
return toughnessSum;
} }
} }
return 0; return 0;

View file

@ -27,10 +27,6 @@
*/ */
package mage.abilities.keyword; package mage.abilities.keyword;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.SpellAbility; import mage.abilities.SpellAbility;
import mage.abilities.StaticAbility; import mage.abilities.StaticAbility;
@ -56,6 +52,11 @@ import mage.game.stack.StackObject;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetControlledPermanent; import mage.target.common.TargetControlledPermanent;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.UUID;
/* /*
* 702.77. Conspire * 702.77. Conspire
* 702.77a Conspire is a keyword that represents two abilities. * 702.77a Conspire is a keyword that represents two abilities.
@ -165,7 +166,7 @@ public class ConspireAbility extends StaticAbility implements OptionalAdditional
if (conspireCost.canPay(ability, getSourceId(), getControllerId(), game) if (conspireCost.canPay(ability, getSourceId(), getControllerId(), game)
&& player.chooseUse(Outcome.Benefit, "Pay " + conspireCost.getText(false) + " ?", ability, game)) { && player.chooseUse(Outcome.Benefit, "Pay " + conspireCost.getText(false) + " ?", ability, game)) {
activateConspire(ability, game); activateConspire(ability, game);
for (Iterator it = ((Costs) conspireCost).iterator(); it.hasNext();) { for (Iterator it = conspireCost.iterator(); it.hasNext(); ) {
Cost cost = (Cost) it.next(); Cost cost = (Cost) it.next();
ability.getCosts().add(cost.copy()); ability.getCosts().add(cost.copy());
} }

View file

@ -28,20 +28,16 @@
package mage.game.draft; package mage.game.draft;
import java.util.*;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.ExpansionSet; import mage.cards.ExpansionSet;
import mage.game.draft.DraftOptions.TimingOption; import mage.game.draft.DraftOptions.TimingOption;
import mage.game.events.Listener; import mage.game.events.*;
import mage.game.events.PlayerQueryEvent;
import mage.game.events.PlayerQueryEventSource;
import mage.game.events.TableEvent;
import mage.game.events.TableEvent.EventType; import mage.game.events.TableEvent.EventType;
import mage.game.events.TableEventSource;
import mage.players.Player; import mage.players.Player;
import mage.players.PlayerList; import mage.players.PlayerList;
import java.util.*;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -262,22 +258,16 @@ public abstract class DraftImpl implements Draft {
if(isAbort()) { if(isAbort()) {
return true; return true;
} }
for (DraftPlayer player: players.values()) { return players.values()
if (player.isPicking()) { .stream()
return false; .noneMatch(DraftPlayer::isPicking);
}
}
return true;
} }
@Override @Override
public boolean allJoined() { public boolean allJoined() {
for (DraftPlayer player: this.players.values()) { return players.values().stream()
if (!player.isJoined()) { .allMatch(DraftPlayer::isJoined);
return false;
}
}
return true;
} }
@Override @Override