The following example builds a very simple, totally useless router that dispatches urls. This examples constructs a router where all some components of a URL have been decomposed into components, and several paths have all their required components and predicates defined. The router will then return the target value only if only a single rule is entirely matched.
final RouteMappings<String, Integer> mappings = RouteMappings.<String, Integer>empty()
.add(Maps.of("protocol", Predicates.is("http"), "host", Predicate.isEqual("example.com")), 12)
.add(Maps.of("protocol", Predicates.is("http"), "host", Predicate.isEqual("example2.com")), 34)
.add(Maps.of("protocol", Predicates.is("https")), 56);
final Router<String, Integer> router = mappings.router();
final Optional<Integer> https = router.route(Maps.of("protocol", "https")); // should return 56
final Optional<Integer> http = router.route(Maps.of("protocol", "http")); // 12 and 34 both match returns nothing.
final Optional<Integer> httpExample = router.route(Maps.of("protocol", "http", "host", "example.com")); // should return 12
assertEquals(Optional.of(56), https);
assertEquals(Optional.empty(), http); // matches two rules, there no value
assertEquals(Optional.of(12), httpExample);
This projects takes this project to the next level, supporting expressing rules about all components within a http request.