/** * If there's no match, returns the result with {@link #notFound(Object) notFound} as the target * if it is set, otherwise returns {@code null}. */ public RouteResult<T> route(final HttpMethod method, final String uri) { final QueryStringDecoder decoder = new QueryStringDecoder(uri); final String[] tokens = StringUtil.split(Path.removeSlashesAtBothEnds(decoder.path()), '/'); MethodlessRouter<T> router = routers.get(method); if (router == null) { router = anyMethodRouter; } RouteResult<T> ret = router.route(tokens); if (ret != null) { return new RouteResult<T>(ret.target(), ret.pathParams(), decoder.parameters()); } if (router != anyMethodRouter) { ret = anyMethodRouter.route(tokens); if (ret != null) { return new RouteResult<T>(ret.target(), ret.pathParams(), decoder.parameters()); } } if (notFound != null) { // Return mutable map to be consistent, instead of // Collections.<String, String>emptyMap() return new RouteResult<T>(notFound, new HashMap<String, String>(), decoder.parameters()); } return null; }