more refactoring

This commit is contained in:
theelk801 2024-09-28 15:20:07 -04:00
parent 3307eb31a5
commit d69bc200d4
26 changed files with 335 additions and 506 deletions

View file

@ -37,7 +37,7 @@ import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.StaticFilters;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.filter.predicate.mageobject.SharesNamePredicate;
import mage.filter.predicate.permanent.ControllerIdPredicate;
import mage.filter.predicate.permanent.LegendRuleAppliesPredicate;
import mage.game.combat.Combat;
@ -2869,7 +2869,7 @@ public abstract class GameImpl implements Game {
for (Permanent legend : legendary) {
FilterPermanent filterLegendName = new FilterPermanent();
filterLegendName.add(SuperType.LEGENDARY.getPredicate());
filterLegendName.add(new NamePredicate(legend.getName()));
filterLegendName.add(new SharesNamePredicate(legend));
filterLegendName.add(new ControllerIdPredicate(legend.getControllerId()));
filterLegendName.add(LegendRuleAppliesPredicate.instance);
if (!getBattlefield().contains(filterLegendName, legend.getControllerId(), null, this, 2)) {

View file

@ -58,6 +58,7 @@ import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.ToIntFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -2169,6 +2170,19 @@ public final class CardUtil {
return stream.filter(clazz::isInstance).map(clazz::cast).filter(Objects::nonNull);
}
public static <T> boolean checkAnyPairs(Collection<T> collection, BiPredicate<T, T> predicate) {
return streamPairsWithMap(collection, (t1, t2) -> predicate.test(t1, t2)).anyMatch(x -> x);
}
public static <T> Stream<T> streamAllPairwiseMatches(Collection<T> collection, BiPredicate<T, T> predicate) {
return streamPairsWithMap(
collection,
(t1, t2) -> predicate.test(t1, t2)
? Stream.of(t1, t2)
: Stream.<T>empty()
).flatMap(Function.identity()).distinct();
}
private static class IntPairIterator implements Iterator<AbstractMap.SimpleImmutableEntry<Integer, Integer>> {
private final int amount;
private int firstCounter = 0;
@ -2201,13 +2215,7 @@ public final class CardUtil {
}
}
public static <T> boolean checkAnyPairs(Collection<T> collection, BiPredicate<T, T> predicate) {
return streamPairsWithMap(collection, (t1, t2) -> predicate.test(t1, t2)).anyMatch(x -> x);
}
public static <T, U> Stream<U> streamPairsWithMap(
Collection<T> collection,
BiFunction<T, T, U> function) {
public static <T, U> Stream<U> streamPairsWithMap(Collection<T> collection, BiFunction<T, T, U> function) {
if (collection.size() < 2) {
return Stream.empty();
}