static String joinPaths(String firstPath, String... paths) {
    StringBuilder joined = new StringBuilder(firstPath);
    for(String path: paths) {
      if (path.isEmpty()) { /* NOP */ }
      else if (joined.length() == 0) {
        joined.append(path);
      }
      else if (joined.charAt(joined.length() - 1) == '/') {
        if (path.startsWith("/")) {
          joined.append(path.substring(1, path.length()));
        }
        else {
          joined.append(path);
        }
      }
      else {
        if (path.startsWith("/")) {
          joined.append(path);
        }
        else {
          joined.append('/').append(path);
        }

      }
    }
    return joined.toString();
  }
Joins path elements properly with slashes avoiding duplicate slashes.

@param firstPath the first path element
@param paths optionally other path elements
@return the joined path
ambari-utility/src/main/java/org/apache/ambari/swagger/AmbariSwaggerReader.java