ParameterizedString { public String applyParameters(final String input) { final Matcher matcher = parameterNamePattern.matcher(input); final StringBuffer b = new StringBuffer(); while(matcher.find()) { final String replaced = this.parameterHandler.apply(matcher.group(1)); matcher.appendReplacement(b, replaced); } matcher.appendTail(b); return b.toString(); } ParameterizedString(final Function<String, String> parameterHandler);  ParameterizedString(final Pattern parameterNamePattern, final Function<String, String> parameterHandler);  ParameterizedString(final String parameterNamePatternString, final Function<String, String> parameterHandler); String applyParameters(final String input); static final Pattern DEFAULT_PARAMETER_NAME_PATTERN; }
@Test public void applyParameters() { final String s = "We have {var1.d} of {var2} items."; ParameterizedString ps = new ParameterizedString(ParameterizedStringTest::getParameterValue); System.out.println(ps.applyParameters(s)); }