code: public static String buildPath(final boolean endWithSep,
                                   final String... val) {
      StringBuilder path = new StringBuilder();
  
      for (String s: val) {
        if (s != null) {
          path.append(s);
        }
      }
  
      String s = path.toString().replaceAll("/+",  "/");
  
      if (endWithSep) {
        if (!s.endsWith("/")) {
          s += "/";
        }
      } else if (s.endsWith("/")) {
        s = s.substring(0, s.length() - 1);
      }
  
      return s;
    }
docs: Build a path out of the given elements. Any parameter may be a path element
  or a path separator. Note this only allows "/" as the separator.
  
  <p>The path is constrained to either end or not end with the path separator.
  The path will be adjusted according to the constraint
  
  @param endWithSep
  @param val - list of elements and path separators.
  @return completed path