public String findLongestPathMatch ( String reqPath ) { SortedSet < String > tail = treeSet . tailSet ( reqPath ) ; if ( tail . isEmpty ( ) ) return null ; String after = tail . first ( ) ; if ( reqPath . startsWith ( after ) ) // common case return tail . first ( ) ; // have to check more, until no common starting chars for ( String key : tail ) { if ( reqPath . startsWith ( key ) ) return key ; // terminate when there's no match at all. if ( StringUtil2 . match ( reqPath , key ) == 0 ) break ; } return null ; }
Find the longest path match .