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 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.util.matcher;
22
23 import jalview.util.MessageManager;
24
25 /**
26  * An enumeration for binary conditions that a user might choose from when
27  * setting filter or match conditions for values
28  */
29 public enum Condition
30 {
31   Contains(false, true, "Contains"),
32   NotContains(false, true, "NotContains"), Matches(false, true, "Matches"),
33   NotMatches(false, true, "NotMatches"), Present(false, false, "Present"),
34   NotPresent(false, false, "NotPresent"), EQ(true, true, "EQ"),
35   NE(true, true, "NE"), LT(true, true, "LT"), LE(true, true, "LE"),
36   GT(true, true, "GT"), GE(true, true, "GE");
37
38   private boolean numeric;
39
40   private boolean needsAPattern;
41
42   /*
43    * value used to save a Condition to the 
44    * Jalview project file or restore it from project; 
45    * it should not be changed even if enum names change in future
46    */
47   private String stableName;
48
49   /**
50    * Answers the enum value whose 'stable name' matches the argument (not case
51    * sensitive), or null if no match
52    * 
53    * @param stableName
54    * @return
55    */
56   public static Condition fromString(String stableName)
57   {
58     for (Condition c : values())
59     {
60       if (c.stableName.equalsIgnoreCase(stableName))
61       {
62         return c;
63       }
64     }
65     return null;
66   }
67
68   /**
69    * Constructor
70    * 
71    * @param isNumeric
72    * @param needsPattern
73    * @param stablename
74    */
75   Condition(boolean isNumeric, boolean needsPattern, String stablename)
76   {
77     numeric = isNumeric;
78     needsAPattern = needsPattern;
79     stableName = stablename;
80   }
81
82   /**
83    * Answers true if the condition does a numerical comparison, else false
84    * (string comparison)
85    * 
86    * @return
87    */
88   public boolean isNumeric()
89   {
90     return numeric;
91   }
92
93   /**
94    * Answers true if the condition requires a pattern to compare against, else
95    * false
96    * 
97    * @return
98    */
99   public boolean needsAPattern()
100   {
101     return needsAPattern;
102   }
103
104   public String getStableName()
105   {
106     return stableName;
107   }
108
109   /**
110    * Answers a display name for the match condition, suitable for showing in
111    * drop-down menus. The value may be internationalized using the resource key
112    * "label.matchCondition_" with the enum name appended.
113    * 
114    * @return
115    */
116   @Override
117   public String toString()
118   {
119     return MessageManager.getStringOrReturn("label.matchCondition_",
120             name());
121   }
122 }