JAL-2850 JAL-1766 option to load contig sequence referenced by VCF
[jalview.git] / src / jalview / util / matcher / KeyedMatcher.java
index cd952e7..f21756a 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;
   }
@@ -71,22 +73,24 @@ public class KeyedMatcher implements KeyedMatcherI
   }
 
   /**
-   * Answers a string description of this matcher, suitable for debugging or
-   * logging. The format may change in future.
+   * Answers a string description of this matcher, suitable for display, debugging
+   * or logging. The format may change in future.
    */
   @Override
   public String toString()
   {
     StringBuilder sb = new StringBuilder();
-    sb.append(key).append(" ").append(matcher.getCondition().toString())
-            .append(" ");
-    if (matcher.getCondition().isNumeric())
+    sb.append(String.join(COLON, key)).append(" ")
+            .append(matcher.getCondition().toString());
+    Condition condition = matcher.getCondition();
+    if (condition.isNumeric())
     {
-      sb.append(matcher.getPattern());
+      sb.append(" ").append(matcher.getPattern());
     }
-    else
+    else if (condition != Condition.Present
+            && condition != Condition.NotPresent)
     {
-      sb.append("'").append(matcher.getPattern()).append("'");
+      sb.append(" '").append(matcher.getPattern()).append("'");
     }
 
     return sb.toString();