Guava migration - Migrate Optionals

This commit is contained in:
Jetz
2024-09-02 17:52:18 -04:00
parent 8702e299cd
commit ecf25a8c00
8 changed files with 17 additions and 28 deletions

View File

@@ -1,10 +1,10 @@
package forge.game;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.ObjectUtils;
import com.google.common.base.Optional;
import com.google.common.collect.ForwardingTable;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Maps;
@@ -39,7 +39,7 @@ public class GameEntityCounterTable extends ForwardingTable<Optional<Player>, Ga
}
public Integer put(Player putter, GameEntity object, CounterType type, Integer value) {
Optional<Player> o = Optional.fromNullable(putter);
Optional<Player> o = Optional.ofNullable(putter);
Map<CounterType, Integer> map = get(o, object);
if (map == null) {
map = Maps.newHashMap();
@@ -49,7 +49,7 @@ public class GameEntityCounterTable extends ForwardingTable<Optional<Player>, Ga
}
public int get(Player putter, GameEntity object, CounterType type) {
Optional<Player> o = Optional.fromNullable(putter);
Optional<Player> o = Optional.ofNullable(putter);
Map<CounterType, Integer> map = get(o, object);
if (map == null || !map.containsKey(type)) {
return 0;
@@ -76,7 +76,7 @@ public class GameEntityCounterTable extends ForwardingTable<Optional<Player>, Ga
result.putAll(ge.getCounters());
return result;
}
Map<CounterType, Integer> alreadyRemoved = column(ge).get(Optional.absent());
Map<CounterType, Integer> alreadyRemoved = column(ge).get(Optional.<Player>empty());
for (Map.Entry<CounterType, Integer> e : ge.getCounters().entrySet()) {
int rest = e.getValue() - (alreadyRemoved.getOrDefault(e.getKey(), 0));
if (rest > 0) {
@@ -176,7 +176,7 @@ public class GameEntityCounterTable extends ForwardingTable<Optional<Player>, Ga
if (cause != null && cause.hasParam("MaxFromEffect")) {
value = Math.min(value, Integer.parseInt(cause.getParam("MaxFromEffect")) - gm.getKey().getCounters(ec.getKey()));
}
gm.getKey().addCounterInternal(ec.getKey(), value, e.getKey().orNull(), true, result, runParams);
gm.getKey().addCounterInternal(ec.getKey(), value, e.getKey().orElse(null), true, result, runParams);
if (remember && ec.getValue() >= 1) {
cause.getHostCard().addRemembered(gm.getKey());
}

View File

@@ -6,7 +6,6 @@ import java.util.Map.Entry;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.base.Optional;
import forge.game.Game;
import forge.game.GameEntity;

View File

@@ -3,8 +3,8 @@ package forge.game.ability.effects;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import com.google.common.base.Optional;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
@@ -46,14 +46,14 @@ public class ReplaceCounterEffect extends SpellAbilityEffect {
Multimap<CounterType, Player> playerMap = HashMultimap.create();
for (Map.Entry<Optional<Player>, Map<CounterType, Integer>> e : counterTable.entrySet()) {
for (CounterType ct : e.getValue().keySet()) {
playerMap.put(ct, e.getKey().orNull());
playerMap.put(ct, e.getKey().orElse(null));
}
}
// there shouldn't be a case where one of the players is null, and the other is not
for (Map.Entry<CounterType, Collection<Player>> e : playerMap.asMap().entrySet()) {
Optional<Player> p = Optional.fromNullable(chooser.getController().chooseSingleEntityForEffect(new PlayerCollection(e.getValue()), sa, "Choose Player for " + e.getKey().getName(), null));
Optional<Player> p = Optional.ofNullable(chooser.getController().chooseSingleEntityForEffect(new PlayerCollection(e.getValue()), sa, "Choose Player for " + e.getKey().getName(), null));
sa.setReplacingObject(AbilityKey.CounterNum, counterTable.get(p).get(e.getKey()));
int value = AbilityUtils.calculateAmount(card, sa.getParam("Amount"), sa);
@@ -65,7 +65,7 @@ public class ReplaceCounterEffect extends SpellAbilityEffect {
}
} else {
for (Map.Entry<Optional<Player>, Map<CounterType, Integer>> e : counterTable.entrySet()) {
if (!sa.matchesValidParam("ValidSource", e.getKey().orNull())) {
if (!sa.matchesValidParam("ValidSource", e.getKey().orElse(null))) {
continue;
}

View File

@@ -1,10 +1,10 @@
package forge.game.card;
import java.util.List;
import java.util.Optional;
import org.apache.commons.lang3.ObjectUtils;
import com.google.common.base.Optional;
import com.google.common.collect.ForwardingTable;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists;
@@ -40,7 +40,7 @@ public class ActivationTable extends ForwardingTable<SpellAbility, Optional<Stat
SpellAbility original = getOriginal(sa);
if (original != null) {
Optional<StaticAbility> st = Optional.fromNullable(root.getGrantorStatic());
Optional<StaticAbility> st = Optional.ofNullable(root.getGrantorStatic());
List<Player> activators = get(original, st);
if (activators == null) {
@@ -58,7 +58,7 @@ public class ActivationTable extends ForwardingTable<SpellAbility, Optional<Stat
public List<Player> getActivators(SpellAbility sa) {
SpellAbility root = sa.getRootAbility();
SpellAbility original = getOriginal(sa);
Optional<StaticAbility> st = Optional.fromNullable(root.getGrantorStatic());
Optional<StaticAbility> st = Optional.ofNullable(root.getGrantorStatic());
if (contains(original, st)) {
return get(original, st);

View File

@@ -18,7 +18,6 @@
package forge.game.card;
import com.esotericsoftware.minlog.Log;
import com.google.common.base.Optional;
import com.google.common.collect.*;
import forge.GameCommand;
import forge.StaticData;

View File

@@ -19,8 +19,7 @@ package forge.game.cost;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.base.Optional;
import java.util.Optional;
import forge.game.GameEntity;
import forge.game.ability.AbilityUtils;
@@ -119,7 +118,7 @@ public class CostRemoveAnyCounter extends CostPart {
@Override
public boolean payAsDecided(Player ai, PaymentDecision decision, SpellAbility ability, final boolean effect) {
int removed = 0;
for (Entry<GameEntity, Map<CounterType, Integer>> e : decision.counterTable.row(Optional.absent()).entrySet()) {
for (Entry<GameEntity, Map<CounterType, Integer>> e : decision.counterTable.row(Optional.empty()).entrySet()) {
for (Entry<CounterType, Integer> v : e.getValue().entrySet()) {
removed += v.getValue();
e.getKey().subtractCounter(v.getKey(), v.getValue(), ai);

View File

@@ -1,11 +1,10 @@
package forge.game.replacement;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.ObjectUtils;
import com.google.common.base.Optional;
import forge.game.ability.AbilityKey;
import forge.game.card.Card;
import forge.game.card.CounterType;
@@ -85,7 +84,7 @@ public class ReplaceAddCounter extends ReplacementEffect {
Map<Optional<Player>, Map<CounterType, Integer>> counterMap = (Map<Optional<Player>, Map<CounterType, Integer>>) runParams.get(AbilityKey.CounterMap);
for (Map.Entry<Optional<Player>, Map<CounterType, Integer>> e : counterMap.entrySet()) {
if (!matchesValidParam("ValidSource", e.getKey().orNull())) {
if (!matchesValidParam("ValidSource", e.getKey().orElse(null))) {
continue;
}
if (hasParam("ValidCounterType")) {

View File

@@ -17,19 +17,12 @@
*/
package forge.game.replacement;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import forge.game.card.*;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;