mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
minor optimizations to card filtering
This commit is contained in:
@@ -80,7 +80,7 @@ class FilterCheckBoxes {
|
||||
if (red.isSelected()) { colors.add(CardRules.Predicates.Presets.isRed); }
|
||||
if (green.isSelected()) { colors.add(CardRules.Predicates.Presets.isGreen); }
|
||||
if (colorless.isSelected()) { colors.add(CardRules.Predicates.Presets.isColorless); }
|
||||
Predicate<CardRules> filterByColor = colors.size() == 6 ? Predicate.getTrue(CardRules.class) : Predicate.or(colors);
|
||||
Predicate<CardRules> filterByColor = colors.size() == 6 ? CardRules.Predicates.Presets.constantTrue : Predicate.or(colors);
|
||||
|
||||
List<Predicate<CardRules>> types = new ArrayList<Predicate<CardRules>>();
|
||||
if (land.isSelected()) { types.add(CardRules.Predicates.Presets.isLand); }
|
||||
@@ -90,7 +90,7 @@ class FilterCheckBoxes {
|
||||
if (planeswalker.isSelected()) { types.add(CardRules.Predicates.Presets.isPlaneswalker); }
|
||||
if (artifact.isSelected()) { types.add(CardRules.Predicates.Presets.isArtifact); }
|
||||
if (enchantment.isSelected()) { types.add(CardRules.Predicates.Presets.isEnchantment); }
|
||||
Predicate<CardRules> filterByType = types.size() == 7 ? Predicate.getTrue(CardRules.class) : Predicate.or(types);
|
||||
Predicate<CardRules> filterByType = types.size() == 7 ? CardRules.Predicates.Presets.constantTrue : Predicate.or(types);
|
||||
|
||||
return Predicate.brigde(Predicate.and(filterByColor, filterByType), CardPrinted.fnGetRules);
|
||||
}
|
||||
|
||||
@@ -205,11 +205,10 @@ public abstract class Predicate<T> {
|
||||
}
|
||||
|
||||
// Static builder methods - they choose concrete implementation by themselves
|
||||
public static <U, T> Predicate<U> brigde(Predicate<T> predicate, Lambda1<T, U> fnBridge) {
|
||||
// TODO Auto-generated method stub
|
||||
public static <U, T> Predicate<U> brigde(final Predicate<T> predicate, final Lambda1<T, U> fnBridge) {
|
||||
return new Bridge<T, U>(predicate, fnBridge);
|
||||
}
|
||||
|
||||
|
||||
public static <T> Predicate<T> not(final Predicate<T> operand1) { return new Not<T>(operand1); }
|
||||
public static <T> Predicate<T> compose(final Predicate<T> operand1,
|
||||
final PredicatesOp operator, final Predicate<T> operand2)
|
||||
@@ -223,11 +222,13 @@ public abstract class Predicate<T> {
|
||||
return new NodeAnd<T>(operand1, operand2);
|
||||
}
|
||||
public static <T> Predicate<T> and(final Iterable<Predicate<T>> operand) { return new MultiNodeAnd<T>(operand); }
|
||||
public static <T, U> Predicate<T> and(final Predicate<T> operand1, final Predicate<U> operand2, Lambda1<U, T> bridge) { return new NodeAndBridged<T, U>(operand1, operand2, bridge); }
|
||||
|
||||
public static <T> Predicate<T> or(final Predicate<T> operand1, final Predicate<T> operand2) { return new NodeOr<T>(operand1, operand2); }
|
||||
public static <T, U> Predicate<T> and(final Predicate<T> operand1, final Predicate<U> operand2, final Lambda1<U, T> bridge)
|
||||
{ return new NodeAndBridged<T, U>(operand1, operand2, bridge); }
|
||||
public static <T> Predicate<T> or(final Predicate<T> operand1, final Predicate<T> operand2)
|
||||
{ return new NodeOr<T>(operand1, operand2); }
|
||||
public static <T> Predicate<T> or(final Iterable<Predicate<T>> operand) { return new MultiNodeOr<T>(operand); }
|
||||
public static <T, U> Predicate<T> or(final Predicate<T> operand1, final Predicate<U> operand2, Lambda1<U, T> bridge) { return new NodeOrBridged<T, U>(operand1, operand2, bridge); }
|
||||
public static <T, U> Predicate<T> or(final Predicate<T> operand1, final Predicate<U> operand2, final Lambda1<U, T> bridge)
|
||||
{ return new NodeOrBridged<T, U>(operand1, operand2, bridge); }
|
||||
|
||||
// Concrete implementations
|
||||
// unary operators
|
||||
@@ -241,6 +242,7 @@ public abstract class Predicate<T> {
|
||||
protected final Lambda1<T, U> fnBridge;
|
||||
public Bridge(final Predicate<T> operand, final Lambda1<T, U> fnTfromU) { filter = operand; fnBridge = fnTfromU; }
|
||||
@Override public boolean isTrue(final U card) { return filter.isTrue(fnBridge.apply(card)); }
|
||||
@Override public boolean is1() { return filter.is1(); }
|
||||
}
|
||||
// binary operators
|
||||
protected static class Node<T> extends Predicate<T> {
|
||||
|
||||
Reference in New Issue
Block a user