X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Futil%2Fmatcher%2FCondition.java;h=f47b3676d7de3d88ea5654f1a1ec51f662a0c37c;hb=caa5930cf71ef14a4af891f2c17aa4a6e0f72bcf;hp=3401ae84e22986a2e4e483b3fff9430f4d72f367;hpb=ef14d83cfe8ca0bb2271d50d638516cdc90c2b8b;p=jalview.git diff --git a/src/jalview/util/matcher/Condition.java b/src/jalview/util/matcher/Condition.java index 3401ae8..f47b367 100644 --- a/src/jalview/util/matcher/Condition.java +++ b/src/jalview/util/matcher/Condition.java @@ -1,31 +1,82 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ 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, true), NotContains(false, true), Matches(false, true), - NotMatches(false, true), Present(false, false), NotPresent(false, false), - EQ(true, true), NE(true, true), LT(true, true), LE(true, true), - GT(true, true), GE(true, 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; private boolean needsAPattern; - Condition(boolean isNumeric, boolean needsPattern) + /* + * 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; } /** @@ -50,6 +101,11 @@ public enum Condition 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 @@ -60,14 +116,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()); } }