refactor: clean up some superfluous null filters in optionals

This commit is contained in:
xenohedron 2024-11-29 02:34:43 -05:00
parent b1f914bbf4
commit faeca638de
15 changed files with 1 additions and 20 deletions

View file

@ -125,7 +125,6 @@ class AirtightAlibiReplacementEffect extends ReplacementEffectImpl {
public boolean applies(GameEvent event, Ability source, Game game) {
return Optional
.ofNullable(source.getSourcePermanentIfItStillExists(game))
.filter(Objects::nonNull)
.map(Permanent::getAttachedTo)
.map(event.getTargetId()::equals)
.orElse(false);

View file

@ -76,11 +76,9 @@ class AssaultIntercessorEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
return Optional
.ofNullable(getValue("creatureDied"))
.filter(Objects::nonNull)
.map(Permanent.class::cast)
.map(Controllable::getControllerId)
.map(game::getPlayer)
.filter(Objects::nonNull)
.map(player -> player.loseLife(2, game, source, false) > 0)
.orElse(false);
}

View file

@ -67,7 +67,6 @@ enum BrassKnucklesCondition implements Condition {
.ofNullable(source.getSourcePermanentIfItStillExists(game))
.map(Permanent::getAttachedTo)
.map(game::getPermanent)
.filter(Objects::nonNull)
.map(Permanent::getAttachments)
.map(Collection::stream)
.map(stream -> stream.map(game::getPermanent))

View file

@ -114,7 +114,6 @@ class ConquerorsFlailEffect extends ContinuousRuleModifyingEffectImpl {
.ofNullable(source.getSourcePermanentIfItStillExists(game))
.map(Permanent::getAttachedTo)
.map(game::getPermanent)
.filter(Objects::nonNull)
.map(permanent -> permanent.isCreature(game))
.orElse(false);
}

View file

@ -90,7 +90,6 @@ class ElspethsTalentTriggeredAbility extends TriggeredAbilityImpl {
&& event.getSourceId().equals(permanent.getAttachedTo())
&& isControlledBy(event.getPlayerId())
&& Optional.ofNullable(game.getStack().getStackObject(event.getSourceId()))
.filter(Objects::nonNull)
.map(StackObject::getStackAbility)
.map(LoyaltyAbility.class::isInstance)
.orElse(false);

View file

@ -69,7 +69,6 @@ enum EmergentWoodwurmPredicate implements ObjectSourcePlayerPredicate<Card> {
.of(input)
.map(ObjectSourcePlayer::getSource)
.map(ability -> ability.getSourcePermanentOrLKI(game))
.filter(Objects::nonNull)
.map(MageObject::getPower)
.map(MageInt::getValue)
.map(i -> input.getObject().getManaValue() <= i)

View file

@ -77,7 +77,6 @@ enum GuardianScalelordPredicate implements ObjectSourcePlayerPredicate<Card> {
public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
return Optional
.ofNullable(input.getSource().getSourcePermanentOrLKI(game))
.filter(Objects::nonNull)
.map(MageObject::getPower)
.map(MageInt::getValue)
.map(p -> input.getObject().getManaValue() <= p)

View file

@ -78,10 +78,9 @@ enum NarsetEnlightenedExilePredicate implements ObjectSourcePlayerPredicate<Card
public boolean apply(ObjectSourcePlayer<Card> input, Game game) {
return Optional
.ofNullable(input.getSource().getSourcePermanentOrLKI(game))
.filter(Objects::nonNull)
.map(MageObject::getPower)
.map(MageInt::getValue)
.map(p -> input.getObject().getManaValue() < p)
.orElse(false);
}
}
}

View file

@ -103,11 +103,9 @@ class PainDistributorEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
return Optional
.ofNullable(getValue("permanentDied"))
.filter(Objects::nonNull)
.map(Permanent.class::cast)
.map(Controllable::getControllerId)
.map(game::getPlayer)
.filter(Objects::nonNull)
.map(player -> player.damage(1, source, game) > 0)
.orElse(false);
}

View file

@ -110,7 +110,6 @@ enum QuintoriusLoremasterPredicate implements ObjectSourcePlayerPredicate<Card>
UUID exileZoneId = CardUtil.getExileZoneId(game, quintorius.getId(), quintorius.getZoneChangeCounter(game));
return exile.getExileZone(exileZoneId);
})
.filter(Objects::nonNull)
.map(exile -> exile.contains(input.getObject().getId()))
.orElse(false);
}

View file

@ -70,7 +70,6 @@ enum RangersOfIthilienPredicate implements ObjectSourcePlayerPredicate<Permanent
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return Optional
.ofNullable(input.getSource().getSourcePermanentIfItStillExists(game))
.filter(Objects::nonNull)
.map(MageObject::getPower)
.map(MageInt::getValue)
.map(i -> i > input.getObject().getPower().getValue())

View file

@ -77,11 +77,9 @@ class RingwraithsEffect extends OneShotEffect {
return Optional
.ofNullable(getTargetPointer().getFirst(game, source))
.map(game::getPermanent)
.filter(Objects::nonNull)
.filter(permanent -> permanent.isLegendary(game))
.map(Controllable::getControllerId)
.map(game::getPlayer)
.filter(Objects::nonNull)
.map(player -> player.loseLife(3, game, source, false) > 0)
.orElse(false);
}

View file

@ -79,7 +79,6 @@ enum SurgeEngineCondition implements Condition {
public boolean apply(Game game, Ability source) {
return Optional
.ofNullable(source.getSourcePermanentIfItStillExists(game))
.filter(Objects::nonNull)
.map(permanent -> !permanent.hasAbility(DefenderAbility.getInstance(), game))
.orElse(false);
}
@ -94,7 +93,6 @@ class SurgeEngineAbility extends ActivatedAbilityImpl {
private static final Condition staticCondition = (game, source) -> Optional
.ofNullable(source.getSourcePermanentIfItStillExists(game))
.filter(Objects::nonNull)
.map(permanent -> permanent.getColor(game))
.map(ObjectColor::isBlue)
.orElse(false);

View file

@ -74,7 +74,6 @@ class ThrashingFrontlinerTriggeredAbility extends TriggeredAbilityImpl {
.ofNullable(this.getSourceId())
.map(game.getCombat()::getDefenderId)
.map(game::getPermanent)
.filter(Objects::nonNull)
.map(permanent -> permanent.isBattle(game))
.orElse(false);
}

View file

@ -73,7 +73,6 @@ class WarTrainedSlasherTriggeredAbility extends TriggeredAbilityImpl {
.ofNullable(this.getSourceId())
.map(game.getCombat()::getDefenderId)
.map(game::getPermanent)
.filter(Objects::nonNull)
.map(permanent -> permanent.isBattle(game))
.orElse(false);
}