1 package jalview.util.matcher;
3 import java.util.function.Function;
6 * An immutable class that models one or more match conditions, each of which is
7 * applied to the value obtained by lookup given the match key.
9 * For example, the value provider could be a SequenceFeature's attributes map,
10 * and the conditions might be
12 * <li>CSQ contains "pathological"</li>
14 * <li>AF <= 1.0e-5</li>
20 public class KeyedMatcher implements KeyedMatcherI
22 private static final String COLON = ":";
24 final private String[] key;
26 final private MatcherI matcher;
29 * Constructor given a key, a test condition and a match pattern
35 public KeyedMatcher(Condition cond, String pattern, String... theKey)
38 matcher = new Matcher(cond, pattern);
42 * Constructor given a key, a test condition and a numerical value to compare
43 * to. Note that if a non-numerical condition is specified, the float will be
44 * converted to a string.
50 public KeyedMatcher(Condition cond, float value, String... theKey)
53 matcher = new Matcher(cond, value);
57 public boolean matches(Function<String[], String> valueProvider)
59 String value = valueProvider.apply(key);
60 return matcher.matches(value);
64 public String[] getKey()
70 public MatcherI getMatcher()
76 * Answers a string description of this matcher, suitable for debugging or
77 * logging. The format may change in future.
80 public String toString()
82 StringBuilder sb = new StringBuilder();
83 sb.append(String.join(COLON, key)).append(" ")
84 .append(matcher.getCondition().toString()).append(" ");
85 if (matcher.getCondition().isNumeric())
87 sb.append(matcher.getPattern());
91 sb.append("'").append(matcher.getPattern()).append("'");