@Test public void sameNamedVariables() { final String pattern = "/{group:.+}/{name}/{version}/{name}-{version}.{ext}"; final TokenParser parser = new TokenParser(pattern); log(parser); Map<String, String> tokens; tokens = parser.parse("/org/eclipse/jetty/jetty-io/maven-metadata.xml"); assertThat(tokens, is(nullValue())); tokens = parser.parse("/org/eclipse/jetty/jetty-io1/8.1.16.v20140903/jetty-io2-8.1.16.v20140903.pom"); assertThat(tokens, is(nullValue())); tokens = parser.parse("/org/eclipse/jetty/jetty-io/8.1.16.v20140903/jetty-io-8.1.16.v20140903.pom"); assertThat(tokens, is(notNullValue())); assertThat(tokens.entrySet(), hasSize(4)); assertThat(tokens.get("group"), is(equalTo("org/eclipse/jetty"))); assertThat(tokens.get("name"), is(equalTo("jetty-io"))); assertThat(tokens.get("version"), is(equalTo("8.1.16.v20140903"))); assertThat(tokens.get("ext"), is(equalTo("pom"))); }
@Nullable public Map<String, String> parse(final String path) { final Matcher matcher = pattern.matcher(path); if (!matcher.matches()) { return null; } Map<String, String> values = new HashMap<>(); for (VariableToken variableToken : variables) { final String name = variableToken.getName(); final String value = matcher.group(variableToken.getRegexpGroupName()); if (values.containsKey(name)) { final String existingValue = values.get(name); if (!Objects.equals(existingValue, value)) { log.trace("Variable '{}' values mismatch: '{}' vs '{}'", name, existingValue, value); return null; } } else { values.put(name, value); } } return values; }
TokenParser extends ComponentSupport { @Nullable public Map<String, String> parse(final String path) { final Matcher matcher = pattern.matcher(path); if (!matcher.matches()) { return null; } Map<String, String> values = new HashMap<>(); for (VariableToken variableToken : variables) { final String name = variableToken.getName(); final String value = matcher.group(variableToken.getRegexpGroupName()); if (values.containsKey(name)) { final String existingValue = values.get(name); if (!Objects.equals(existingValue, value)) { log.trace("Variable '{}' values mismatch: '{}' vs '{}'", name, existingValue, value); return null; } } else { values.put(name, value); } } return values; } }
TokenParser extends ComponentSupport { @Nullable public Map<String, String> parse(final String path) { final Matcher matcher = pattern.matcher(path); if (!matcher.matches()) { return null; } Map<String, String> values = new HashMap<>(); for (VariableToken variableToken : variables) { final String name = variableToken.getName(); final String value = matcher.group(variableToken.getRegexpGroupName()); if (values.containsKey(name)) { final String existingValue = values.get(name); if (!Objects.equals(existingValue, value)) { log.trace("Variable '{}' values mismatch: '{}' vs '{}'", name, existingValue, value); return null; } } else { values.put(name, value); } } return values; } TokenParser(final String templatePattern); }
TokenParser extends ComponentSupport { @Nullable public Map<String, String> parse(final String path) { final Matcher matcher = pattern.matcher(path); if (!matcher.matches()) { return null; } Map<String, String> values = new HashMap<>(); for (VariableToken variableToken : variables) { final String name = variableToken.getName(); final String value = matcher.group(variableToken.getRegexpGroupName()); if (values.containsKey(name)) { final String existingValue = values.get(name); if (!Objects.equals(existingValue, value)) { log.trace("Variable '{}' values mismatch: '{}' vs '{}'", name, existingValue, value); return null; } } else { values.put(name, value); } } return values; } TokenParser(final String templatePattern); @Nullable Map<String, String> parse(final String path); String getPattern(); @Override String toString(); }
TokenParser extends ComponentSupport { @Nullable public Map<String, String> parse(final String path) { final Matcher matcher = pattern.matcher(path); if (!matcher.matches()) { return null; } Map<String, String> values = new HashMap<>(); for (VariableToken variableToken : variables) { final String name = variableToken.getName(); final String value = matcher.group(variableToken.getRegexpGroupName()); if (values.containsKey(name)) { final String existingValue = values.get(name); if (!Objects.equals(existingValue, value)) { log.trace("Variable '{}' values mismatch: '{}' vs '{}'", name, existingValue, value); return null; } } else { values.put(name, value); } } return values; } TokenParser(final String templatePattern); @Nullable Map<String, String> parse(final String path); String getPattern(); @Override String toString();  }