private boolean matches(String pattern, String path, boolean matchAllSegments) {
        String[] pathSegments = path.substring(1).split("/");
        String[] patternSegments = pattern.substring(1).split("/");

        for (int i = 0; i < pathSegments.length; i++) {
            String pathSegment = pathSegments[i].trim();
            String patternSegment = patternSegments[i].trim();
            boolean endsWithWildCard = patternSegment.endsWith("*");
            boolean entireSegmentIsWild = endsWithWildCard && patternSegment.length() == 1;
            if (entireSegmentIsWild) {
                continue;
            } else if (endsWithWildCard) {
                //strip off wildcard
                patternSegment = patternSegment.substring(0, patternSegment.length() - 1);
                if (!pathSegment.startsWith(patternSegment)) {
                    return false;
                }
            } else {
                if (!pathSegment.equals(patternSegment)) {
                    return false;
                }
            }
        }

        if (matchAllSegments) {
            if (pathSegments.length != patternSegments.length) {
                int diff = patternSegments.length - pathSegments.length;
                int lowerBound = patternSegments.length - diff;
                for (int i = patternSegments.length - 1; i >= lowerBound; i--) {
                    if (!patternSegments[i].equals("*")) {
                        return false;
                    }
                }
            }
        }

        return true;

    }
private boolean matches ( String pattern , String path , boolean matchAllSegments ) { String [ ] pathSegments = path . substring ( 1 ) . split ( "/" ) ; String [ ] patternSegments = pattern . substring ( 1 ) . split ( "/" ) ; for ( int i = 0 ; i < pathSegments . length ; i ++ ) { String pathSegment = pathSegments [ i ] . trim ( ) ; String patternSegment = patternSegments [ i ] . trim ( ) ; boolean endsWithWildCard = patternSegment . endsWith ( "*" ) ; boolean entireSegmentIsWild = endsWithWildCard && patternSegment . length ( ) == 1 ; if ( entireSegmentIsWild ) { continue ; } else if ( endsWithWildCard ) { patternSegment = patternSegment . substring ( 0 , patternSegment . length ( ) - 1 ) ; if ( ! pathSegment . startsWith ( patternSegment ) ) { return false ; } } else { if ( ! pathSegment . equals ( patternSegment ) ) { return false ; } } } if ( matchAllSegments ) { if ( pathSegments . length != patternSegments . length ) { int diff = patternSegments . length - pathSegments . length ; int lowerBound = patternSegments . length - diff ; for ( int i = patternSegments . length - 1 ; i >= lowerBound ; i -- ) { if ( ! patternSegments [ i ] . equals ( "*" ) ) { return false ; } } } } return true ; }
@param pattern
@param path
@param matchAllSegments
@return