Cleanup in UriUtils.getUpdateUri

- String instantiation replaced with StringBuilder and empty string constant

Signed-off-by: Laszlo Hornyak <laszlo.hornyak@gmail.com>
This commit is contained in:
Laszlo Hornyak 2014-02-11 18:56:37 +01:00
parent 59364ee9a4
commit 351ccf3755
2 changed files with 11 additions and 5 deletions

View File

@ -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();

View File

@ -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
}