*/
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);
* 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;
}
}
/**
- * 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();