Improved: Remove unused ‘StringUtil#mapToStr’ method
(OFBIZ-11014) git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1859926 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -20,7 +20,6 @@ package org.apache.ofbiz.base.util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -216,51 +215,6 @@ public class StringUtil {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates an encoded String from a Map of name/value pairs (MUST BE STRINGS!)
|
||||
* @param map The Map of name/value pairs
|
||||
* @return String The encoded String
|
||||
*/
|
||||
public static String mapToStr(Map<? extends Object, ? extends Object> map) {
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder buf = new StringBuilder();
|
||||
boolean first = true;
|
||||
|
||||
for (Map.Entry<? extends Object, ? extends Object> entry: map.entrySet()) {
|
||||
Object key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
|
||||
if (!(key instanceof String) || !(value instanceof String)) {
|
||||
continue;
|
||||
}
|
||||
String encodedName = null;
|
||||
try {
|
||||
encodedName = URLEncoder.encode((String) key, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Debug.logError(e, module);
|
||||
}
|
||||
String encodedValue = null;
|
||||
try {
|
||||
encodedValue = URLEncoder.encode((String) value, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Debug.logError(e, module);
|
||||
}
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
buf.append("|");
|
||||
}
|
||||
|
||||
buf.append(encodedName);
|
||||
buf.append("=");
|
||||
buf.append(encodedValue);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a String version of a Map (should contain only strings) and creates a new Map.
|
||||
* Partial Map elements are skipped: <code>{foo=fooValue, bar=}</code> will contain only
|
||||
|
||||
@@ -88,14 +88,6 @@ public class StringUtilTests extends GenericTestCaseBase {
|
||||
assertEquals("double-trim", map("2", "two", "1", "one"), StringUtil.strToMap(" 1 = one | 2 = two ", true));
|
||||
}
|
||||
|
||||
public void testMapToStr() {
|
||||
assertNull("null-map", StringUtil.mapToStr(null));
|
||||
assertEquals("empty", "", StringUtil.mapToStr(Collections.emptyMap()));
|
||||
assertEquals("single", "1=one", StringUtil.mapToStr(map("1", "one")));
|
||||
assertEquals("double", "1=one|2=two", StringUtil.mapToStr(map("1", "one", "2", "two")));
|
||||
assertEquals("double-with-non-string", "1=one|2=two", StringUtil.mapToStr(map("a", this, "1", "one", "2", "two", this, "a")));
|
||||
}
|
||||
|
||||
public void testToMap() {
|
||||
for (String s: new String[] {"", "{", "}", "}{"}) {
|
||||
IllegalArgumentException caught = null;
|
||||
|
||||
Reference in New Issue
Block a user