3401ae84e22986a2e4e483b3fff9430f4d72f367
[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, true), NotContains(false, true), Matches(false, true),
15   NotMatches(false, true), Present(false, false), NotPresent(false, false),
16   EQ(true, true), NE(true, true), LT(true, true), LE(true, true),
17   GT(true, true), GE(true, true);
18
19   private static Map<Condition, String> displayNames = new HashMap<>();
20   
21   private boolean numeric;
22
23   private boolean needsAPattern;
24
25   Condition(boolean isNumeric, boolean needsPattern)
26   {
27     numeric = isNumeric;
28     needsAPattern = needsPattern;
29   }
30
31   /**
32    * Answers true if the condition does a numerical comparison, else false
33    * (string comparison)
34    * 
35    * @return
36    */
37   public boolean isNumeric()
38   {
39     return numeric;
40   }
41
42   /**
43    * Answers true if the condition requires a pattern to compare against, else
44    * false
45    * 
46    * @return
47    */
48   public boolean needsAPattern()
49   {
50     return needsAPattern;
51   }
52
53   /**
54    * Answers a display name for the match condition, suitable for showing in
55    * drop-down menus. The value may be internationalized using the resource key
56    * "label.matchCondition_" with the enum name appended.
57    * 
58    * @return
59    */
60   @Override
61   public String toString()
62   {
63     String name = displayNames.get(this);
64     if (name != null)
65     {
66       return name;
67     }
68     name = MessageManager
69             .getStringOrReturn("label.matchCondition_", name());
70     displayNames.put(this, name);
71     return name;
72   }
73 }