mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Guava migration - Migrate Optionals
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
package forge.game;
|
package forge.game;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import com.google.common.collect.ForwardingTable;
|
import com.google.common.collect.ForwardingTable;
|
||||||
import com.google.common.collect.HashBasedTable;
|
import com.google.common.collect.HashBasedTable;
|
||||||
import com.google.common.collect.Maps;
|
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) {
|
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);
|
Map<CounterType, Integer> map = get(o, object);
|
||||||
if (map == null) {
|
if (map == null) {
|
||||||
map = Maps.newHashMap();
|
map = Maps.newHashMap();
|
||||||
@@ -49,7 +49,7 @@ public class GameEntityCounterTable extends ForwardingTable<Optional<Player>, Ga
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int get(Player putter, GameEntity object, CounterType type) {
|
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);
|
Map<CounterType, Integer> map = get(o, object);
|
||||||
if (map == null || !map.containsKey(type)) {
|
if (map == null || !map.containsKey(type)) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -76,7 +76,7 @@ public class GameEntityCounterTable extends ForwardingTable<Optional<Player>, Ga
|
|||||||
result.putAll(ge.getCounters());
|
result.putAll(ge.getCounters());
|
||||||
return result;
|
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()) {
|
for (Map.Entry<CounterType, Integer> e : ge.getCounters().entrySet()) {
|
||||||
int rest = e.getValue() - (alreadyRemoved.getOrDefault(e.getKey(), 0));
|
int rest = e.getValue() - (alreadyRemoved.getOrDefault(e.getKey(), 0));
|
||||||
if (rest > 0) {
|
if (rest > 0) {
|
||||||
@@ -176,7 +176,7 @@ public class GameEntityCounterTable extends ForwardingTable<Optional<Player>, Ga
|
|||||||
if (cause != null && cause.hasParam("MaxFromEffect")) {
|
if (cause != null && cause.hasParam("MaxFromEffect")) {
|
||||||
value = Math.min(value, Integer.parseInt(cause.getParam("MaxFromEffect")) - gm.getKey().getCounters(ec.getKey()));
|
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) {
|
if (remember && ec.getValue() >= 1) {
|
||||||
cause.getHostCard().addRemembered(gm.getKey());
|
cause.getHostCard().addRemembered(gm.getKey());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import java.util.Map.Entry;
|
|||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.GameEntity;
|
import forge.game.GameEntity;
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package forge.game.ability.effects;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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.HashMultimap;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
@@ -46,14 +46,14 @@ public class ReplaceCounterEffect extends SpellAbilityEffect {
|
|||||||
Multimap<CounterType, Player> playerMap = HashMultimap.create();
|
Multimap<CounterType, Player> playerMap = HashMultimap.create();
|
||||||
for (Map.Entry<Optional<Player>, Map<CounterType, Integer>> e : counterTable.entrySet()) {
|
for (Map.Entry<Optional<Player>, Map<CounterType, Integer>> e : counterTable.entrySet()) {
|
||||||
for (CounterType ct : e.getValue().keySet()) {
|
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
|
// 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()) {
|
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()));
|
sa.setReplacingObject(AbilityKey.CounterNum, counterTable.get(p).get(e.getKey()));
|
||||||
int value = AbilityUtils.calculateAmount(card, sa.getParam("Amount"), sa);
|
int value = AbilityUtils.calculateAmount(card, sa.getParam("Amount"), sa);
|
||||||
@@ -65,7 +65,7 @@ public class ReplaceCounterEffect extends SpellAbilityEffect {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Map.Entry<Optional<Player>, Map<CounterType, Integer>> e : counterTable.entrySet()) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package forge.game.card;
|
package forge.game.card;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import com.google.common.collect.ForwardingTable;
|
import com.google.common.collect.ForwardingTable;
|
||||||
import com.google.common.collect.HashBasedTable;
|
import com.google.common.collect.HashBasedTable;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -40,7 +40,7 @@ public class ActivationTable extends ForwardingTable<SpellAbility, Optional<Stat
|
|||||||
SpellAbility original = getOriginal(sa);
|
SpellAbility original = getOriginal(sa);
|
||||||
|
|
||||||
if (original != null) {
|
if (original != null) {
|
||||||
Optional<StaticAbility> st = Optional.fromNullable(root.getGrantorStatic());
|
Optional<StaticAbility> st = Optional.ofNullable(root.getGrantorStatic());
|
||||||
|
|
||||||
List<Player> activators = get(original, st);
|
List<Player> activators = get(original, st);
|
||||||
if (activators == null) {
|
if (activators == null) {
|
||||||
@@ -58,7 +58,7 @@ public class ActivationTable extends ForwardingTable<SpellAbility, Optional<Stat
|
|||||||
public List<Player> getActivators(SpellAbility sa) {
|
public List<Player> getActivators(SpellAbility sa) {
|
||||||
SpellAbility root = sa.getRootAbility();
|
SpellAbility root = sa.getRootAbility();
|
||||||
SpellAbility original = getOriginal(sa);
|
SpellAbility original = getOriginal(sa);
|
||||||
Optional<StaticAbility> st = Optional.fromNullable(root.getGrantorStatic());
|
Optional<StaticAbility> st = Optional.ofNullable(root.getGrantorStatic());
|
||||||
|
|
||||||
if (contains(original, st)) {
|
if (contains(original, st)) {
|
||||||
return get(original, st);
|
return get(original, st);
|
||||||
|
|||||||
@@ -18,7 +18,6 @@
|
|||||||
package forge.game.card;
|
package forge.game.card;
|
||||||
|
|
||||||
import com.esotericsoftware.minlog.Log;
|
import com.esotericsoftware.minlog.Log;
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import com.google.common.collect.*;
|
import com.google.common.collect.*;
|
||||||
import forge.GameCommand;
|
import forge.GameCommand;
|
||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ package forge.game.cost;
|
|||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Optional;
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import forge.game.GameEntity;
|
import forge.game.GameEntity;
|
||||||
import forge.game.ability.AbilityUtils;
|
import forge.game.ability.AbilityUtils;
|
||||||
@@ -119,7 +118,7 @@ public class CostRemoveAnyCounter extends CostPart {
|
|||||||
@Override
|
@Override
|
||||||
public boolean payAsDecided(Player ai, PaymentDecision decision, SpellAbility ability, final boolean effect) {
|
public boolean payAsDecided(Player ai, PaymentDecision decision, SpellAbility ability, final boolean effect) {
|
||||||
int removed = 0;
|
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()) {
|
for (Entry<CounterType, Integer> v : e.getValue().entrySet()) {
|
||||||
removed += v.getValue();
|
removed += v.getValue();
|
||||||
e.getKey().subtractCounter(v.getKey(), v.getValue(), ai);
|
e.getKey().subtractCounter(v.getKey(), v.getValue(), ai);
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
package forge.game.replacement;
|
package forge.game.replacement;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
|
|
||||||
import forge.game.ability.AbilityKey;
|
import forge.game.ability.AbilityKey;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.card.CounterType;
|
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);
|
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()) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
if (hasParam("ValidCounterType")) {
|
if (hasParam("ValidCounterType")) {
|
||||||
|
|||||||
@@ -17,19 +17,12 @@
|
|||||||
*/
|
*/
|
||||||
package forge.game.replacement;
|
package forge.game.replacement;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
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 forge.game.card.*;
|
import forge.game.card.*;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import com.google.common.base.Optional;
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user