public boolean isSubPathOf()

in bval-jsr/src/main/java/org/apache/bval/jsr/util/PathImpl.java [286:319]


    public boolean isSubPathOf(Path path) {
        if (path instanceof PathImpl && ((PathImpl) path).isRootPath()) {
            return true;
        }
        final Iterator<Node> pathIter = path.iterator();
        final Iterator<Node> thisIter = iterator();
        while (pathIter.hasNext()) {
            final Node pathNode = pathIter.next();
            if (!thisIter.hasNext()) {
                return false;
            }
            final Node thisNode = thisIter.next();
            if (pathNode.isInIterable()) {
                if (!thisNode.isInIterable()) {
                    return false;
                }
                if (pathNode.getIndex() != null && !pathNode.getIndex().equals(thisNode.getIndex())) {
                    return false;
                }
                if (pathNode.getKey() != null && !pathNode.getKey().equals(thisNode.getKey())) {
                    return false;
                }
            } else if (thisNode.isInIterable()) {
                // in this case we have shown that the proposed parent is not
                // indexed, and we are, thus the paths cannot match
                return false;
            }
            if (pathNode.getName() == null || pathNode.getName().equals(thisNode.getName())) {
                continue;
            }
            return false;
        }
        return true;
    }