boolean isBeneath()

in hbase-oss/src/main/java/org/apache/hadoop/hbase/oss/sync/ZKTreeLockManager.java [265:283]


  boolean isBeneath(Path parent, Path given) {
    if (parent.equals(given)) {
      return false;
    }
    String parentPathStr = parent.toString();
    String givenPathStr = given.toString();
    int offset = givenPathStr.indexOf(parentPathStr);
    // Is the given path fully contained in some path beneath the parent.
    if (0 != offset) {
      return false;
    }
    // The given path is a substring of the parent path. It might share a common name (e.g. /foo and /foo1)
    // or it might be a subdirectory or file in the parent (e.g. /foo and /foo/bar)
    String givenRemainer = givenPathStr.substring(parentPathStr.length());
    // If the remainder of the given path starts with a '/', then it's contained beneath the parent.
    // If there are additional characters, the given path simple shares a prefix in the file/dir represented
    // by the parent.
    return givenRemainer.startsWith(Path.SEPARATOR);
  }