public void add(final String source, final T destination) {

    // replace multiple slashes with a single slash.
    String path = source.replaceAll("/+", "/");

    path = (path.endsWith("/") && path.length() > 1)
      ? path.substring(0, path.length() - 1) : path;


    String[] parts = path.split("/", maxPathParts + 2);
    if (parts.length - 1 > maxPathParts) {
      throw new IllegalArgumentException(String.format("Number of parts of path %s exceeds allowed limit %s",
                                                       source, maxPathParts));
    }
    StringBuilder sb =  new StringBuilder();
    List<String> groupNames = new ArrayList<>();

    for (String part : parts) {
      Matcher groupMatcher = GROUP_PATTERN.matcher(part);
      if (groupMatcher.matches()) {
        groupNames.add(groupMatcher.group(1));
        sb.append("([^/]+?)");
      } else if (WILD_CARD_PATTERN.matcher(part).matches()) {
        sb.append(".*?");
      } else {
        sb.append(part);
      }
      sb.append("/");
    }

    //Ignore the last "/"
    sb.setLength(sb.length() - 1);

    Pattern pattern = Pattern.compile(sb.toString());
    patternRouteList.add(ImmutablePair.of(pattern, new RouteDestinationWithGroups(destination, groupNames)));
  }
public void add ( final String source , final T destination ) { String path = source . replaceAll ( "/+" , "/" ) ; path = ( path . endsWith ( "/" ) && path . length ( ) > 1 ) ? path . substring ( 0 , path . length ( ) - 1 ) : path ; String [ ] parts = path . split ( "/" , maxPathParts + 2 ) ; if ( parts . length - 1 > maxPathParts ) { throw new IllegalArgumentException ( String . format ( "Number of parts of path %s exceeds allowed limit %s" , source , maxPathParts ) ) ; } StringBuilder sb = new StringBuilder ( ) ; List < String > groupNames = new ArrayList < > ( ) ; for ( String part : parts ) { Matcher groupMatcher = GROUP_PATTERN . matcher ( part ) ; if ( groupMatcher . matches ( ) ) { groupNames . add ( groupMatcher . group ( 1 ) ) ; sb . append ( "([^/]+?)" ) ; } else if ( WILD_CARD_PATTERN . matcher ( part ) . matches ( ) ) { sb . append ( ".*?" ) ; } else { sb . append ( part ) ; } sb . append ( "/" ) ; } sb . setLength ( sb . length ( ) - 1 ) ; Pattern pattern = Pattern . compile ( sb . toString ( ) ) ; patternRouteList . add ( ImmutablePair . of ( pattern , new RouteDestinationWithGroups ( destination , groupNames ) ) ) ; }
Add a source and destination.

@param source  Source path to be routed. Routed path can have named wild-card pattern with braces "{}".
@param destination Destination of the path.