JAL-2808 update spike to latest (filter range, Present option)
[jalview.git] / src / jalview / util / matcher / Condition.java
1 package jalview.util.matcher;
2
3 import jalview.util.MessageManager;
4
5 import java.util.HashMap;
6 import java.util.Map;
7
8 /**
9  * An enumeration for binary conditions that a user might choose from when
10  * setting filter or match conditions for values
11  */
12 public enum Condition
13 {
14   Contains(false), NotContains(false), Matches(false), NotMatches(false),
15   Present(false), NotPresent(false),
16   EQ(true), NE(true), LT(true), LE(true), GT(true), GE(true);
17
18   private static Map<Condition, String> displayNames = new HashMap<>();
19   
20   private boolean numeric;
21
22   Condition(boolean isNumeric)
23   {
24     numeric = isNumeric;
25   }
26
27   /**
28    * Answers true if the condition does a numerical comparison, else false
29    * (string comparison)
30    * 
31    * @return
32    */
33   public boolean isNumeric()
34   {
35     return numeric;
36   }
37
38   /**
39    * Answers a display name for the match condition, suitable for showing in
40    * drop-down menus. The value may be internationalized using the resource key
41    * "label.matchCondition_" with the enum name appended.
42    * 
43    * @return
44    */
45   @Override
46   public String toString()
47   {
48     String name = displayNames.get(this);
49     if (name != null)
50     {
51       return name;
52     }
53     name = MessageManager
54             .getStringOrReturn("label.matchCondition_", name());
55     displayNames.put(this, name);
56     return name;
57   }
58 }