Renamed UriBuilder to URIBuilder

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1172642 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2011-09-19 14:34:47 +00:00
parent 40a0ed44d2
commit eab98043c4
2 changed files with 27 additions and 24 deletions

View File

@ -36,7 +36,10 @@ import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
public class UriBuilder {
/**
* @since 4.2
*/
public class URIBuilder {
private String scheme;
private String schemeSpecificPart;
@ -48,17 +51,17 @@ public class UriBuilder {
private List<NameValuePair> queryParams;
private String fragment;
public UriBuilder() {
public URIBuilder() {
super();
this.port = -1;
}
public UriBuilder(final String string) throws URISyntaxException {
public URIBuilder(final String string) throws URISyntaxException {
super();
digestURI(new URI(string));
}
public UriBuilder(final URI uri) {
public URIBuilder(final URI uri) {
super();
digestURI(uri);
}
@ -108,7 +111,7 @@ public class UriBuilder {
/**
* Sets URI scheme.
*/
public UriBuilder setScheme(final String scheme) {
public URIBuilder setScheme(final String scheme) {
this.scheme = scheme;
return this;
}
@ -116,7 +119,7 @@ public class UriBuilder {
/**
* Sets URI user-info.
*/
public UriBuilder setUserInfo(final String userInfo) {
public URIBuilder setUserInfo(final String userInfo) {
this.userInfo = userInfo;
this.schemeSpecificPart = null;
this.authority = null;
@ -126,14 +129,14 @@ public class UriBuilder {
/**
* Sets URI user-info in a form of 'username:password'.
*/
public UriBuilder setUserInfo(final String username, final String password) {
public URIBuilder setUserInfo(final String username, final String password) {
return setUserInfo(username + ':' + password);
}
/**
* Sets URI host.
*/
public UriBuilder setHost(final String host) {
public URIBuilder setHost(final String host) {
this.host = host;
this.schemeSpecificPart = null;
this.authority = null;
@ -143,7 +146,7 @@ public class UriBuilder {
/**
* Sets URI port.
*/
public UriBuilder setPort(final int port) {
public URIBuilder setPort(final int port) {
this.port = port < 0 ? -1 : port;
this.schemeSpecificPart = null;
this.authority = null;
@ -153,7 +156,7 @@ public class UriBuilder {
/**
* Sets URI path.
*/
public UriBuilder setPath(final String path) {
public URIBuilder setPath(final String path) {
this.path = path;
this.schemeSpecificPart = null;
return this;
@ -162,7 +165,7 @@ public class UriBuilder {
/**
* Removes all query parameters.
*/
public UriBuilder removeQuery() {
public URIBuilder removeQuery() {
this.queryParams = null;
this.schemeSpecificPart = null;
return this;
@ -171,7 +174,7 @@ public class UriBuilder {
/**
* Set URI query.
*/
public UriBuilder setQuery(final String query) {
public URIBuilder setQuery(final String query) {
this.queryParams = parseQuery(query, HTTP.UTF_8);
this.schemeSpecificPart = null;
return this;
@ -180,7 +183,7 @@ public class UriBuilder {
/**
* Adds a parameter-value pair to URI query.
*/
public UriBuilder addParameter(final String param, final String value) {
public URIBuilder addParameter(final String param, final String value) {
if (this.queryParams == null) {
this.queryParams = new ArrayList<NameValuePair>();
}
@ -192,7 +195,7 @@ public class UriBuilder {
/**
* Sets parameter-value pair to URI query removing existing parameters with the same name.
*/
public UriBuilder setParameter(final String param, final String value) {
public URIBuilder setParameter(final String param, final String value) {
if (this.queryParams == null) {
this.queryParams = new ArrayList<NameValuePair>();
}
@ -212,7 +215,7 @@ public class UriBuilder {
/**
* Sets URI fragment.
*/
public UriBuilder setFragment(final String fragment) {
public URIBuilder setFragment(final String fragment) {
this.fragment = fragment;
return this;
}

View File

@ -36,7 +36,7 @@ public class TestURIBuilder {
@Test
public void testHierarchicalUri() throws Exception {
URI uri = new URI("http", "stuff", "localhost", 80, "/some stuff", "param=stuff", "fragment");
UriBuilder uribuilder = new UriBuilder(uri);
URIBuilder uribuilder = new URIBuilder(uri);
URI result = uribuilder.build();
Assert.assertEquals(uri, result);
}
@ -44,7 +44,7 @@ public class TestURIBuilder {
@Test
public void testOpaqueUri() throws Exception {
URI uri = new URI("stuff", "some-stuff", "fragment");
UriBuilder uribuilder = new UriBuilder(uri);
URIBuilder uribuilder = new URIBuilder(uri);
URI result = uribuilder.build();
Assert.assertEquals(uri, result);
}
@ -52,19 +52,19 @@ public class TestURIBuilder {
@Test
public void testOpaqueUriMutation() throws Exception {
URI uri = new URI("stuff", "some-stuff", "fragment");
UriBuilder uribuilder = new UriBuilder(uri).setQuery("param1&param2=stuff").setFragment(null);
URIBuilder uribuilder = new URIBuilder(uri).setQuery("param1&param2=stuff").setFragment(null);
Assert.assertEquals(new URI("stuff:?param1&param2=stuff"), uribuilder.build());
}
@Test
public void testHierarchicalUriMutation() throws Exception {
UriBuilder uribuilder = new UriBuilder("/").setScheme("http").setHost("localhost").setPort(80).setPath("/stuff");
URIBuilder uribuilder = new URIBuilder("/").setScheme("http").setHost("localhost").setPort(80).setPath("/stuff");
Assert.assertEquals(new URI("http://localhost:80/stuff"), uribuilder.build());
}
@Test
public void testEmpty() throws Exception {
UriBuilder uribuilder = new UriBuilder();
URIBuilder uribuilder = new URIBuilder();
URI result = uribuilder.build();
Assert.assertEquals(new URI(""), result);
}
@ -72,7 +72,7 @@ public class TestURIBuilder {
@Test
public void testSetUserInfo() throws Exception {
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff", null);
UriBuilder uribuilder = new UriBuilder(uri).setUserInfo("user", "password");
URIBuilder uribuilder = new URIBuilder(uri).setUserInfo("user", "password");
URI result = uribuilder.build();
Assert.assertEquals(new URI("http://user:password@localhost:80/?param=stuff"), result);
}
@ -80,7 +80,7 @@ public class TestURIBuilder {
@Test
public void testRemoveParameters() throws Exception {
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff", null);
UriBuilder uribuilder = new UriBuilder(uri).removeQuery();
URIBuilder uribuilder = new URIBuilder(uri).removeQuery();
URI result = uribuilder.build();
Assert.assertEquals(new URI("http://localhost:80/"), result);
}
@ -88,7 +88,7 @@ public class TestURIBuilder {
@Test
public void testSetParameter() throws Exception {
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff&blah&blah", null);
UriBuilder uribuilder = new UriBuilder(uri).setParameter("param", "some other stuff")
URIBuilder uribuilder = new URIBuilder(uri).setParameter("param", "some other stuff")
.setParameter("blah", "blah");
URI result = uribuilder.build();
Assert.assertEquals(new URI("http://localhost:80/?param=some+other+stuff&blah=blah"), result);
@ -97,7 +97,7 @@ public class TestURIBuilder {
@Test
public void testAddParameter() throws Exception {
URI uri = new URI("http", null, "localhost", 80, "/", "param=stuff&blah&blah", null);
UriBuilder uribuilder = new UriBuilder(uri).addParameter("param", "some other stuff")
URIBuilder uribuilder = new URIBuilder(uri).addParameter("param", "some other stuff")
.addParameter("blah", "blah");
URI result = uribuilder.build();
Assert.assertEquals(new URI("http://localhost:80/?param=stuff&blah&blah&" +