JAL-2808 revised util.matcher package, 2 filter conditions per feature
[jalview.git] / src / jalview / util / matcher / Matcher.java
index b162d5d..638933d 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.util.matcher;
 
+import java.util.Objects;
 import java.util.regex.Pattern;
 
 /**
@@ -47,9 +48,14 @@ public class Matcher implements MatcherI
     if (cond.isNumeric())
     {
       value = Float.valueOf(compareTo);
+      pattern = String.valueOf(value);
     }
-    // pattern matches will be non-case-sensitive
-    pattern = compareTo.toUpperCase();
+    else
+    {
+      // pattern matches will be non-case-sensitive
+      pattern = compareTo.toUpperCase();
+    }
+
     // if we add regex conditions (e.g. matchesPattern), then
     // pattern should hold the raw regex, and
     // regexPattern = Pattern.compile(compareTo);
@@ -65,9 +71,10 @@ public class Matcher implements MatcherI
    */
   public Matcher(Condition cond, float compareTo)
   {
+    Objects.requireNonNull(cond);
     condition = cond;
     value = compareTo;
-    pattern = String.valueOf(compareTo);
+    pattern = String.valueOf(compareTo).toUpperCase();
   }
 
   /**
@@ -181,8 +188,8 @@ public class Matcher implements MatcherI
       return false;
     }
     Matcher m = (Matcher) obj;
-    return condition != m.condition || value != m.value
-            || !pattern.equals(m.pattern);
+    return condition == m.condition && value == m.value
+            && pattern.equals(m.pattern);
   }
 
   @Override
@@ -202,4 +209,10 @@ public class Matcher implements MatcherI
   {
     return value;
   }
+
+  @Override
+  public String toString()
+  {
+    return condition.name() + " " + pattern;
+  }
 }