Skip to content
Permalink
Browse files

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
  • Loading branch information
mthl committed May 25, 2019
1 parent fd7eab1 commit c79b0633ab5ce3c6895c81631939eb0a40f54a78
@@ -20,7 +20,6 @@

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 static String join(Collection<?> col, CharSequence delim) {
}


/**
* 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 void testStrToMap() {
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;

0 comments on commit c79b063

Please sign in to comment.
You can’t perform that action at this time.