mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
Guava migration - Inline Predicates.compose
This commit is contained in:
@@ -61,6 +61,7 @@ import io.sentry.Breadcrumb;
|
|||||||
import io.sentry.Sentry;
|
import io.sentry.Sentry;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2284,7 +2285,7 @@ public class AiController {
|
|||||||
List<ReplacementEffect> shield = filterList(list, CardTraitPredicates.hasParam("ShieldCounter"));
|
List<ReplacementEffect> shield = filterList(list, CardTraitPredicates.hasParam("ShieldCounter"));
|
||||||
List<ReplacementEffect> regeneration = filterList(list, CardTraitPredicates.hasParam("Regeneration"));
|
List<ReplacementEffect> regeneration = filterList(list, CardTraitPredicates.hasParam("Regeneration"));
|
||||||
List<ReplacementEffect> umbraArmor = filterList(list, CardTraitPredicates.isKeyword(Keyword.UMBRA_ARMOR));
|
List<ReplacementEffect> umbraArmor = filterList(list, CardTraitPredicates.isKeyword(Keyword.UMBRA_ARMOR));
|
||||||
List<ReplacementEffect> umbraArmorIndestructible = filterList(umbraArmor, Predicates.compose(CardPredicates.hasKeyword(Keyword.INDESTRUCTIBLE), CardTraitBase::getHostCard));
|
List<ReplacementEffect> umbraArmorIndestructible = filterList(umbraArmor, x -> x.getHostCard().hasKeyword(Keyword.INDESTRUCTIBLE));
|
||||||
|
|
||||||
// Indestructible umbra armor is the best
|
// Indestructible umbra armor is the best
|
||||||
if (!umbraArmorIndestructible.isEmpty()) {
|
if (!umbraArmorIndestructible.isEmpty()) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import java.util.function.Function;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import forge.util.Iterables;
|
import forge.util.Iterables;
|
||||||
import forge.util.Predicates;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import forge.StaticData;
|
import forge.StaticData;
|
||||||
@@ -206,7 +205,8 @@ public class DeckHints {
|
|||||||
private Iterable<PaperCard> getMatchingItems(Iterable<PaperCard> source, Predicate<CardRules> predicate, Function<PaperCard, CardRules> fn) {
|
private Iterable<PaperCard> getMatchingItems(Iterable<PaperCard> source, Predicate<CardRules> predicate, Function<PaperCard, CardRules> fn) {
|
||||||
// TODO should token generators be counted differently for their potential?
|
// 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?
|
// 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) {
|
public static Predicate<CardRules> rulesWithTokens(final Predicate<CardRules> predicate) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package forge.util;
|
package forge.util;
|
||||||
|
|
||||||
import java.util.function.Function;
|
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class Predicates {
|
public class Predicates {
|
||||||
@@ -15,9 +14,4 @@ public class Predicates {
|
|||||||
//TODO: Should be able to clean up the casting here.
|
//TODO: Should be able to clean up the casting here.
|
||||||
return x -> Iterables.any(components, (Predicate<Predicate<? super T>>) i -> i.test(x));
|
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public class ChangeZoneEffect extends SpellAbilityEffect {
|
public class ChangeZoneEffect extends SpellAbilityEffect {
|
||||||
@@ -1151,7 +1152,8 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
|
|||||||
}
|
}
|
||||||
if (sa.hasParam("DifferentPower")) {
|
if (sa.hasParam("DifferentPower")) {
|
||||||
for (Card c : chosenCards) {
|
for (Card c : chosenCards) {
|
||||||
fetchList = CardLists.filter(fetchList, Predicates.compose(Predicate.isEqual(c.getNetPower()), Card::getNetPower).negate());
|
int chosenPower = c.getNetPower();
|
||||||
|
fetchList = CardLists.filter(fetchList, x -> x.getNetPower() != chosenPower);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sa.hasParam("ShareLandType")) {
|
if (sa.hasParam("ShareLandType")) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package forge.game.ability.effects;
|
package forge.game.ability.effects;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@@ -19,7 +20,6 @@ import forge.item.PaperCard;
|
|||||||
import forge.item.PaperCardPredicates;
|
import forge.item.PaperCardPredicates;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
import forge.util.Iterables;
|
import forge.util.Iterables;
|
||||||
import forge.util.Predicates;
|
|
||||||
|
|
||||||
public class PlayLandVariantEffect extends SpellAbilityEffect {
|
public class PlayLandVariantEffect extends SpellAbilityEffect {
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ public class PlayLandVariantEffect extends SpellAbilityEffect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Predicate<PaperCard> cp = Predicates.compose(landNames::contains, PaperCard::getName);
|
final Predicate<PaperCard> cp = x -> landNames.contains(x.getName());
|
||||||
cards = Lists.newArrayList(Iterables.filter(cards, cp));
|
cards = Lists.newArrayList(Iterables.filter(cards, cp));
|
||||||
// get a random basic land
|
// get a random basic land
|
||||||
Card random;
|
Card random;
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import java.awt.event.MouseEvent;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1002,12 +1003,12 @@ public abstract class ItemManager<T extends InventoryItem> extends JPanel implem
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (useFilter && this.wantUnique) {
|
if (useFilter && this.wantUnique) {
|
||||||
final Predicate<Entry<T, Integer>> filterForPool = Predicates.compose(this.filterPredicate, Entry::getKey);
|
final Predicate<Entry<T, Integer>> filterForPool = x -> this.filterPredicate.test(x.getKey());
|
||||||
final Iterable<Entry<T, Integer>> items = getUnique(Iterables.filter(this.pool, filterForPool));
|
final Iterable<Entry<T, Integer>> items = getUnique(Iterables.filter(this.pool, filterForPool));
|
||||||
this.model.addItems(items);
|
this.model.addItems(items);
|
||||||
}
|
}
|
||||||
else if (useFilter) {
|
else if (useFilter) {
|
||||||
final Predicate<Entry<T, Integer>> pred = Predicates.compose(this.filterPredicate, Entry::getKey);
|
final Predicate<Entry<T, Integer>> pred = x -> this.filterPredicate.test(x.getKey());;
|
||||||
this.model.addItems(Iterables.filter(this.pool, pred));
|
this.model.addItems(Iterables.filter(this.pool, pred));
|
||||||
}
|
}
|
||||||
else if (this.wantUnique) {
|
else if (this.wantUnique) {
|
||||||
|
|||||||
@@ -782,7 +782,7 @@ public abstract class ItemManager<T extends InventoryItem> extends FContainer im
|
|||||||
|
|
||||||
Iterable<Entry<T, Integer>> items = pool;
|
Iterable<Entry<T, Integer>> items = pool;
|
||||||
if (useFilter) {
|
if (useFilter) {
|
||||||
Predicate<Entry<T, Integer>> pred = Predicates.compose(filterPredicate, (Function<Entry<T, Integer>, T>) Entry::getKey);
|
Predicate<Entry<T, Integer>> pred = x -> filterPredicate.test(x.getKey());
|
||||||
items = Iterables.filter(pool, pred);
|
items = Iterables.filter(pool, pred);
|
||||||
}
|
}
|
||||||
model.addItems(items);
|
model.addItems(items);
|
||||||
|
|||||||
Reference in New Issue
Block a user