From 3b8298e7c25cc46d25a20f6f09dd4e14a9a1f77b Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Mon, 6 Jan 2020 14:59:10 -0500 Subject: [PATCH] moved SubTypePredicate into SubType --- .../src/main/java/mage/constants/SubType.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Mage/src/main/java/mage/constants/SubType.java b/Mage/src/main/java/mage/constants/SubType.java index 4f157b95620..4c495ad93bb 100644 --- a/Mage/src/main/java/mage/constants/SubType.java +++ b/Mage/src/main/java/mage/constants/SubType.java @@ -1,5 +1,8 @@ package mage.constants; +import mage.MageObject; +import mage.filter.predicate.Predicate; +import mage.game.Game; import mage.util.SubTypeList; import java.util.Arrays; @@ -439,7 +442,30 @@ public enum SubType { YANLING("Yanling", SubTypeSet.PlaneswalkerType), YODA("Yoda", SubTypeSet.PlaneswalkerType, true); // Star Wars + public static class SubTypePredicate implements Predicate { + + private final SubType subtype; + + private SubTypePredicate(SubType subtype) { + this.subtype = subtype; + } + + + @Override + public boolean apply(MageObject input, Game game) { + return input.hasSubtype(subtype, game); + } + + @Override + public String toString() { + return "Subtype(" + subtype + ')'; + } + } + private final SubTypeSet subTypeSet; + private final String description; + private final boolean customSet; + private final SubTypePredicate predicate; SubType(String description, SubTypeSet subTypeSet) { this(description, subTypeSet, false); @@ -449,21 +475,22 @@ public enum SubType { this.description = description; this.subTypeSet = subTypeSet; this.customSet = customSet; + this.predicate = new SubTypePredicate(this); } public String getDescription() { return description; } - private final String description; - - private final boolean customSet; - @Override public String toString() { return description; } + public SubTypePredicate getPredicate() { + return predicate; + } + public static SubType fromString(String value) { for (SubType st : SubType.values()) { if (st.toString().equals(value)) {