From 3d1f23e03b113ed662868c128c5c54da7752bdae Mon Sep 17 00:00:00 2001 From: North Date: Tue, 10 Jul 2012 21:49:19 +0300 Subject: [PATCH] Added base Predicates and MageObject Predicates. --- .../filter/predicate/IntComparePredicate.java | 77 ++++++ Mage/src/mage/filter/predicate/Predicate.java | 54 +++++ .../src/mage/filter/predicate/Predicates.java | 229 ++++++++++++++++++ .../mageobject/AbilityPredicate.java | 63 +++++ .../mageobject/CardTypePredicate.java | 56 +++++ .../predicate/mageobject/ColorPredicate.java | 56 +++++ .../mageobject/ColorlessPredicate.java | 49 ++++ .../ConvertedManaCostPredicate.java | 53 ++++ .../predicate/mageobject/NamePredicate.java | 55 +++++ .../predicate/mageobject/PowerPredicate.java | 53 ++++ .../mageobject/SubtypePredicate.java | 55 +++++ .../predicate/mageobject/Supertype.java | 55 +++++ .../mageobject/ToughnessPredicate.java | 53 ++++ 13 files changed, 908 insertions(+) create mode 100644 Mage/src/mage/filter/predicate/IntComparePredicate.java create mode 100644 Mage/src/mage/filter/predicate/Predicate.java create mode 100644 Mage/src/mage/filter/predicate/Predicates.java create mode 100644 Mage/src/mage/filter/predicate/mageobject/AbilityPredicate.java create mode 100644 Mage/src/mage/filter/predicate/mageobject/CardTypePredicate.java create mode 100644 Mage/src/mage/filter/predicate/mageobject/ColorPredicate.java create mode 100644 Mage/src/mage/filter/predicate/mageobject/ColorlessPredicate.java create mode 100644 Mage/src/mage/filter/predicate/mageobject/ConvertedManaCostPredicate.java create mode 100644 Mage/src/mage/filter/predicate/mageobject/NamePredicate.java create mode 100644 Mage/src/mage/filter/predicate/mageobject/PowerPredicate.java create mode 100644 Mage/src/mage/filter/predicate/mageobject/SubtypePredicate.java create mode 100644 Mage/src/mage/filter/predicate/mageobject/Supertype.java create mode 100644 Mage/src/mage/filter/predicate/mageobject/ToughnessPredicate.java diff --git a/Mage/src/mage/filter/predicate/IntComparePredicate.java b/Mage/src/mage/filter/predicate/IntComparePredicate.java new file mode 100644 index 00000000000..a40f138b90c --- /dev/null +++ b/Mage/src/mage/filter/predicate/IntComparePredicate.java @@ -0,0 +1,77 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate; + +import mage.MageObject; +import mage.filter.Filter; +import mage.game.Game; + +/** + * + * @author North + */ +public abstract class IntComparePredicate implements Predicate { + + protected final Filter.ComparisonType type; + protected final int value; + + public IntComparePredicate(Filter.ComparisonType type, int value) { + this.type = type; + this.value = value; + } + + protected abstract int getInputValue(T input); + + @Override + public final boolean apply(T input, Game game) { + int inputValue = input.getPower().getValue(); + switch (type) { + case Equal: + if (inputValue != value) { + return false; + } + break; + case GreaterThan: + if (inputValue <= value) { + return false; + } + break; + case LessThan: + if (inputValue >= value) { + return false; + } + break; + } + return true; + } + + @Override + public String toString() { + return type.toString() + value; + } +} diff --git a/Mage/src/mage/filter/predicate/Predicate.java b/Mage/src/mage/filter/predicate/Predicate.java new file mode 100644 index 00000000000..d5d577c6ea5 --- /dev/null +++ b/Mage/src/mage/filter/predicate/Predicate.java @@ -0,0 +1,54 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate; + +import java.io.Serializable; +import mage.game.Game; + +/** + * Determines a true or false value for a given input. + * + * @author North + */ +public interface Predicate extends Serializable { + /** + * Returns the result of applying this predicate to {@code input}. This method is generally + * expected, but not absolutely required, to have the following properties: + * + *
    + *
  • Its execution does not cause any observable side effects.
  • + *
  • The computation is consistent with equals; that is, {@link Objects#equal + * Objects.equal}{@code (a, b)} implies that {@code predicate.apply(a) == + * predicate.apply(b)}.
  • + *
+ * + * @throws NullPointerException if {@code input} is null and this predicate does not accept null + * arguments + */ + boolean apply(T input, Game game); +} diff --git a/Mage/src/mage/filter/predicate/Predicates.java b/Mage/src/mage/filter/predicate/Predicates.java new file mode 100644 index 00000000000..a8f0b0427ec --- /dev/null +++ b/Mage/src/mage/filter/predicate/Predicates.java @@ -0,0 +1,229 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import mage.game.Game; + +/** + * Static utility methods pertaining to {@code Predicate} instances. + * + *

All methods returns serializable predicates as long as they're given serializable parameters.

+ * + * @author North + */ +public final class Predicates { + + private Predicates() { + } + + /** + * Returns a predicate that evaluates to {@code true} if the given predicate evaluates to {@code false}. + */ + public static Predicate not(Predicate predicate) { + return new NotPredicate(predicate); + } + + /** + * Returns a predicate that evaluates to {@code true} if each of its components evaluates to {@code true}. The + * components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is + * found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this + * predicate. If {@code components} is empty, the returned predicate will always evaluate to {@code true}. + */ + public static Predicate and(Iterable> components) { + return new AndPredicate(defensiveCopy(components)); + } + + /** + * Returns a predicate that evaluates to {@code true} if each of its components evaluates to {@code true}. The + * components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is + * found. It defensively copies the array passed in, so future changes to it won't alter the behavior of this + * predicate. If {@code components} is empty, the returned predicate will always evaluate to {@code true}. + */ + public static Predicate and(Predicate... components) { + return new AndPredicate(defensiveCopy(components)); + } + + /** + * Returns a predicate that evaluates to {@code true} if both of its components evaluate to {@code true}. The + * components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is + * found. + */ + public static Predicate and(Predicate first, Predicate second) { + return new AndPredicate(Predicates.asList(checkNotNull(first), checkNotNull(second))); + } + + /** + * Returns a predicate that evaluates to {@code true} if any one of its components evaluates to {@code true}. The + * components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found. + * It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. + * If {@code components} is empty, the returned predicate will always evaluate to {@code true}. + */ + public static Predicate or(Iterable> components) { + return new OrPredicate(defensiveCopy(components)); + } + + /** + * Returns a predicate that evaluates to {@code true} if any one of its components evaluates to {@code true}. The + * components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found. + * It defensively copies the array passed in, so future changes to it won't alter the behavior of this predicate. If + * {@code components} is empty, the returned predicate will always evaluate to {@code true}. + */ + public static Predicate or(Predicate... components) { + return new OrPredicate(defensiveCopy(components)); + } + + /** + * Returns a predicate that evaluates to {@code true} if either of its components evaluates to {@code true}. The + * components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found. + */ + public static Predicate or(Predicate first, Predicate second) { + return new OrPredicate(Predicates.asList(first, second)); + } + + /** + * @see Predicates#not(Predicate) + */ + private static class NotPredicate implements Predicate { + + final Predicate predicate; + + NotPredicate(Predicate predicate) { + this.predicate = checkNotNull(predicate); + } + + @Override + public boolean apply(T t, Game game) { + return !predicate.apply(t, game); + } + + @Override + public String toString() { + return "Not(" + predicate.toString() + ")"; + } + private static final long serialVersionUID = 0; + } + + /** + * @see Predicates#and(Iterable) + */ + private static class AndPredicate implements Predicate { + + private final List> components; + + private AndPredicate(List> components) { + this.components = components; + } + + @Override + public boolean apply(T t, Game game) { + for (int i = 0; i < components.size(); i++) { + if (!components.get(i).apply(t, game)) { + return false; + } + } + return true; + } + + @Override + public String toString() { + return "And(" + commaJoin(components) + ")"; + } + private static final long serialVersionUID = 0; + } + + /** + * @see Predicates#or(Iterable) + */ + private static class OrPredicate implements Predicate { + + private final List> components; + + private OrPredicate(List> components) { + this.components = components; + } + + @Override + public boolean apply(T t, Game game) { + for (int i = 0; i < components.size(); i++) { + if (components.get(i).apply(t, game)) { + return true; + } + } + return false; + } + + @Override + public String toString() { + return "Or(" + commaJoin(components) + ")"; + } + private static final long serialVersionUID = 0; + } + + @SuppressWarnings("unchecked") + private static List> asList(Predicate first, Predicate second) { + return Arrays.>asList(first, second); + } + + private static List defensiveCopy(T... array) { + return defensiveCopy(Arrays.asList(array)); + } + + static List defensiveCopy(Iterable iterable) { + ArrayList list = new ArrayList(); + for (T element : iterable) { + list.add(checkNotNull(element)); + } + return list; + } + + /** + * Ensures that an object reference passed as a parameter to the calling method is not null. + * + * @param reference an object reference + * @return the non-null reference that was validated + * @throws NullPointerException if {@code reference} is null + */ + private static T checkNotNull(T reference) { + if (reference == null) { + throw new NullPointerException(); + } + return reference; + } + + private static String commaJoin(List components) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < components.size(); i++) { + sb.append(components.get(i).toString()); + } + sb.deleteCharAt(sb.length() - 1); + return sb.toString(); + } +} diff --git a/Mage/src/mage/filter/predicate/mageobject/AbilityPredicate.java b/Mage/src/mage/filter/predicate/mageobject/AbilityPredicate.java new file mode 100644 index 00000000000..312fae73141 --- /dev/null +++ b/Mage/src/mage/filter/predicate/mageobject/AbilityPredicate.java @@ -0,0 +1,63 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.mageobject; + +import mage.MageObject; +import mage.abilities.Abilities; +import mage.abilities.Ability; +import mage.filter.predicate.Predicate; +import mage.game.Game; + +/** + * + * @author North + */ +public class AbilityPredicate implements Predicate { + + private final Class abilityClass; + + public AbilityPredicate(Class abilityClass) { + this.abilityClass = abilityClass; + } + + @Override + public boolean apply(T input, Game game) { + Abilities abilities = input.getAbilities(); + for (int i = 0; i < abilities.size(); i++) { + if (abilityClass.equals(abilities.get(i).getClass())) { + return true; + } + } + return false; + } + + @Override + public String toString() { + return "Ability(" + abilityClass.toString() + ')'; + } +} diff --git a/Mage/src/mage/filter/predicate/mageobject/CardTypePredicate.java b/Mage/src/mage/filter/predicate/mageobject/CardTypePredicate.java new file mode 100644 index 00000000000..f3f2ee9ac8a --- /dev/null +++ b/Mage/src/mage/filter/predicate/mageobject/CardTypePredicate.java @@ -0,0 +1,56 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.mageobject; + +import mage.Constants.CardType; +import mage.MageObject; +import mage.filter.predicate.Predicate; +import mage.game.Game; + +/** + * + * @author North + */ +public class CardTypePredicate implements Predicate { + + private final CardType cardType; + + public CardTypePredicate(CardType cardType) { + this.cardType = cardType; + } + + @Override + public boolean apply(T input, Game game) { + return input.getCardType().contains(cardType); + } + + @Override + public String toString() { + return "CardType(" + cardType.toString() + ')'; + } +} diff --git a/Mage/src/mage/filter/predicate/mageobject/ColorPredicate.java b/Mage/src/mage/filter/predicate/mageobject/ColorPredicate.java new file mode 100644 index 00000000000..f78c5826a2c --- /dev/null +++ b/Mage/src/mage/filter/predicate/mageobject/ColorPredicate.java @@ -0,0 +1,56 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.mageobject; + +import mage.MageObject; +import mage.ObjectColor; +import mage.filter.predicate.Predicate; +import mage.game.Game; + +/** + * + * @author North + */ +public class ColorPredicate implements Predicate { + + private final ObjectColor color; + + public ColorPredicate(ObjectColor color) { + this.color = color; + } + + @Override + public boolean apply(T input, Game game) { + return input.getColor().contains(color); + } + + @Override + public String toString() { + return "Color(" + color.toString() + ')'; + } +} diff --git a/Mage/src/mage/filter/predicate/mageobject/ColorlessPredicate.java b/Mage/src/mage/filter/predicate/mageobject/ColorlessPredicate.java new file mode 100644 index 00000000000..9d779a48956 --- /dev/null +++ b/Mage/src/mage/filter/predicate/mageobject/ColorlessPredicate.java @@ -0,0 +1,49 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.mageobject; + +import mage.MageObject; +import mage.filter.predicate.Predicate; +import mage.game.Game; + +/** + * + * @author North + */ +public class ColorlessPredicate implements Predicate { + + @Override + public boolean apply(T input, Game game) { + return input.getColor().isColorless(); + } + + @Override + public String toString() { + return "Colorless"; + } +} diff --git a/Mage/src/mage/filter/predicate/mageobject/ConvertedManaCostPredicate.java b/Mage/src/mage/filter/predicate/mageobject/ConvertedManaCostPredicate.java new file mode 100644 index 00000000000..bb2b22fabf6 --- /dev/null +++ b/Mage/src/mage/filter/predicate/mageobject/ConvertedManaCostPredicate.java @@ -0,0 +1,53 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.mageobject; + +import mage.MageObject; +import mage.filter.Filter; +import mage.filter.predicate.IntComparePredicate; + +/** + * + * @author North + */ +public class ConvertedManaCostPredicate extends IntComparePredicate { + + public ConvertedManaCostPredicate(Filter.ComparisonType type, int value) { + super(type, value); + } + + @Override + protected int getInputValue(T input) { + return input.getManaCost().convertedManaCost(); + } + + @Override + public String toString() { + return "ConvertedManaCost" + super.toString(); + } +} diff --git a/Mage/src/mage/filter/predicate/mageobject/NamePredicate.java b/Mage/src/mage/filter/predicate/mageobject/NamePredicate.java new file mode 100644 index 00000000000..c0bead3cf0d --- /dev/null +++ b/Mage/src/mage/filter/predicate/mageobject/NamePredicate.java @@ -0,0 +1,55 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.mageobject; + +import mage.MageObject; +import mage.filter.predicate.Predicate; +import mage.game.Game; + +/** + * + * @author North + */ +public class NamePredicate implements Predicate { + + private final String name; + + public NamePredicate(String name) { + this.name = name; + } + + @Override + public boolean apply(T input, Game game) { + return name.equals(input.getName()); + } + + @Override + public String toString() { + return "Name(" + name + ')'; + } +} diff --git a/Mage/src/mage/filter/predicate/mageobject/PowerPredicate.java b/Mage/src/mage/filter/predicate/mageobject/PowerPredicate.java new file mode 100644 index 00000000000..218e29aa2b2 --- /dev/null +++ b/Mage/src/mage/filter/predicate/mageobject/PowerPredicate.java @@ -0,0 +1,53 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.mageobject; + +import mage.MageObject; +import mage.filter.Filter; +import mage.filter.predicate.IntComparePredicate; + +/** + * + * @author North + */ +public class PowerPredicate extends IntComparePredicate { + + public PowerPredicate(Filter.ComparisonType type, int value) { + super(type, value); + } + + @Override + protected int getInputValue(T input) { + return input.getPower().getValue(); + } + + @Override + public String toString() { + return "Power" + super.toString(); + } +} diff --git a/Mage/src/mage/filter/predicate/mageobject/SubtypePredicate.java b/Mage/src/mage/filter/predicate/mageobject/SubtypePredicate.java new file mode 100644 index 00000000000..d19169f2ce3 --- /dev/null +++ b/Mage/src/mage/filter/predicate/mageobject/SubtypePredicate.java @@ -0,0 +1,55 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.mageobject; + +import mage.MageObject; +import mage.filter.predicate.Predicate; +import mage.game.Game; + +/** + * + * @author North + */ +public class SubtypePredicate implements Predicate { + + private final String subtype; + + public SubtypePredicate(String subtype) { + this.subtype = subtype; + } + + @Override + public boolean apply(T input, Game game) { + return input.getSubtype().contains(subtype); + } + + @Override + public String toString() { + return "Subtype(" + subtype + ')'; + } +} diff --git a/Mage/src/mage/filter/predicate/mageobject/Supertype.java b/Mage/src/mage/filter/predicate/mageobject/Supertype.java new file mode 100644 index 00000000000..233101ea096 --- /dev/null +++ b/Mage/src/mage/filter/predicate/mageobject/Supertype.java @@ -0,0 +1,55 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.mageobject; + +import mage.MageObject; +import mage.filter.predicate.Predicate; +import mage.game.Game; + +/** + * + * @author North + */ +public class Supertype implements Predicate { + + private final String supertype; + + public Supertype(String supertype) { + this.supertype = supertype; + } + + @Override + public boolean apply(T input, Game game) { + return input.getSupertype().contains(supertype); + } + + @Override + public String toString() { + return "Supertype(" + supertype + ')'; + } +} diff --git a/Mage/src/mage/filter/predicate/mageobject/ToughnessPredicate.java b/Mage/src/mage/filter/predicate/mageobject/ToughnessPredicate.java new file mode 100644 index 00000000000..e03231842fe --- /dev/null +++ b/Mage/src/mage/filter/predicate/mageobject/ToughnessPredicate.java @@ -0,0 +1,53 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.filter.predicate.mageobject; + +import mage.MageObject; +import mage.filter.Filter; +import mage.filter.predicate.IntComparePredicate; + +/** + * + * @author North + */ +public class ToughnessPredicate extends IntComparePredicate { + + public ToughnessPredicate(Filter.ComparisonType type, int value) { + super(type, value); + } + + @Override + protected int getInputValue(T input) { + return input.getToughness().getValue(); + } + + @Override + public String toString() { + return "Toughness" + super.toString(); + } +}