Guava migration - Inline Predicates.compose

This commit is contained in:
Jetz
2024-09-06 19:48:19 -04:00
parent 6e3726ee79
commit 4c8a94b18a
7 changed files with 13 additions and 15 deletions

View File

@@ -8,7 +8,6 @@ import java.util.function.Function;
import java.util.function.Predicate;
import forge.util.Iterables;
import forge.util.Predicates;
import org.apache.commons.lang3.tuple.Pair;
import forge.StaticData;
@@ -206,7 +205,8 @@ public class DeckHints {
private Iterable<PaperCard> getMatchingItems(Iterable<PaperCard> source, Predicate<CardRules> predicate, Function<PaperCard, CardRules> fn) {
// TODO should token generators be counted differently for their potential?
// And would there ever be a circumstance where `fn` should be anything but PaperCard::getRules?
return Iterables.filter(source, Predicates.compose(tokens ? rulesWithTokens(predicate) : predicate, fn));
Predicate<CardRules> predicate1 = tokens ? rulesWithTokens(predicate) : predicate;
return Iterables.filter(source, x -> predicate1.test(fn.apply(x)));
}
public static Predicate<CardRules> rulesWithTokens(final Predicate<CardRules> predicate) {

View File

@@ -1,6 +1,5 @@
package forge.util;
import java.util.function.Function;
import java.util.function.Predicate;
public class Predicates {
@@ -15,9 +14,4 @@ public class Predicates {
//TODO: Should be able to clean up the casting here.
return x -> Iterables.any(components, (Predicate<Predicate<? super T>>) i -> i.test(x));
}
//TODO: Most uses of this are with the function PaperCard::getRules. Maybe we should just have PaperCardPredicates?
public static <A, B> Predicate<A> compose(Predicate<B> predicate, Function<A, ? extends B> function) {
return x -> predicate.test(function.apply(x));
}
}