code: public static String collapseDots(String path) {
      path = removeExtraneousSlashes(path);
      // Optimization: Most paths don't contain dots.
      if (!path.contains(".")) {
        return path;
      }
  
      List<String> dstFragments = new ArrayList<>();
      for (String fragment : Splitter.on('/').split(path)) {
        if (fragment.equals("..")) {
          if (!dstFragments.isEmpty()) {
            dstFragments.remove(dstFragments.size() - 1);
          }
        } else if (!fragment.equals(".")) {
          dstFragments.add(fragment);
        }
      }
  
      // Special case for Join.join([""]); -> "/"
      if (dstFragments.size() == 1 && dstFragments.get(0).isEmpty()) {
        return "/";
      }
      return Joiner.on("/").join(dstFragments);
    }
docs: Removes all ../ and ./ entries from within the given path. If there are extra ..s that move
  beyond the first directory given, they are removed.
  
  Examples:
  "a/b/../c" results in "a/c"
  "./foo/./../bar" results in "bar"
  "a/.." results in ""
  "a/../../foo" results in "foo"
  
  @param path The path to remove dots from.
  @return The path with all dots collapsed.