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 final private String key;
24 final private MatcherI matcher;
27 * Constructor given a key, a test condition and a match pattern
33 public KeyedMatcher(String theKey, Condition cond, String pattern)
36 matcher = new Matcher(cond, pattern);
40 * Constructor given a key, a test condition and a numerical value to compare
41 * to. Note that if a non-numerical condition is specified, the float will be
42 * converted to a string.
48 public KeyedMatcher(String theKey, Condition cond, float value)
51 matcher = new Matcher(cond, value);
55 public boolean matches(Function<String, String> valueProvider)
57 String value = valueProvider.apply(key);
58 return matcher.matches(value);
62 public String getKey()
68 public MatcherI getMatcher()
74 * Answers a string description of this matcher, suitable for debugging or
75 * logging. The format may change in future.
78 public String toString()
80 StringBuilder sb = new StringBuilder();
81 sb.append(key).append(" ").append(matcher.getCondition().toString())
83 if (matcher.getCondition().isNumeric())
85 sb.append(matcher.getPattern());
89 sb.append("'").append(matcher.getPattern()).append("'");