code: public static String normalizePath(String path) {
      String normalizedPath = path.replaceAll("//+", "/").replaceFirst("(.+)/$", "$1");
      PathUtils.validatePath(normalizedPath);
      return normalizedPath;
    }
docs: Validate and return a normalized zookeeper path which doesn't contain consecutive slashes and
  never ends with a slash (except for root path).
  
  @param path the path to be normalized
  @return normalized path string