@Test public void testConstructMissingOptions() throws URISyntaxException { final URIPattern pattern = new URIPattern("scheme:/*path/:name"); TestHelpers.assertThrows("Should reject missing name", IllegalArgumentException.class, new Runnable() { @Override public void run() { Map<String, String> options = Maps.newHashMap(); options.put("path", "a/b/c"); pattern.construct(options); } }); Map<String, String> options = Maps.newHashMap(); options.put("name", "table-name"); URI constructed = pattern.construct(options); Assert.assertEquals(URI.create("scheme:/table-name"), constructed); }
public URI construct(Map<String, String> options) { Map<String, String> uriData = Maps.newLinkedHashMap(options); try { String scheme = defaults.get(SCHEME); if (uriData.containsKey(SCHEME)) { scheme = uriData.remove(SCHEME); } StringBuilder builder = new StringBuilder(); builder.append(scheme).append(":"); if (!pattern.isOpaque()) { StringBuilder authBuilder = new StringBuilder(); String user = constructUserInfo(uriData, defaults); String host = removeNonDefault(HOST, uriData, defaults); int port = constructPort(uriData, defaults); if (user != null) { authBuilder.append(user).append("@"); } if (host != null) { authBuilder.append(host); } if (port >= 0) { authBuilder.append(":").append(port); } String auth = authBuilder.toString(); if (!auth.isEmpty()) { builder.append(" } } builder.append(constructPath(uriData, patternPath)); String query = constructQuery(uriData, defaults); if (query != null) { builder.append("?").append(query); } return new URI(builder.toString()); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Could not build URI", ex); } }
URIPattern { public URI construct(Map<String, String> options) { Map<String, String> uriData = Maps.newLinkedHashMap(options); try { String scheme = defaults.get(SCHEME); if (uriData.containsKey(SCHEME)) { scheme = uriData.remove(SCHEME); } StringBuilder builder = new StringBuilder(); builder.append(scheme).append(":"); if (!pattern.isOpaque()) { StringBuilder authBuilder = new StringBuilder(); String user = constructUserInfo(uriData, defaults); String host = removeNonDefault(HOST, uriData, defaults); int port = constructPort(uriData, defaults); if (user != null) { authBuilder.append(user).append("@"); } if (host != null) { authBuilder.append(host); } if (port >= 0) { authBuilder.append(":").append(port); } String auth = authBuilder.toString(); if (!auth.isEmpty()) { builder.append(" } } builder.append(constructPath(uriData, patternPath)); String query = constructQuery(uriData, defaults); if (query != null) { builder.append("?").append(query); } return new URI(builder.toString()); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Could not build URI", ex); } } }
URIPattern { public URI construct(Map<String, String> options) { Map<String, String> uriData = Maps.newLinkedHashMap(options); try { String scheme = defaults.get(SCHEME); if (uriData.containsKey(SCHEME)) { scheme = uriData.remove(SCHEME); } StringBuilder builder = new StringBuilder(); builder.append(scheme).append(":"); if (!pattern.isOpaque()) { StringBuilder authBuilder = new StringBuilder(); String user = constructUserInfo(uriData, defaults); String host = removeNonDefault(HOST, uriData, defaults); int port = constructPort(uriData, defaults); if (user != null) { authBuilder.append(user).append("@"); } if (host != null) { authBuilder.append(host); } if (port >= 0) { authBuilder.append(":").append(port); } String auth = authBuilder.toString(); if (!auth.isEmpty()) { builder.append(" } } builder.append(constructPath(uriData, patternPath)); String query = constructQuery(uriData, defaults); if (query != null) { builder.append("?").append(query); } return new URI(builder.toString()); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Could not build URI", ex); } } URIPattern(URI uri);  URIPattern(String uri); }
URIPattern { public URI construct(Map<String, String> options) { Map<String, String> uriData = Maps.newLinkedHashMap(options); try { String scheme = defaults.get(SCHEME); if (uriData.containsKey(SCHEME)) { scheme = uriData.remove(SCHEME); } StringBuilder builder = new StringBuilder(); builder.append(scheme).append(":"); if (!pattern.isOpaque()) { StringBuilder authBuilder = new StringBuilder(); String user = constructUserInfo(uriData, defaults); String host = removeNonDefault(HOST, uriData, defaults); int port = constructPort(uriData, defaults); if (user != null) { authBuilder.append(user).append("@"); } if (host != null) { authBuilder.append(host); } if (port >= 0) { authBuilder.append(":").append(port); } String auth = authBuilder.toString(); if (!auth.isEmpty()) { builder.append(" } } builder.append(constructPath(uriData, patternPath)); String query = constructQuery(uriData, defaults); if (query != null) { builder.append("?").append(query); } return new URI(builder.toString()); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Could not build URI", ex); } } URIPattern(URI uri);  URIPattern(String uri); String getScheme(); String getPatternString(); @Override boolean equals(Object o); @Override int hashCode(); URI construct(Map<String, String> options); boolean matches(URI uri); boolean matches(String uri); Map<String, String> getMatch(URI uri); Map<String, String> getMatch(String uri); Map<String, String> getLastMatch(); @Override String toString(); }
URIPattern { public URI construct(Map<String, String> options) { Map<String, String> uriData = Maps.newLinkedHashMap(options); try { String scheme = defaults.get(SCHEME); if (uriData.containsKey(SCHEME)) { scheme = uriData.remove(SCHEME); } StringBuilder builder = new StringBuilder(); builder.append(scheme).append(":"); if (!pattern.isOpaque()) { StringBuilder authBuilder = new StringBuilder(); String user = constructUserInfo(uriData, defaults); String host = removeNonDefault(HOST, uriData, defaults); int port = constructPort(uriData, defaults); if (user != null) { authBuilder.append(user).append("@"); } if (host != null) { authBuilder.append(host); } if (port >= 0) { authBuilder.append(":").append(port); } String auth = authBuilder.toString(); if (!auth.isEmpty()) { builder.append(" } } builder.append(constructPath(uriData, patternPath)); String query = constructQuery(uriData, defaults); if (query != null) { builder.append("?").append(query); } return new URI(builder.toString()); } catch (URISyntaxException ex) { throw new IllegalArgumentException("Could not build URI", ex); } } URIPattern(URI uri);  URIPattern(String uri); String getScheme(); String getPatternString(); @Override boolean equals(Object o); @Override int hashCode(); URI construct(Map<String, String> options); boolean matches(URI uri); boolean matches(String uri); Map<String, String> getMatch(URI uri); Map<String, String> getMatch(String uri); Map<String, String> getLastMatch(); @Override String toString(); static final String SCHEME; static final String HOST; static final String PORT; static final String USERNAME; static final String PASSWORD; }