public boolean matches()

in src/main/java/org/apache/sling/api/resource/path/Path.java [115:160]


    public boolean matches(final String otherPath) {
        if (otherPath.startsWith(GLOB_PREFIX)) {
            if (this.isPattern) {
                // both are patterns, then they must be equal.
                // need to compare Pattern.pattern() as that class does
                // not implement a semantic equals(...) method
                final Path oPath = new Path(otherPath);
                return this.regexPattern.pattern().equals(oPath.regexPattern.pattern());
            }

            // this is path, provided argument is a pattern

            // simple check, if this is root, everything is a sub pattern
            if ("/".equals(this.path)) {
                return true;
            }
            // simplest case - the prefix of the glob pattern matches already
            // for example: this path = /apps
            //              glob      = /apps/**
            // then we iterate by removing the last path segment
            String subPath = otherPath;
            while (subPath != null) {
                final Path oPath = new Path(subPath);
                if (oPath.matches(this.path)) {
                    return true;
                }
                final int lastSlash = subPath.lastIndexOf('/');
                if (lastSlash == GLOB_PREFIX.length()) {
                    subPath = null;
                } else {
                    subPath = subPath.substring(0, lastSlash);
                }
            }

            return false;
        }

        // provided argument is a path
        if (!otherPath.startsWith("/")) {
            throw new IllegalArgumentException("Path must be absolute: " + otherPath);
        }
        if (isPattern) {
            return this.regexPattern.matcher(otherPath).matches();
        }
        return this.path.equals(otherPath) || otherPath.startsWith(this.prefix);
    }