Guava migration - Inline Predicates.in

This commit is contained in:
Jetz
2024-09-02 20:06:49 -04:00
parent ef011d3f51
commit 4eb8fddfef
4 changed files with 3 additions and 7 deletions

View File

@@ -2450,7 +2450,7 @@ public class ComputerUtil {
// not enough good choices, need to fill the rest // not enough good choices, need to fill the rest
int minDiff = min - goodChoices.size(); int minDiff = min - goodChoices.size();
if (minDiff > 0) { if (minDiff > 0) {
goodChoices.addAll(Aggregates.random(CardLists.filter(validCards, Predicates.not(Predicates.in(goodChoices))), minDiff)); goodChoices.addAll(Aggregates.random(CardLists.filter(validCards, Predicates.not(goodChoices::contains)), minDiff));
return goodChoices; return goodChoices;
} }

View File

@@ -924,7 +924,7 @@ public class ComputerUtilCost {
public static CardCollection paymentChoicesWithoutTargets(Iterable<Card> choices, SpellAbility source, Player ai) { public static CardCollection paymentChoicesWithoutTargets(Iterable<Card> choices, SpellAbility source, Player ai) {
if (source.usesTargeting()) { if (source.usesTargeting()) {
final CardCollection targets = new CardCollection(source.getTargets().getTargetCards()); final CardCollection targets = new CardCollection(source.getTargets().getTargetCards());
choices = Iterables.filter(choices, Predicates.not(Predicates.and(CardPredicates.isController(ai), Predicates.in(targets)))); choices = Iterables.filter(choices, Predicates.not(Predicates.and(CardPredicates.isController(ai), targets::contains)));
} }
return new CardCollection(choices); return new CardCollection(choices);
} }

View File

@@ -1,6 +1,5 @@
package forge.util; package forge.util;
import java.util.Collection;
import java.util.Objects; import java.util.Objects;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
@@ -44,7 +43,4 @@ public class Predicates {
return x -> Objects.equals(target, x); return x -> Objects.equals(target, x);
} }
public static <T> Predicate<T> in(Collection<? extends T> target) {
return target::contains;
}
} }

View File

@@ -147,7 +147,7 @@ public final class FServerManager {
broadcastExcept(event, Collections.singleton(notTo)); broadcastExcept(event, Collections.singleton(notTo));
} }
public void broadcastExcept(final NetEvent event, final Collection<RemoteClient> notTo) { public void broadcastExcept(final NetEvent event, final Collection<RemoteClient> notTo) {
broadcastTo(event, Iterables.filter(clients.values(), Predicates.not(Predicates.in(notTo)))); broadcastTo(event, Iterables.filter(clients.values(), Predicates.not(notTo::contains)));
} }
private void broadcastTo(final NetEvent event, final Iterable<RemoteClient> to) { private void broadcastTo(final NetEvent event, final Iterable<RemoteClient> to) {
for (final RemoteClient client : to) { for (final RemoteClient client : to) {