JAL-2808 classes to support filtering by attribute value
[jalview.git] / src / jalview / util / matcher / Condition.java
diff --git a/src/jalview/util/matcher/Condition.java b/src/jalview/util/matcher/Condition.java
new file mode 100644 (file)
index 0000000..455f805
--- /dev/null
@@ -0,0 +1,57 @@
+package jalview.util.matcher;
+
+import jalview.util.MessageManager;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * An enumeration for binary conditions that a user might choose from when
+ * setting filter or match conditions for values
+ */
+public enum Condition
+{
+  Contains(false), NotContains(false), Matches(false), NotMatches(false),
+  EQ(true), NE(true), LT(true), LE(true), GT(true), GE(true);
+
+  private static Map<Condition, String> displayNames = new HashMap<>();
+  
+  private boolean numeric;
+
+  Condition(boolean isNumeric)
+  {
+    numeric = isNumeric;
+  }
+
+  /**
+   * Answers true if the condition does a numerical comparison, else false
+   * (string comparison)
+   * 
+   * @return
+   */
+  public boolean isNumeric()
+  {
+    return numeric;
+  }
+
+  /**
+   * Answers a display name for the match condition, suitable for showing in
+   * drop-down menus. The value may be internationalized using the resource key
+   * "label.matchCondition_" with the enum name appended.
+   * 
+   * @return
+   */
+  @Override
+  public String toString()
+  {
+    String name = displayNames.get(this);
+    if (name != null)
+    {
+      return name;
+    }
+    name = MessageManager
+            .getStringOrReturn("label.matchCondition_", name());
+    displayNames.put(this, name);
+    return name;
+  }
+}