class RestxRouting {

    public Optional<Match> match(RestxRequest restxRequest) {
        for (RestxRoute route : routes) {
            Optional<? extends RestxHandlerMatch> match = route.match(restxRequest);
            if (match.isPresent()) {
                // here we need to:
                // - check which filters apply
                // - order all filters (route filters and regular filters) by priority
                // so we put all matches as NamedComponents (to preserve the filter priority) in a list,
                // and finally sort the list by priority before returning it as a Match
                ImmutableCollection<NamedComponent<RestxHandlerMatch>> routeFilters = this.routeFilters.get(route);

                List<NamedComponent<RestxHandlerMatch>> matches = Lists.newArrayListWithCapacity(
                        filters.size() + routeFilters.size() + 1);
                matches.addAll(routeFilters);

                for (NamedComponent<RestxFilter> filter : filters) {
                    Optional<? extends RestxHandlerMatch> filterMatch = filter.getComponent().match(restxRequest);
                    if (filterMatch.isPresent()) {
                        matches.add(NamedComponent.of(
                                RestxHandlerMatch.class, filter.getName().getName(),
                                filter.getPriority(), filterMatch.get()));
                    }
                }

                return Optional.of(new Match(
                        ImmutableList.<RestxHandlerMatch>builder()
                                .addAll(
                                        transform(Ordering.from(Factory.NAMED_COMPONENT_COMPARATOR).sortedCopy(matches),
                                                NamedComponent.<RestxHandlerMatch>toComponent()))
                                .add(match.get())
                                .build(),
                        match));
            }
        }
        return Optional.absent();
    }

    public  RestxRouting(ImmutableList<NamedComponent<RestxFilter>> filters,
                        ImmutableList<NamedComponent<RestxRouteFilter>> routeFilters,
                        ImmutableList<RestxRoute> routes);

}