UrlRewriter { @SuppressWarnings("unchecked") public static OptionMap parseOptionString(Class<?> controller, String optionString) { String[] urlTokens = optionString.split("\\?", 2); OptionMap options = OptionMap.of("controller", controller, "action", urlTokens[0]); if (urlTokens.length == 2 && !urlTokens[1].isEmpty()) { String[] paramToken = urlTokens[1].split("&"); Arrays.stream(paramToken) .map(kv -> kv.split("=", 2)) .filter(pair -> !pair[0].equals("controller") && !pair[0].equals("action")) .forEach(pair -> { if (pair.length == 1) { options.put(pair[0], null); } else if (pair.length == 2) { Object value = options.get(pair[0]); if (value == null) { options.put(pair[0], pair[1]); } else if (value instanceof List) { ((List<String>) value).add(pair[1]); } else { List<String> values = new ArrayList<>(); values.add(value.toString()); values.add(pair[1]); options.put(pair[0], values); } } }); } return options; }  static RoutingGenerationContext urlFor(OptionMap options); static RoutingGenerationContext urlFor(Class<?> controller, String optionString); static HttpResponse redirect(Class<?> controller, String options, HttpResponseUtils.RedirectStatusCode code); @SuppressWarnings("unchecked") static OptionMap parseOptionString(Class<?> controller, String optionString);  }
@Test void parseOptionString() { assertThat(UrlRewriter.parseOptionString(FooController.class, "index?a=1&b=2")) .contains(entry("a", "1")) .contains(entry("b", "2")); }