@Test public void testToQueryUrl() { Map<String, String> parameters = new HashMap<String, String>(); parameters.put(CommonParams.NAMESPACE_ID, "namespace"); parameters.put(CommonParams.SERVICE_NAME, "service"); parameters.put(CommonParams.GROUP_NAME, "group"); parameters.put(CommonParams.CLUSTER_NAME, null); parameters.put("ip", "1.1.1.1"); parameters.put("port", String.valueOf(9999)); parameters.put("weight", String.valueOf(1.0)); parameters.put("ephemeral", String.valueOf(true)); String excepted = "groupName=group&namespaceId=namespace&port=9999&ip=1.1.1.1&weight=1.0&ephemeral=true&serviceName=service"; assertEquals(excepted, Query.newInstance().initParams(parameters).toQueryUrl()); }
public String toQueryUrl() { StringBuilder urlBuilder = new StringBuilder(); Set<Map.Entry<String, Object>> entrySet = params.entrySet(); int i = entrySet.size(); for (Map.Entry<String, Object> entry : entrySet) { try { if (null != entry.getValue()) { urlBuilder.append(entry.getKey()).append("=") .append(URLEncoder.encode(String.valueOf(entry.getValue()), "UTF-8")); if (i > 1) { urlBuilder.append("&"); } } i--; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return urlBuilder.toString(); }
Query { public String toQueryUrl() { StringBuilder urlBuilder = new StringBuilder(); Set<Map.Entry<String, Object>> entrySet = params.entrySet(); int i = entrySet.size(); for (Map.Entry<String, Object> entry : entrySet) { try { if (null != entry.getValue()) { urlBuilder.append(entry.getKey()).append("=") .append(URLEncoder.encode(String.valueOf(entry.getValue()), "UTF-8")); if (i > 1) { urlBuilder.append("&"); } } i--; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return urlBuilder.toString(); } }
Query { public String toQueryUrl() { StringBuilder urlBuilder = new StringBuilder(); Set<Map.Entry<String, Object>> entrySet = params.entrySet(); int i = entrySet.size(); for (Map.Entry<String, Object> entry : entrySet) { try { if (null != entry.getValue()) { urlBuilder.append(entry.getKey()).append("=") .append(URLEncoder.encode(String.valueOf(entry.getValue()), "UTF-8")); if (i > 1) { urlBuilder.append("&"); } } i--; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return urlBuilder.toString(); } Query(); }
Query { public String toQueryUrl() { StringBuilder urlBuilder = new StringBuilder(); Set<Map.Entry<String, Object>> entrySet = params.entrySet(); int i = entrySet.size(); for (Map.Entry<String, Object> entry : entrySet) { try { if (null != entry.getValue()) { urlBuilder.append(entry.getKey()).append("=") .append(URLEncoder.encode(String.valueOf(entry.getValue()), "UTF-8")); if (i > 1) { urlBuilder.append("&"); } } i--; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return urlBuilder.toString(); } Query(); static Query newInstance(); Query addParam(String key, Object value); Object getValue(String key); Query initParams(Map<String, String> params); void initParams(List<String> list); String toQueryUrl(); void clear(); boolean isEmpty(); }
Query { public String toQueryUrl() { StringBuilder urlBuilder = new StringBuilder(); Set<Map.Entry<String, Object>> entrySet = params.entrySet(); int i = entrySet.size(); for (Map.Entry<String, Object> entry : entrySet) { try { if (null != entry.getValue()) { urlBuilder.append(entry.getKey()).append("=") .append(URLEncoder.encode(String.valueOf(entry.getValue()), "UTF-8")); if (i > 1) { urlBuilder.append("&"); } } i--; } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } return urlBuilder.toString(); } Query(); static Query newInstance(); Query addParam(String key, Object value); Object getValue(String key); Query initParams(Map<String, String> params); void initParams(List<String> list); String toQueryUrl(); void clear(); boolean isEmpty(); static final Query EMPTY; }