package me.neurodock.genius; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.Map; public class ParameterStringBuilder { public static String getParamsString(Map params) throws UnsupportedEncodingException { if(params == null) return ""; StringBuilder result = new StringBuilder(); for (Map.Entry entry : params.entrySet()) { result.append(URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8)); result.append("="); result.append(URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8)); result.append("&"); } String resultString = result.toString(); return !resultString.isEmpty() ? resultString.substring(0, resultString.length() - 1) : resultString; } }