@ SuppressWarnings ( { "PMD.CyclomaticComplexity" , "PMD.NPathComplexity" , "PMD.CollapsibleIfStatements" , "PMD.DataflowAnomalyAnalysis" } ) public int matches ( URI resource ) { if ( protocol != null && ! protocol . equals ( "*" ) ) { if ( resource . getScheme ( ) == null ) { return - 1 ; } if ( Arrays . stream ( protocol . split ( "," ) ) . noneMatch ( proto -> proto . equals ( resource . getScheme ( ) ) ) ) { return - 1 ; } } if ( host != null && ! host . equals ( "*" ) ) { if ( resource . getHost ( ) == null || ! resource . getHost ( ) . equals ( host ) ) { return - 1 ; } } if ( port != null && ! port . equals ( "*" ) ) { if ( Integer . parseInt ( port ) != resource . getPort ( ) ) { return - 1 ; } } String [ ] reqElements = PathSpliterator . stream ( resource . getPath ( ) ) . skip ( 1 ) . toArray ( size -> new String [ size ] ) ; String [ ] reqElementsPlus = null ; // Created lazily for ( int pathIdx = 0 ; pathIdx < pathPatternElements . length ; pathIdx ++ ) { String [ ] pathPattern = pathPatternElements [ pathIdx ] ; if ( prefixSegs [ pathIdx ] == pathPattern . length - 1 && lastIsEmpty ( pathPattern ) ) { // Special case, pattern ends with vertical bar if ( reqElementsPlus == null ) { reqElementsPlus = reqElements ; if ( ! lastIsEmpty ( reqElementsPlus ) ) { reqElementsPlus = Arrays . copyOf ( reqElementsPlus , reqElementsPlus . length + 1 ) ; reqElementsPlus [ reqElementsPlus . length - 1 ] = "" ; } } if ( matchPath ( pathPattern , reqElementsPlus ) ) { return prefixSegs [ pathIdx ] ; } } else { if ( matchPath ( pathPattern , reqElements ) ) { return prefixSegs [ pathIdx ] ; } } } return - 1 ; }
Matches the given resource URI against the pattern .