JAL-2808 spike updated with latest
[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   EQ(true), NE(true), LT(true), LE(true), GT(true), GE(true);
16
17   private static Map<Condition, String> displayNames = new HashMap<>();
18   
19   private boolean numeric;
20
21   Condition(boolean isNumeric)
22   {
23     numeric = isNumeric;
24   }
25
26   /**
27    * Answers true if the condition does a numerical comparison, else false
28    * (string comparison)
29    * 
30    * @return
31    */
32   public boolean isNumeric()
33   {
34     return numeric;
35   }
36
37   /**
38    * Answers a display name for the match condition, suitable for showing in
39    * drop-down menus. The value may be internationalized using the resource key
40    * "label.matchCondition_" with the enum name appended.
41    * 
42    * @return
43    */
44   @Override
45   public String toString()
46   {
47     String name = displayNames.get(this);
48     if (name != null)
49     {
50       return name;
51     }
52     name = MessageManager
53             .getStringOrReturn("label.matchCondition_", name());
54     displayNames.put(this, name);
55     return name;
56   }
57 }