JAL-2835 spike updated with latest
[jalview.git] / src / jalview / util / matcher / KeyedMatcher.java
index 5e42e1c..ef1c702 100644 (file)
@@ -19,18 +19,20 @@ import java.util.function.Function;
  */
 public class KeyedMatcher implements KeyedMatcherI
 {
-  final private String key;
+  private static final String COLON = ":";
+
+  final private String[] key;
 
   final private MatcherI matcher;
 
   /**
    * Constructor given a key, a test condition and a match pattern
    * 
-   * @param theKey
    * @param cond
    * @param pattern
+   * @param theKey
    */
-  public KeyedMatcher(String theKey, Condition cond, String pattern)
+  public KeyedMatcher(Condition cond, String pattern, String... theKey)
   {
     key = theKey;
     matcher = new Matcher(cond, pattern);
@@ -41,25 +43,25 @@ public class KeyedMatcher implements KeyedMatcherI
    * to. Note that if a non-numerical condition is specified, the float will be
    * converted to a string.
    * 
-   * @param theKey
    * @param cond
    * @param value
+   * @param theKey
    */
-  public KeyedMatcher(String theKey, Condition cond, float value)
+  public KeyedMatcher(Condition cond, float value, String... theKey)
   {
     key = theKey;
     matcher = new Matcher(cond, value);
   }
 
   @Override
-  public boolean matches(Function<String, String> valueProvider)
+  public boolean matches(Function<String[], String> valueProvider)
   {
     String value = valueProvider.apply(key);
     return matcher.matches(value);
   }
 
   @Override
-  public String getKey()
+  public String[] getKey()
   {
     return key;
   }
@@ -78,8 +80,16 @@ public class KeyedMatcher implements KeyedMatcherI
   public String toString()
   {
     StringBuilder sb = new StringBuilder();
-    sb.append(key).append(" ").append(matcher.getCondition().toString())
-            .append(" ").append(matcher.getPattern());
+    sb.append(String.join(COLON, key)).append(" ")
+            .append(matcher.getCondition().toString()).append(" ");
+    if (matcher.getCondition().isNumeric())
+    {
+      sb.append(matcher.getPattern());
+    }
+    else
+    {
+      sb.append("'").append(matcher.getPattern()).append("'");
+    }
 
     return sb.toString();
   }