mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Guava migration - Remove Functions dependency
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
package forge.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
@@ -29,6 +25,16 @@ public class Aggregates {
|
||||
return max;
|
||||
}
|
||||
|
||||
public static Integer max(final Iterable<Integer> source) {
|
||||
if (source == null) return null;
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (int value : source) {
|
||||
if (value > max)
|
||||
max = value;
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
public static final <T> Integer min(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
|
||||
if (source == null) { return null; }
|
||||
int max = Integer.MAX_VALUE;
|
||||
@@ -41,6 +47,16 @@ public class Aggregates {
|
||||
return max;
|
||||
}
|
||||
|
||||
public static Integer min(final Iterable<Integer> source) {
|
||||
if (source == null) return null;
|
||||
int min = Integer.MAX_VALUE;
|
||||
for (int value : source) {
|
||||
if (value < min)
|
||||
min = value;
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
public static final <T> T itemWithMax(final Iterable<T> source, final Function<T, Integer> valueAccessor) {
|
||||
if (source == null) { return null; }
|
||||
int max = Integer.MIN_VALUE;
|
||||
@@ -83,6 +99,16 @@ public class Aggregates {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int sum(final Iterable<Integer> source) {
|
||||
int result = 0;
|
||||
if(source != null) {
|
||||
for(final Integer value : source) {
|
||||
result += value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static final <T> T random(final T[] source) {
|
||||
if (source == null) { return null; }
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package forge.game.ability;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.*;
|
||||
import forge.card.CardStateName;
|
||||
import forge.card.CardType;
|
||||
@@ -674,9 +673,9 @@ public class AbilityUtils {
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterable<Integer> numbers = (Iterable<Integer>) to;
|
||||
if (calcX[0].endsWith("Max")) {
|
||||
count = Aggregates.max(numbers, Functions.identity());
|
||||
count = Aggregates.max(numbers);
|
||||
} else {
|
||||
count = Aggregates.sum(numbers, Functions.identity());
|
||||
count = Aggregates.sum(numbers);
|
||||
}
|
||||
} else {
|
||||
count = (Integer) to;
|
||||
@@ -2390,7 +2389,7 @@ public class AbilityUtils {
|
||||
} else if (sq[0].startsWith("Num")) {
|
||||
num = dmgInstances.size();
|
||||
} else {
|
||||
num = Aggregates.sum(dmgInstances, Functions.identity());
|
||||
num = Aggregates.sum(dmgInstances);
|
||||
}
|
||||
return doXMath(num, expr, c, ctb);
|
||||
}
|
||||
@@ -3528,7 +3527,7 @@ public class AbilityUtils {
|
||||
if (value.contains("Counters")) {
|
||||
int count = 0;
|
||||
if (sq[1].equals("ALL")) {
|
||||
count = Aggregates.sum(player.getCounters().values(), Functions.identity());
|
||||
count = Aggregates.sum(player.getCounters().values());
|
||||
} else {
|
||||
count = player.getCounters(CounterType.getType(sq[1]));
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.Map;
|
||||
import forge.game.card.*;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
@@ -233,7 +232,7 @@ public class CountersRemoveEffect extends SpellAbilityEffect {
|
||||
int max = Math.min(cntToRemove, tgtCounters.get(chosenType));
|
||||
// remove selection so player can't cheat additional trigger by choosing the same type multiple times
|
||||
tgtCounters.remove(chosenType);
|
||||
int remaining = Aggregates.sum(tgtCounters.values(), Functions.identity());
|
||||
int remaining = Aggregates.sum(tgtCounters.values());
|
||||
// player must choose enough so he can still reach the amount with other types
|
||||
int min = sa.hasParam("UpTo") ? 0 : Math.max(1, max - remaining);
|
||||
prompt = Localizer.getInstance().getMessage("lblSelectRemoveCountersNumberOfTarget", chosenType.getName());
|
||||
|
||||
@@ -2,8 +2,6 @@ package forge.game.trigger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
|
||||
import forge.game.ability.AbilityKey;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CounterType;
|
||||
@@ -38,7 +36,7 @@ public class TriggerCounterPlayerAddedAll extends Trigger {
|
||||
@Override
|
||||
public void setTriggeringObjects(SpellAbility sa, Map<AbilityKey, Object> runParams) {
|
||||
sa.setTriggeringObjectsFrom(runParams, AbilityKey.Source, AbilityKey.Object, AbilityKey.CounterMap);
|
||||
sa.setTriggeringObject(AbilityKey.Amount, Aggregates.sum(((Map<CounterType, Integer>) runParams.get(AbilityKey.CounterMap)).values(), Functions.identity()));
|
||||
sa.setTriggeringObject(AbilityKey.Amount, Aggregates.sum(((Map<CounterType, Integer>) runParams.get(AbilityKey.CounterMap)).values()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user