public static Path getParentRegardlessOfScheme(Path path, Collection<Path> candidates) {
    Path schemalessPath = Path.getPathWithoutSchemeAndAuthority(path);

    for(;path!=null && schemalessPath!=null; path=path.getParent(),schemalessPath=schemalessPath.getParent()){
      if(candidates.contains(path))
        return path;
      if(candidates.contains(schemalessPath))
        return schemalessPath;
    }
    // exception?
    return null;
  }
Returns the deepest candidate path for the given path.

prioritizes on paths including schema / then includes matches without schema

@param path
@param candidates  the candidate paths
@return
common/src/java/org/apache/hadoop/hive/common/FileUtils.java