mirror of
https://github.com/magefree/mage.git
synced 2026-01-25 04:39:18 -08:00
more refactoring
This commit is contained in:
parent
3307eb31a5
commit
d69bc200d4
26 changed files with 335 additions and 506 deletions
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue