From deb29c0659336b7df407a7696fd88a7a1360d531 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Wed, 29 Jun 2022 18:32:15 -0400 Subject: [PATCH] replaced instances of Optional::of with Optional::ofNullable (fixes #9183) --- Mage.Sets/src/mage/cards/a/AmuletOfVigor.java | 2 +- Mage.Sets/src/mage/cards/b/BhaalLordOfMurder.java | 4 +--- Mage.Sets/src/mage/cards/b/BrassKnuckles.java | 3 +-- Mage.Sets/src/mage/cards/c/ConquerorsFlail.java | 3 +-- Mage.Sets/src/mage/cards/c/CrewCaptain.java | 4 +--- Mage.Sets/src/mage/cards/d/DelayedBlastFireball.java | 2 +- Mage.Sets/src/mage/cards/d/DescentIntoAvernus.java | 4 +--- Mage.Sets/src/mage/cards/f/FaldornDreadWolfHerald.java | 4 +--- Mage.Sets/src/mage/cards/f/FolkHero.java | 4 +--- Mage.Sets/src/mage/cards/g/GavelOfTheRighteous.java | 8 +++++--- Mage.Sets/src/mage/cards/g/GreatswordOfTyr.java | 4 +--- Mage.Sets/src/mage/cards/g/GuildswornProwler.java | 4 +--- Mage.Sets/src/mage/cards/h/HauntedOne.java | 4 +--- Mage.Sets/src/mage/cards/j/JourneyToTheLostCity.java | 4 ++-- Mage.Sets/src/mage/cards/l/LivaanCultistOfTiamat.java | 4 +--- Mage.Sets/src/mage/cards/l/LozhanDragonsLegacy.java | 4 +--- Mage.Sets/src/mage/cards/l/LuxiorGiadasGift.java | 8 +++----- Mage.Sets/src/mage/cards/m/Manaplasm.java | 2 +- Mage.Sets/src/mage/cards/m/MockingDoppelganger.java | 4 +--- Mage.Sets/src/mage/cards/m/MyrkulLordOfBones.java | 4 +--- Mage.Sets/src/mage/cards/p/PassionateArchaeologist.java | 2 +- Mage.Sets/src/mage/cards/p/PublicEnemy.java | 3 +-- Mage.Sets/src/mage/cards/s/SailorsBane.java | 4 +--- Mage.Sets/src/mage/cards/s/SchemingFence.java | 4 ++-- Mage.Sets/src/mage/cards/s/StunningStrike.java | 4 +--- Mage.Sets/src/mage/cards/v/ViciousBattlerager.java | 4 +--- .../common/BecomesBlockedAttachedTriggeredAbility.java | 4 +--- .../common/GiveManaAbilityAndCastSourceAbility.java | 2 +- 28 files changed, 36 insertions(+), 71 deletions(-) diff --git a/Mage.Sets/src/mage/cards/a/AmuletOfVigor.java b/Mage.Sets/src/mage/cards/a/AmuletOfVigor.java index 383366fa4f1..232e767b8d2 100644 --- a/Mage.Sets/src/mage/cards/a/AmuletOfVigor.java +++ b/Mage.Sets/src/mage/cards/a/AmuletOfVigor.java @@ -78,7 +78,7 @@ class AmuletOfVigorTriggeredAbility extends TriggeredAbilityImpl { // that triggers depends on stack order, so make each trigger unique with extra info return "Whenever a permanent enters the battlefield tapped and under your control, untap it." + Optional - .of(this.getEffects().get(0).getTargetPointer()) + .ofNullable(this.getEffects().get(0).getTargetPointer()) .map(targetPointer -> targetPointer.getData("triggeredName")) .filter(s -> s != null && !s.isEmpty()) .map(s -> " Triggered permanent: " + s) diff --git a/Mage.Sets/src/mage/cards/b/BhaalLordOfMurder.java b/Mage.Sets/src/mage/cards/b/BhaalLordOfMurder.java index 9aae7aa359f..58779d7fe27 100644 --- a/Mage.Sets/src/mage/cards/b/BhaalLordOfMurder.java +++ b/Mage.Sets/src/mage/cards/b/BhaalLordOfMurder.java @@ -24,7 +24,6 @@ import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCreaturePermanent; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -79,8 +78,7 @@ enum BhaalLordOfMurderCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - return Optional.of(game.getPlayer(source.getControllerId())) - .filter(Objects::nonNull) + return Optional.ofNullable(game.getPlayer(source.getControllerId())) .map(Player::getLife) .map(x -> 2 * x >= game.getStartingLife()) .orElse(false); diff --git a/Mage.Sets/src/mage/cards/b/BrassKnuckles.java b/Mage.Sets/src/mage/cards/b/BrassKnuckles.java index 9e6dbc2839e..cc5a5b226b0 100644 --- a/Mage.Sets/src/mage/cards/b/BrassKnuckles.java +++ b/Mage.Sets/src/mage/cards/b/BrassKnuckles.java @@ -64,8 +64,7 @@ enum BrassKnucklesCondition implements Condition { @Override public boolean apply(Game game, Ability source) { return Optional - .of(source.getSourcePermanentIfItStillExists(game)) - .filter(Objects::nonNull) + .ofNullable(source.getSourcePermanentIfItStillExists(game)) .map(Permanent::getAttachedTo) .map(game::getPermanent) .filter(Objects::nonNull) diff --git a/Mage.Sets/src/mage/cards/c/ConquerorsFlail.java b/Mage.Sets/src/mage/cards/c/ConquerorsFlail.java index d0b0294ccd1..372361be473 100644 --- a/Mage.Sets/src/mage/cards/c/ConquerorsFlail.java +++ b/Mage.Sets/src/mage/cards/c/ConquerorsFlail.java @@ -116,8 +116,7 @@ class ConquerorsFlailEffect extends ContinuousRuleModifyingEffectImpl { return game.isActivePlayer(source.getControllerId()) && game.getOpponents(source.getControllerId()).contains(event.getPlayerId()) && Optional - .of(source.getSourcePermanentIfItStillExists(game)) - .filter(Objects::nonNull) + .ofNullable(source.getSourcePermanentIfItStillExists(game)) .map(Permanent::getAttachedTo) .map(game::getPermanent) .filter(Objects::nonNull) diff --git a/Mage.Sets/src/mage/cards/c/CrewCaptain.java b/Mage.Sets/src/mage/cards/c/CrewCaptain.java index fa70c900e80..a6bfde66d44 100644 --- a/Mage.Sets/src/mage/cards/c/CrewCaptain.java +++ b/Mage.Sets/src/mage/cards/c/CrewCaptain.java @@ -15,7 +15,6 @@ import mage.constants.SubType; import mage.game.Game; import mage.game.permanent.Permanent; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -57,8 +56,7 @@ enum CrewCaptainCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - return Optional.of(source.getSourcePermanentIfItStillExists(game)) - .filter(Objects::nonNull) + return Optional.ofNullable(source.getSourcePermanentIfItStillExists(game)) .map(Permanent::getTurnsOnBattlefield) .orElseGet(() -> -1) == 0; } diff --git a/Mage.Sets/src/mage/cards/d/DelayedBlastFireball.java b/Mage.Sets/src/mage/cards/d/DelayedBlastFireball.java index 27869758212..fddb85970b5 100644 --- a/Mage.Sets/src/mage/cards/d/DelayedBlastFireball.java +++ b/Mage.Sets/src/mage/cards/d/DelayedBlastFireball.java @@ -56,7 +56,7 @@ enum DelayedBlastFireballValue implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { return Optional - .of(sourceAbility.getSourceObjectIfItStillExists(game)) + .ofNullable(sourceAbility.getSourceObjectIfItStillExists(game)) .filter(Spell.class::isInstance) .map(Spell.class::cast) .map(Spell::getFromZone) diff --git a/Mage.Sets/src/mage/cards/d/DescentIntoAvernus.java b/Mage.Sets/src/mage/cards/d/DescentIntoAvernus.java index adeab9b5b97..fdef10661e8 100644 --- a/Mage.Sets/src/mage/cards/d/DescentIntoAvernus.java +++ b/Mage.Sets/src/mage/cards/d/DescentIntoAvernus.java @@ -16,7 +16,6 @@ import mage.counters.CounterType; import mage.game.Game; import mage.game.permanent.token.TreasureToken; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -71,8 +70,7 @@ class DescentIntoAvernusEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { int count = Optional - .of(source.getSourcePermanentOrLKI(game)) - .filter(Objects::nonNull) + .ofNullable(source.getSourcePermanentOrLKI(game)) .map(permanent -> permanent.getCounters(game)) .map(counters -> counters.getCount(CounterType.DESCENT)) .orElse(0); diff --git a/Mage.Sets/src/mage/cards/f/FaldornDreadWolfHerald.java b/Mage.Sets/src/mage/cards/f/FaldornDreadWolfHerald.java index ce58a90eed1..c488486b06e 100644 --- a/Mage.Sets/src/mage/cards/f/FaldornDreadWolfHerald.java +++ b/Mage.Sets/src/mage/cards/f/FaldornDreadWolfHerald.java @@ -21,7 +21,6 @@ import mage.game.events.GameEvent; import mage.game.permanent.token.WolfToken; import mage.game.stack.Spell; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -90,8 +89,7 @@ class FaldornDreadWolfHeraldTriggeredAbility extends TriggeredAbilityImpl { return eEvent.getFromZone() == Zone.EXILED && eEvent.getTarget().isLand(game); case SPELL_CAST: return Optional - .of(game.getSpell(event.getTargetId())) - .filter(Objects::nonNull) + .ofNullable(game.getSpell(event.getTargetId())) .map(Spell::getFromZone) .equals(Zone.EXILED); } diff --git a/Mage.Sets/src/mage/cards/f/FolkHero.java b/Mage.Sets/src/mage/cards/f/FolkHero.java index 3517be8c37a..3d0f099d1c8 100644 --- a/Mage.Sets/src/mage/cards/f/FolkHero.java +++ b/Mage.Sets/src/mage/cards/f/FolkHero.java @@ -17,7 +17,6 @@ import mage.filter.predicate.ObjectSourcePlayerPredicate; import mage.game.Game; import mage.game.stack.Spell; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -63,8 +62,7 @@ enum FolkHeroPredicate implements ObjectSourcePlayerPredicate { @Override public boolean apply(ObjectSourcePlayer input, Game game) { return Optional - .of(input.getSource().getSourcePermanentIfItStillExists(game)) - .filter(Objects::nonNull) + .ofNullable(input.getSource().getSourcePermanentIfItStillExists(game)) .map(permanent -> input.getObject().shareCreatureTypes(game, permanent)) .orElse(false); } diff --git a/Mage.Sets/src/mage/cards/g/GavelOfTheRighteous.java b/Mage.Sets/src/mage/cards/g/GavelOfTheRighteous.java index b5d1f5cfdf4..7b70b64eed9 100644 --- a/Mage.Sets/src/mage/cards/g/GavelOfTheRighteous.java +++ b/Mage.Sets/src/mage/cards/g/GavelOfTheRighteous.java @@ -22,7 +22,10 @@ import mage.counters.Counter; import mage.counters.CounterType; import mage.game.Game; -import java.util.*; +import java.util.Collection; +import java.util.HashMap; +import java.util.Optional; +import java.util.UUID; import java.util.stream.IntStream; /** @@ -78,8 +81,7 @@ enum GavelOfTheRighteousCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - return Optional.of(source.getSourcePermanentIfItStillExists(game)) - .filter(Objects::nonNull) + return Optional.ofNullable(source.getSourcePermanentIfItStillExists(game)) .map(permanent -> permanent.getCounters(game)) .map(HashMap::values) .map(Collection::stream) diff --git a/Mage.Sets/src/mage/cards/g/GreatswordOfTyr.java b/Mage.Sets/src/mage/cards/g/GreatswordOfTyr.java index ba2671b22c8..8fb67ff0454 100644 --- a/Mage.Sets/src/mage/cards/g/GreatswordOfTyr.java +++ b/Mage.Sets/src/mage/cards/g/GreatswordOfTyr.java @@ -20,7 +20,6 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -67,8 +66,7 @@ enum GreatswordOfTyrPredicate implements ObjectSourcePlayerPredicate @Override public boolean apply(ObjectSourcePlayer input, Game game) { - return Optional.of(input.getSource().getSourcePermanentOrLKI(game)) - .filter(Objects::nonNull) + return Optional.ofNullable(input.getSource().getSourcePermanentOrLKI(game)) .map(Permanent::getAttachedTo) .map(uuid -> game.getCombat().getDefendingPlayerId(uuid, game)) .map(input.getObject()::isControlledBy) diff --git a/Mage.Sets/src/mage/cards/g/GuildswornProwler.java b/Mage.Sets/src/mage/cards/g/GuildswornProwler.java index c479d2a70bd..a7d63dbdbdc 100644 --- a/Mage.Sets/src/mage/cards/g/GuildswornProwler.java +++ b/Mage.Sets/src/mage/cards/g/GuildswornProwler.java @@ -14,7 +14,6 @@ import mage.constants.SubType; import mage.game.Game; import mage.watchers.common.BlockingOrBlockedWatcher; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -58,8 +57,7 @@ enum GuildswornProwlerCondition implements Condition { @Override public boolean apply(Game game, Ability source) { return Optional - .of(source.getSourcePermanentOrLKI(game)) - .filter(Objects::nonNull) + .ofNullable(source.getSourcePermanentOrLKI(game)) .map(permanent -> !BlockingOrBlockedWatcher.check(permanent, game)) .orElse(false); } diff --git a/Mage.Sets/src/mage/cards/h/HauntedOne.java b/Mage.Sets/src/mage/cards/h/HauntedOne.java index 1fdb85b71e5..4cb6fb296a6 100644 --- a/Mage.Sets/src/mage/cards/h/HauntedOne.java +++ b/Mage.Sets/src/mage/cards/h/HauntedOne.java @@ -18,7 +18,6 @@ import mage.filter.predicate.ObjectSourcePlayerPredicate; import mage.game.Game; import mage.game.permanent.Permanent; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -74,8 +73,7 @@ enum HauntedOnePredicate implements ObjectSourcePlayerPredicate { @Override public boolean apply(ObjectSourcePlayer input, Game game) { - return Optional.of(input.getSource().getSourcePermanentOrLKI(game)) - .filter(Objects::nonNull) + return Optional.ofNullable(input.getSource().getSourcePermanentOrLKI(game)) .map(permanent -> permanent.shareCreatureTypes(game, input.getObject())) .orElse(false); } diff --git a/Mage.Sets/src/mage/cards/j/JourneyToTheLostCity.java b/Mage.Sets/src/mage/cards/j/JourneyToTheLostCity.java index 2bc2cf5e500..7192314f079 100644 --- a/Mage.Sets/src/mage/cards/j/JourneyToTheLostCity.java +++ b/Mage.Sets/src/mage/cards/j/JourneyToTheLostCity.java @@ -106,7 +106,7 @@ class JourneyToTheLostCityEffect extends RollDieWithResultTableEffect { int count = cards.count(StaticFilters.FILTER_CARD_CREATURE, game); if (count > 0) { for (UUID tokenId : token.getLastAddedTokenIds()) { - Optional.of(game.getPermanent(tokenId)) + Optional.ofNullable(game.getPermanent(tokenId)) .ifPresent(permanent -> permanent.addCounters( CounterType.P1P1.createInstance(count), source, game )); @@ -123,7 +123,7 @@ class JourneyToTheLostCityEffect extends RollDieWithResultTableEffect { StaticFilters.FILTER_CARD_PERMANENT, game ), Zone.BATTLEFIELD, source, game); } - Optional.of(source.getSourcePermanentIfItStillExists(game)) + Optional.ofNullable(source.getSourcePermanentIfItStillExists(game)) .ifPresent(permanent -> permanent.sacrifice(source, game)); return true; } diff --git a/Mage.Sets/src/mage/cards/l/LivaanCultistOfTiamat.java b/Mage.Sets/src/mage/cards/l/LivaanCultistOfTiamat.java index 25b4c3d03db..0468dab09e9 100644 --- a/Mage.Sets/src/mage/cards/l/LivaanCultistOfTiamat.java +++ b/Mage.Sets/src/mage/cards/l/LivaanCultistOfTiamat.java @@ -19,7 +19,6 @@ import mage.game.Game; import mage.game.stack.Spell; import mage.target.common.TargetCreaturePermanent; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -63,8 +62,7 @@ enum LivaanCultistOfTiamatValue implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - return Optional.of(effect.getValue("spellCast")) - .filter(Objects::nonNull) + return Optional.ofNullable(effect.getValue("spellCast")) .map(Spell.class::cast) .map(Spell::getManaValue) .orElse(0); diff --git a/Mage.Sets/src/mage/cards/l/LozhanDragonsLegacy.java b/Mage.Sets/src/mage/cards/l/LozhanDragonsLegacy.java index 13a3424e8bc..1f4a8434fec 100644 --- a/Mage.Sets/src/mage/cards/l/LozhanDragonsLegacy.java +++ b/Mage.Sets/src/mage/cards/l/LozhanDragonsLegacy.java @@ -20,7 +20,6 @@ import mage.game.Game; import mage.game.stack.Spell; import mage.target.common.TargetAnyTarget; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -76,9 +75,8 @@ enum LozhanDragonsLegacyValue implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - return Optional.of(effect.getValue("spellCast")) + return Optional.ofNullable(effect.getValue("spellCast")) .map(Spell.class::cast) - .filter(Objects::nonNull) .map(Spell::getManaValue) .orElse(0); } diff --git a/Mage.Sets/src/mage/cards/l/LuxiorGiadasGift.java b/Mage.Sets/src/mage/cards/l/LuxiorGiadasGift.java index 83a6495acfc..58baed61b92 100644 --- a/Mage.Sets/src/mage/cards/l/LuxiorGiadasGift.java +++ b/Mage.Sets/src/mage/cards/l/LuxiorGiadasGift.java @@ -17,10 +17,10 @@ import mage.filter.common.FilterControlledPlaneswalkerPermanent; import mage.game.Game; import mage.game.permanent.Permanent; import mage.target.TargetPermanent; +import mage.target.common.TargetControlledCreaturePermanent; import java.util.*; import java.util.stream.IntStream; -import mage.target.common.TargetControlledCreaturePermanent; /** * @author TheElk801 @@ -65,8 +65,7 @@ enum LuxiorGiadasGiftValue implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - return Optional.of(sourceAbility.getSourcePermanentIfItStillExists(game)) - .filter(Objects::nonNull) + return Optional.ofNullable(sourceAbility.getSourcePermanentIfItStillExists(game)) .map(Permanent::getAttachedTo) .map(game::getPermanent) .filter(Objects::nonNull) @@ -112,8 +111,7 @@ class LuxiorGiadasGiftEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - Optional.of(source.getSourcePermanentIfItStillExists(game)) - .filter(Objects::nonNull) + Optional.ofNullable(source.getSourcePermanentIfItStillExists(game)) .map(Permanent::getAttachedTo) .map(game::getPermanent) .ifPresent(permanent -> { diff --git a/Mage.Sets/src/mage/cards/m/Manaplasm.java b/Mage.Sets/src/mage/cards/m/Manaplasm.java index 18f35efb833..e6b27982f19 100644 --- a/Mage.Sets/src/mage/cards/m/Manaplasm.java +++ b/Mage.Sets/src/mage/cards/m/Manaplasm.java @@ -51,7 +51,7 @@ enum ManaplasmValue implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - return Optional.of((Spell) effect.getValue("spellCast")).map(Spell::getManaValue).orElse(0); + return Optional.ofNullable((Spell) effect.getValue("spellCast")).map(Spell::getManaValue).orElse(0); } @Override diff --git a/Mage.Sets/src/mage/cards/m/MockingDoppelganger.java b/Mage.Sets/src/mage/cards/m/MockingDoppelganger.java index c5b0aaa08c5..05a192c8726 100644 --- a/Mage.Sets/src/mage/cards/m/MockingDoppelganger.java +++ b/Mage.Sets/src/mage/cards/m/MockingDoppelganger.java @@ -25,7 +25,6 @@ import mage.game.permanent.Permanent; import mage.util.CardUtil; import mage.util.functions.CopyApplier; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -87,8 +86,7 @@ enum MockingDoppelgangerPredicate implements ObjectSourcePlayerPredicate input, Game game) { return Optional - .of(input.getSource().getSourcePermanentIfItStillExists(game)) - .filter(Objects::nonNull) + .ofNullable(input.getSource().getSourcePermanentIfItStillExists(game)) .map(permanent -> CardUtil.haveSameNames(permanent, input.getObject())) .orElse(false); } diff --git a/Mage.Sets/src/mage/cards/m/MyrkulLordOfBones.java b/Mage.Sets/src/mage/cards/m/MyrkulLordOfBones.java index cc319a6e17e..2fd39f38742 100644 --- a/Mage.Sets/src/mage/cards/m/MyrkulLordOfBones.java +++ b/Mage.Sets/src/mage/cards/m/MyrkulLordOfBones.java @@ -22,7 +22,6 @@ import mage.game.Game; import mage.game.permanent.PermanentCard; import mage.players.Player; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -69,8 +68,7 @@ enum MyrkulLordOfBonesCondition implements Condition { @Override public boolean apply(Game game, Ability source) { - return Optional.of(game.getPlayer(source.getControllerId())) - .filter(Objects::nonNull) + return Optional.ofNullable(game.getPlayer(source.getControllerId())) .map(Player::getLife) .map(x -> 2 * x >= game.getStartingLife()) .orElse(false); diff --git a/Mage.Sets/src/mage/cards/p/PassionateArchaeologist.java b/Mage.Sets/src/mage/cards/p/PassionateArchaeologist.java index b9613ce1ab5..59f149e7fa3 100644 --- a/Mage.Sets/src/mage/cards/p/PassionateArchaeologist.java +++ b/Mage.Sets/src/mage/cards/p/PassionateArchaeologist.java @@ -64,7 +64,7 @@ enum PassionateArchaeologistValue implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { return Optional - .of(effect.getValue("spellCast")) + .ofNullable(effect.getValue("spellCast")) .filter(Spell.class::isInstance) .map(Spell.class::cast) .map(Spell::getManaValue) diff --git a/Mage.Sets/src/mage/cards/p/PublicEnemy.java b/Mage.Sets/src/mage/cards/p/PublicEnemy.java index ae9bbf15c89..0d7c675a0ed 100644 --- a/Mage.Sets/src/mage/cards/p/PublicEnemy.java +++ b/Mage.Sets/src/mage/cards/p/PublicEnemy.java @@ -80,8 +80,7 @@ class PublicEnemyEffect extends RequirementEffect { @Override public UUID mustAttackDefender(Ability source, Game game) { - return Optional.of(source.getSourcePermanentIfItStillExists(game)) - .filter(Objects::nonNull) + return Optional.ofNullable(source.getSourcePermanentIfItStillExists(game)) .map(Permanent::getAttachedTo) .map(game::getControllerId) .orElse(null); diff --git a/Mage.Sets/src/mage/cards/s/SailorsBane.java b/Mage.Sets/src/mage/cards/s/SailorsBane.java index 10f36d95c46..cdaf2b0da51 100644 --- a/Mage.Sets/src/mage/cards/s/SailorsBane.java +++ b/Mage.Sets/src/mage/cards/s/SailorsBane.java @@ -23,7 +23,6 @@ import mage.filter.predicate.Predicates; import mage.game.Game; import mage.players.Player; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -81,8 +80,7 @@ enum SailorsBaneValue implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { return Optional - .of(game.getPlayer(sourceAbility.getControllerId())) - .filter(Objects::nonNull) + .ofNullable(game.getPlayer(sourceAbility.getControllerId())) .map(Player::getGraveyard) .map(graveyard -> graveyard.count(filter, game)) .orElse(0) diff --git a/Mage.Sets/src/mage/cards/s/SchemingFence.java b/Mage.Sets/src/mage/cards/s/SchemingFence.java index 673b90b2bd1..774ff04ab41 100644 --- a/Mage.Sets/src/mage/cards/s/SchemingFence.java +++ b/Mage.Sets/src/mage/cards/s/SchemingFence.java @@ -140,7 +140,7 @@ class SchemingFenceDisableEffect extends ContinuousRuleModifyingEffectImpl { return false; } - return Optional.of(chosenPermanentMOR) + return Optional.ofNullable(chosenPermanentMOR) .map(MageObjectReference.class::cast) .filter(mor -> mor.zoneCounterIsCurrent(game)) .map(MageObjectReference::getSourceId) // TODO: Are both of this line and the next one necessary? @@ -177,7 +177,7 @@ class SchemingFenceGainEffect extends ContinuousEffectImpl { return false; } - Permanent chosenPermanent = Optional.of(chosenPermanentMOR) + Permanent chosenPermanent = Optional.ofNullable(chosenPermanentMOR) .map(MageObjectReference.class::cast) .map(mor -> mor.getPermanent(game)) .orElse(null); diff --git a/Mage.Sets/src/mage/cards/s/StunningStrike.java b/Mage.Sets/src/mage/cards/s/StunningStrike.java index 22ee4edcb4b..2a6cafe8c54 100644 --- a/Mage.Sets/src/mage/cards/s/StunningStrike.java +++ b/Mage.Sets/src/mage/cards/s/StunningStrike.java @@ -24,7 +24,6 @@ import mage.game.permanent.Permanent; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -93,8 +92,7 @@ class StunningStrikeEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Optional.of(source.getSourcePermanentOrLKI(game)) - .filter(Objects::nonNull) + Optional.ofNullable(source.getSourcePermanentOrLKI(game)) .map(Permanent::getAttachedTo) .map(game::getPermanent) .ifPresent(permanent -> { diff --git a/Mage.Sets/src/mage/cards/v/ViciousBattlerager.java b/Mage.Sets/src/mage/cards/v/ViciousBattlerager.java index 5d01108e6f5..8cbd552b5b5 100644 --- a/Mage.Sets/src/mage/cards/v/ViciousBattlerager.java +++ b/Mage.Sets/src/mage/cards/v/ViciousBattlerager.java @@ -13,7 +13,6 @@ import mage.constants.Outcome; import mage.constants.SubType; import mage.game.Game; -import java.util.Objects; import java.util.Optional; import java.util.UUID; @@ -67,8 +66,7 @@ class ViciousBattleragerEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - return Optional.of(game.getPlayer(game.getControllerId(getTargetPointer().getFirst(game, source)))) - .filter(Objects::nonNull) + return Optional.ofNullable(game.getPlayer(game.getControllerId(getTargetPointer().getFirst(game, source)))) .map(player -> player.loseLife(5, game, source, false) > 0) .orElse(false); } diff --git a/Mage/src/main/java/mage/abilities/common/BecomesBlockedAttachedTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/BecomesBlockedAttachedTriggeredAbility.java index 7cf7043efe6..6b20ccc69de 100644 --- a/Mage/src/main/java/mage/abilities/common/BecomesBlockedAttachedTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/BecomesBlockedAttachedTriggeredAbility.java @@ -9,7 +9,6 @@ import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.target.targetpointer.FixedTarget; -import java.util.Objects; import java.util.Optional; /** @@ -41,8 +40,7 @@ public class BecomesBlockedAttachedTriggeredAbility extends TriggeredAbilityImpl @Override public boolean checkTrigger(GameEvent event, Game game) { Permanent permanent = Optional - .of(getSourcePermanentOrLKI(game)) - .filter(Objects::nonNull) + .ofNullable(getSourcePermanentOrLKI(game)) .map(Permanent::getAttachedTo) .map(game::getPermanent) .orElse(null); diff --git a/Mage/src/main/java/mage/abilities/common/GiveManaAbilityAndCastSourceAbility.java b/Mage/src/main/java/mage/abilities/common/GiveManaAbilityAndCastSourceAbility.java index db2f5016745..11b396b879f 100644 --- a/Mage/src/main/java/mage/abilities/common/GiveManaAbilityAndCastSourceAbility.java +++ b/Mage/src/main/java/mage/abilities/common/GiveManaAbilityAndCastSourceAbility.java @@ -63,7 +63,7 @@ class CastExiledFromHandCardEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Optional.of(getValue("exiledHandCardRef")) + Optional.ofNullable(getValue("exiledHandCardRef")) .filter(Objects::nonNull) .map(MageObjectReference.class::cast) .map(mor -> mor.getCard(game))