TemplateBasedUriBuilder { public String build(String uri, Map<String, String> uriParameters) { StringBuilder composedUri = new StringBuilder(); java.util.regex.Matcher matcher = placeholderPattern.matcher(uri); int searchIx = 0; while (matcher.find(searchIx)) { composedUri.append(uri.substring(searchIx, matcher.start())); String parameterName = matcher.group(1); if (parameterName != null && parameterName.length() > 1) { String value = uriParameters.get(parameterName); if (value != null) { composedUri.append(value); } else { composedUri.append(matcher.group()); } } searchIx = matcher.end(); } if (searchIx < uri.length()) { composedUri.append(uri.substring(searchIx)); } return composedUri.toString(); }  String build(String uri, Map<String, String> uriParameters);  }
@Test public void templateBasedUriBuilding() { TemplateBasedUriBuilder builder = new TemplateBasedUriBuilder(); assertEquals("http: builder.build("http: ImmutableMap.of("host", "localhost", "port", "9080", "id", "0"))); assertEquals("https: builder.build("{scheme}: ImmutableMap.of("host", "localhost", "port", "9080", "id", "0", "scheme", "https"))); assertEquals("http: builder.build("http: ImmutableMap.of("host", "localhost", "port", "9080", "id", "0", "association", "repositories"))); assertEquals("http: builder.build("http: ImmutableMap.of("host", "localhost", "port", "9080", "id", "0", "association", "repositories"))); assertEquals("http: builder.build("{scheme}{host}:{port}{path}", ImmutableMap.of("scheme", "http: assertEquals("http: builder.build("{scheme}{hostName}:{port}{path1}", ImmutableMap.of("scheme", "http: }