@Test public void slashesInTheSecondGroup() { final String pattern = "/{singleSegment}/{manySegments:.+}"; final TokenParser parser = new TokenParser(pattern); log(parser); final Map<String, String> tokens = parser.parse("/1/2/3/4/5"); assertThat(tokens, is(notNullValue())); assertThat(tokens.entrySet(), hasSize(2)); assertThat(tokens.get("singleSegment"), is(equalTo("1"))); assertThat(tokens.get("manySegments"), is(equalTo("2/3/4/5"))); }
@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();  }