Skip to content

Commit

Permalink
Improved: Remove unused ‘StringUtil#mapToStr’ method
Browse files Browse the repository at this point in the history
(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 c79b063
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -216,51 +215,6 @@ public static Map<String, String> strToMap(String str) {
}


/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c79b063

Please sign in to comment.