svn commit: r1859926 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util: StringUtil.java test/StringUtilTests.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1859926 - in /ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util: StringUtil.java test/StringUtilTests.java

mthl
Author: mthl
Date: Sat May 25 09:21:06 2019
New Revision: 1859926

URL: http://svn.apache.org/viewvc?rev=1859926&view=rev
Log:
Improved: Remove unused ‘StringUtil#mapToStr’ method
(OFBIZ-11014)

Modified:
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java
    ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/StringUtilTests.java

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java?rev=1859926&r1=1859925&r2=1859926&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/StringUtil.java Sat May 25 09:21:06 2019
@@ -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;
@@ -217,51 +216,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
      * the foo element.

Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/StringUtilTests.java
URL: http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/StringUtilTests.java?rev=1859926&r1=1859925&r2=1859926&view=diff
==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/StringUtilTests.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/test/StringUtilTests.java Sat May 25 09:21:06 2019
@@ -88,14 +88,6 @@ public class StringUtilTests extends Gen
         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;