private long getWeightedMatchScore ( Iterable < String > requestUriParts , Iterable < String > destUriParts ) { // The score calculated below is a base 5 number // The score will have one digit for one part of the URI // This will allow for 27 parts in the path since log (Long.MAX_VALUE) to base 5 = 27.13 // We limit the number of parts in the path to 25 using MAX_PATH_PARTS constant above to avoid overflow during // score calculation long score = 0 ; for ( Iterator < String > rit = requestUriParts . iterator ( ) , dit = destUriParts . iterator ( ) ; rit . hasNext ( ) && dit . hasNext ( ) ; ) { String requestPart = rit . next ( ) ; String destPart = dit . next ( ) ; if ( requestPart . equals ( destPart ) ) { score = ( score * 5 ) + 4 ; } else if ( PatternPathRouterWithGroups . GROUP_PATTERN . matcher ( destPart ) . matches ( ) ) { score = ( score * 5 ) + 3 ; } else { score = ( score * 5 ) + 2 ; } } return score ; }
Generate a weighted score based on position for matches of URI parts . The matches are weighted in descending order from left to right . Exact match is weighted higher than group match and group match is weighted higher than wildcard match .