replaced various instances of instanceof lambda functions with

This commit is contained in:
Evan Kranzler 2022-04-03 11:11:07 -04:00
parent 26ef55c1bc
commit 26ae7b7281
21 changed files with 37 additions and 46 deletions

View file

@ -18,7 +18,7 @@ public enum BuybackCondition implements Condition {
Card card = game.getCard(source.getSourceId());
if (card != null) {
return card.getAbilities(game).stream()
.filter(a -> a instanceof BuybackAbility)
.filter(BuybackAbility.class::isInstance)
.anyMatch(a -> ((BuybackAbility) a).isBuybackActivated(game));
}
return false;

View file

@ -20,7 +20,7 @@ public enum DashedCondition implements Condition {
Card card = game.getCard(source.getSourceId());
if (card != null) {
return card.getAbilities(game).stream()
.filter(a -> a instanceof DashAbility)
.filter(DashAbility.class::isInstance)
.anyMatch(d -> ((DashAbility) d).isActivated(source, game));
}

View file

@ -23,7 +23,7 @@ public enum EvokedCondition implements Condition {
Card card = game.getCard(source.getSourceId());
if (card != null) {
return card.getAbilities(game).stream()
.filter(ab -> ab instanceof EvokeAbility)
.filter(EvokeAbility.class::isInstance)
.anyMatch(evoke -> ((EvokeAbility) evoke).isActivated(source, game));
}
return false;

View file

@ -140,7 +140,7 @@ public class AlternativeCostSourceAbility extends StaticAbility implements Alter
if (alternativeCostsToCheck.canPay(ability, ability, ability.getControllerId(), game)
&& player.chooseUse(Outcome.Benefit, costChoiceText, this, game)) {
if (ability instanceof SpellAbility) {
ability.getManaCostsToPay().removeIf(manaCost -> manaCost instanceof VariableCost);
ability.getManaCostsToPay().removeIf(VariableCost.class::isInstance);
CardUtil.reduceCost((SpellAbility) ability, ability.getManaCosts());
} else {

View file

@ -418,7 +418,7 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
// extraPredicates from some filters is player related, you don't need it here
List<Predicate> list = new ArrayList<>();
Predicates.collectAllComponents(filter.getPredicates(), list);
if (list.stream().anyMatch(p -> p instanceof SubType.SubTypePredicate)) {
if (list.stream().anyMatch(SubType.SubTypePredicate.class::isInstance)) {
this.addDependedToType(DependencyType.AddingCreatureType);
}
}

View file

@ -118,7 +118,7 @@ class CipherStoreEffect extends OneShotEffect {
Card copyCard = game.copyCard(cipherCard, source, controller.getId());
SpellAbility ability = copyCard.getSpellAbility();
// remove the cipher effect from the copy
ability.getEffects().removeIf(effect -> effect instanceof CipherEffect);
ability.getEffects().removeIf(CipherEffect.class::isInstance);
controller.cast(ability, game, true, new ApprovingObject(source, game));
}

View file

@ -56,7 +56,7 @@ public class CastAsThoughItHadFlashAllEffect extends AsThoughEffectImpl {
if (card != null) {
//Allow lands with morph to be played at instant speed
if (card.isLand(game)) {
boolean morphAbility = card.getAbilities().stream().anyMatch(ability -> ability instanceof MorphAbility);
boolean morphAbility = card.getAbilities().stream().anyMatch(MorphAbility.class::isInstance);
if (morphAbility) {
Card cardCopy = card.copy();
cardCopy.removeAllCardTypes(game);

View file

@ -34,7 +34,7 @@ public class FlankingAbility extends TriggeredAbilityImpl {
Permanent permanent = game.getPermanent(event.getSourceId());
if (permanent != null) {
boolean hasFlankingAbility
= permanent.getAbilities().stream().anyMatch(ability -> ability instanceof FlankingAbility);
= permanent.getAbilities().stream().anyMatch(FlankingAbility.class::isInstance);
if (!hasFlankingAbility) {
for (Effect effect : this.getEffects()) {

View file

@ -95,7 +95,7 @@ public class FilterCard extends FilterObject<Card> {
// card filter can't contain controller predicate (only permanents on battlefield have controller)
List<Predicate> list = new ArrayList<>();
Predicates.collectAllComponents(predicate, list);
if (list.stream().anyMatch(p -> p instanceof TargetController.ControllerPredicate)) {
if (list.stream().anyMatch(TargetController.ControllerPredicate.class::isInstance)) {
throw new IllegalArgumentException("Card filter doesn't support controller predicate");
}
}

View file

@ -3706,7 +3706,7 @@ public abstract class PlayerImpl implements Player, Serializable {
ManaOptions manaFull = availableMana.copy();
if (ability instanceof SpellAbility) {
for (AlternateManaPaymentAbility altAbility : CardUtil.getAbilities(object, game).stream()
.filter(a -> a instanceof AlternateManaPaymentAbility)
.filter(AlternateManaPaymentAbility.class::isInstance)
.map(a -> (AlternateManaPaymentAbility) a)
.collect(Collectors.toList())) {
ManaOptions manaSpecial = altAbility.getManaOptions(ability, game, ability.getManaCostsToPay());
@ -3739,7 +3739,7 @@ public abstract class PlayerImpl implements Player, Serializable {
if (ability instanceof AlternativeSourceCosts && object != null && !(object instanceof Permanent)) {
ActivatedAbility playAbility = null;
if (object.isLand(game)) {
playAbility = (PlayLandAbility) CardUtil.getAbilities(object, game).stream().filter(a -> a instanceof PlayLandAbility).findFirst().orElse(null);
playAbility = (PlayLandAbility) CardUtil.getAbilities(object, game).stream().filter(PlayLandAbility.class::isInstance).findFirst().orElse(null);
} else if (object instanceof Card) {
playAbility = ((Card) object).getSpellAbility();
}