cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ko...@apache.org
Subject [2/2] git commit: updated refs/heads/master to 351ccf3
Date Tue, 11 Feb 2014 20:32:44 GMT
Cleanup in UriUtils.getUpdateUri

- String instantiation replaced with StringBuilder and empty string constant

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/351ccf37
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/351ccf37
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/351ccf37

Branch: refs/heads/master
Commit: 351ccf3755f09529b6ccffe4a188d99a43a0d4e1
Parents: 59364ee
Author: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Authored: Tue Feb 11 18:56:37 2014 +0100
Committer: Laszlo Hornyak <laszlo.hornyak@gmail.com>
Committed: Tue Feb 11 20:44:57 2014 +0100

----------------------------------------------------------------------
 utils/src/com/cloud/utils/UriUtils.java      | 12 +++++++-----
 utils/test/com/cloud/utils/UriUtilsTest.java |  4 ++++
 2 files changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/351ccf37/utils/src/com/cloud/utils/UriUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/UriUtils.java b/utils/src/com/cloud/utils/UriUtils.java
index fab8ffc..bee660d 100644
--- a/utils/src/com/cloud/utils/UriUtils.java
+++ b/utils/src/com/cloud/utils/UriUtils.java
@@ -143,7 +143,7 @@ public class UriUtils {
             URIBuilder builder = new URIBuilder(url);
             builder.removeQuery();
 
-            String updatedQuery = new String();
+            StringBuilder updatedQuery = new StringBuilder();
             List<NameValuePair> queryParams = getUserDetails(query);
             ListIterator<NameValuePair> iterator = queryParams.listIterator();
             while (iterator.hasNext()) {
@@ -156,14 +156,16 @@ public class UriUtils {
                     value = param.getValue();
                 }
 
-                if (updatedQuery.isEmpty()) {
-                    updatedQuery += (param.getName() + "=" + value);
+                if (updatedQuery.length() == 0) {
+                    updatedQuery.append(param.getName()).append('=')
+                            .append(value);
                 } else {
-                    updatedQuery += ("&" + param.getName() + "=" + value);
+                    updatedQuery.append('&').append(param.getName())
+                            .append('=').append(value);
                 }
             }
 
-            String schemeAndHost = new String();
+            String schemeAndHost = "";
             URI newUri = builder.build();
             if (newUri.getScheme() != null) {
                 schemeAndHost = newUri.getScheme() + "://" + newUri.getHost();

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/351ccf37/utils/test/com/cloud/utils/UriUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/test/com/cloud/utils/UriUtilsTest.java b/utils/test/com/cloud/utils/UriUtilsTest.java
index 04fa3e5..e15456a 100644
--- a/utils/test/com/cloud/utils/UriUtilsTest.java
+++ b/utils/test/com/cloud/utils/UriUtilsTest.java
@@ -47,6 +47,10 @@ public class UriUtilsTest {
                 "http://localhost/foo/bar?password=1234", true).startsWith(
                 "http://localhost/foo/bar"));
 
+        //just to see if it is still ok with multiple parameters
+        Assert.assertEquals("http://localhost/foo/bar?param1=true&param2=12345", UriUtils
+                .getUpdateUri("http://localhost/foo/bar?param1=true&param2=12345", false));
+
         //XXX: Interesting cases not covered:
         // * port is ignored and left out from the return value
     }


Mime
View raw message