code: public static String cleanPath(final String path) {
          final String result = path.replaceAll("//+", "/");
          return result.length() == 1 && result.charAt(0) == '/' ? result
                  : result.replaceAll("/+$", "");
      }
docs: Normalizes a path. If the path contains a single '/' character it is returned
  unchanged, otherwise the path is:
  <ol>
  <li>stripped from all multiple consecutive occurrences of '/' characters</li>
  <li>stripped from trailing '/' character(s)</li>
  </ol>
  
  @param path
  path to normalize
  @return normalized path