Merge branch 'documentation/JAL-3407_2.11.1_release' into releases/Release_2_11_1_Branch
[jalview.git] / src / jalview / util / matcher / Condition.java
1 package jalview.util.matcher;
2
3 import jalview.util.MessageManager;
4
5 /**
6  * An enumeration for binary conditions that a user might choose from when
7  * setting filter or match conditions for values
8  */
9 public enum Condition
10 {
11   Contains(false, true, "Contains"),
12   NotContains(false, true, "NotContains"), Matches(false, true, "Matches"),
13   NotMatches(false, true, "NotMatches"), Present(false, false, "Present"),
14   NotPresent(false, false, "NotPresent"), EQ(true, true, "EQ"),
15   NE(true, true, "NE"), LT(true, true, "LT"), LE(true, true, "LE"),
16   GT(true, true, "GT"), GE(true, true, "GE");
17
18   private boolean numeric;
19
20   private boolean needsAPattern;
21
22   /*
23    * value used to save a Condition to the 
24    * Jalview project file or restore it from project; 
25    * it should not be changed even if enum names change in future
26    */
27   private String stableName;
28
29   /**
30    * Answers the enum value whose 'stable name' matches the argument (not case
31    * sensitive), or null if no match
32    * 
33    * @param stableName
34    * @return
35    */
36   public static Condition fromString(String stableName)
37   {
38     for (Condition c : values())
39     {
40       if (c.stableName.equalsIgnoreCase(stableName))
41       {
42         return c;
43       }
44     }
45     return null;
46   }
47
48   /**
49    * Constructor
50    * 
51    * @param isNumeric
52    * @param needsPattern
53    * @param stablename
54    */
55   Condition(boolean isNumeric, boolean needsPattern, String stablename)
56   {
57     numeric = isNumeric;
58     needsAPattern = needsPattern;
59     stableName = stablename;
60   }
61
62   /**
63    * Answers true if the condition does a numerical comparison, else false
64    * (string comparison)
65    * 
66    * @return
67    */
68   public boolean isNumeric()
69   {
70     return numeric;
71   }
72
73   /**
74    * Answers true if the condition requires a pattern to compare against, else
75    * false
76    * 
77    * @return
78    */
79   public boolean needsAPattern()
80   {
81     return needsAPattern;
82   }
83
84   public String getStableName()
85   {
86     return stableName;
87   }
88
89   /**
90    * Answers a display name for the match condition, suitable for showing in
91    * drop-down menus. The value may be internationalized using the resource key
92    * "label.matchCondition_" with the enum name appended.
93    * 
94    * @return
95    */
96   @Override
97   public String toString()
98   {
99     return MessageManager.getStringOrReturn("label.matchCondition_",
100             name());
101   }
102 }