X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Futil%2Fmatcher%2FCondition.java;h=8816a7f2bda0669f58032fd408606fb7c1b1f210;hb=1f3cf1db69c97ace5c0606e2ee0ccbf569970761;hp=455f80511c7c9291a328e131d881aa8e2a677f7e;hpb=baa077bd19420018433d78927aad3ad139e47351;p=jalview.git diff --git a/src/jalview/util/matcher/Condition.java b/src/jalview/util/matcher/Condition.java index 455f805..8816a7f 100644 --- a/src/jalview/util/matcher/Condition.java +++ b/src/jalview/util/matcher/Condition.java @@ -2,25 +2,61 @@ package jalview.util.matcher; import jalview.util.MessageManager; -import java.util.HashMap; -import java.util.Map; - /** * An enumeration for binary conditions that a user might choose from when * setting filter or match conditions for values */ public enum Condition { - Contains(false), NotContains(false), Matches(false), NotMatches(false), - EQ(true), NE(true), LT(true), LE(true), GT(true), GE(true); + Contains(false, true, "Contains"), + NotContains(false, true, "NotContains"), Matches(false, true, "Matches"), + NotMatches(false, true, "NotMatches"), Present(false, false, "Present"), + NotPresent(false, false, "NotPresent"), EQ(true, true, "EQ"), + NE(true, true, "NE"), LT(true, true, "LT"), LE(true, true, "LE"), + GT(true, true, "GT"), GE(true, true, "GE"); - private static Map displayNames = new HashMap<>(); - private boolean numeric; - Condition(boolean isNumeric) + private boolean needsAPattern; + + /* + * value used to save a Condition to the + * Jalview project file or restore it from project; + * it should not be changed even if enum names change in future + */ + private String stableName; + + /** + * Answers the enum value whose 'stable name' matches the argument (not case + * sensitive), or null if no match + * + * @param stableName + * @return + */ + public static Condition fromString(String stableName) + { + for (Condition c : values()) + { + if (c.stableName.equalsIgnoreCase(stableName)) + { + return c; + } + } + return null; + } + + /** + * Constructor + * + * @param isNumeric + * @param needsPattern + * @param stablename + */ + Condition(boolean isNumeric, boolean needsPattern, String stablename) { numeric = isNumeric; + needsAPattern = needsPattern; + stableName = stablename; } /** @@ -35,6 +71,22 @@ public enum Condition } /** + * Answers true if the condition requires a pattern to compare against, else + * false + * + * @return + */ + public boolean needsAPattern() + { + return needsAPattern; + } + + public String getStableName() + { + return stableName; + } + + /** * Answers a display name for the match condition, suitable for showing in * drop-down menus. The value may be internationalized using the resource key * "label.matchCondition_" with the enum name appended. @@ -44,14 +96,7 @@ public enum Condition @Override public String toString() { - String name = displayNames.get(this); - if (name != null) - { - return name; - } - name = MessageManager - .getStringOrReturn("label.matchCondition_", name()); - displayNames.put(this, name); - return name; + return MessageManager.getStringOrReturn("label.matchCondition_", + name()); } }