Polishing

This commit is contained in:
Juergen Hoeller
2018-03-29 17:34:28 +02:00
parent 64f304c333
commit bcda243f63
10 changed files with 61 additions and 66 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -240,8 +240,8 @@ public class UriComponentsBuilder implements Cloneable {
* be parsed unambiguously. Such values should be substituted for URI
* variables to enable correct parsing:
* <pre class="code">
* String uriString = &quot;/hotels/42?filter={value}&quot;;
* UriComponentsBuilder.fromUriString(uriString).buildAndExpand(&quot;hot&amp;cold&quot;);
* String urlString = &quot;https://example.com/hotels/42?filter={value}&quot;;
* UriComponentsBuilder.fromHttpUrl(urlString).buildAndExpand(&quot;hot&amp;cold&quot;);
* </pre>
* @param httpUrl the source URI
* @return the URI components of the URI
@@ -373,10 +373,10 @@ public class UriComponentsBuilder implements Cloneable {
}
// URI components methods
// Instance methods
/**
* Initialize all components of this URI builder with the components of the given URI.
* Initialize components of this builder from components of the given URI.
* @param uri the URI
* @return this UriComponentsBuilder
*/
@@ -412,6 +412,21 @@ public class UriComponentsBuilder implements Cloneable {
return this;
}
/**
* Set or append individual URI components of this builder from the values
* of the given {@link UriComponents} instance.
* <p>For the semantics of each component (i.e. set vs append) check the
* builder methods on this class. For example {@link #host(String)} sets
* while {@link #path(String)} appends.
* @param uriComponents the UriComponents to copy from
* @return this UriComponentsBuilder
*/
public UriComponentsBuilder uriComponents(UriComponents uriComponents) {
Assert.notNull(uriComponents, "UriComponents must not be null");
uriComponents.copyToUriComponentsBuilder(this);
return this;
}
/**
* Set the URI scheme. The given scheme may contain URI template variables,
* and may also be {@code null} to clear the scheme of this builder.
@@ -423,17 +438,6 @@ public class UriComponentsBuilder implements Cloneable {
return this;
}
/**
* Set all components of this URI builder from the given {@link UriComponents}.
* @param uriComponents the UriComponents instance
* @return this UriComponentsBuilder
*/
public UriComponentsBuilder uriComponents(UriComponents uriComponents) {
Assert.notNull(uriComponents, "UriComponents must not be null");
uriComponents.copyToUriComponentsBuilder(this);
return this;
}
/**
* Set the URI scheme-specific-part. When invoked, this method overwrites
* {@linkplain #userInfo(String) user-info}, {@linkplain #host(String) host},
@@ -509,17 +513,6 @@ public class UriComponentsBuilder implements Cloneable {
return this;
}
/**
* Set the path of this builder overriding all existing path and path segment values.
* @param path the URI path; a {@code null} value results in an empty path.
* @return this UriComponentsBuilder
*/
public UriComponentsBuilder replacePath(String path) {
this.pathBuilder = new CompositePathComponentBuilder(path);
resetSchemeSpecificPart();
return this;
}
/**
* Append path segments to the existing path. Each path segment may contain
* URI template variables and should not contain any slashes.
@@ -533,6 +526,17 @@ public class UriComponentsBuilder implements Cloneable {
return this;
}
/**
* Set the path of this builder overriding all existing path and path segment values.
* @param path the URI path (a {@code null} value results in an empty path)
* @return this UriComponentsBuilder
*/
public UriComponentsBuilder replacePath(String path) {
this.pathBuilder = new CompositePathComponentBuilder(path);
resetSchemeSpecificPart();
return this;
}
/**
* Append the given query to the existing query of this builder.
* The given query may contain URI template variables.
@@ -582,7 +586,7 @@ public class UriComponentsBuilder implements Cloneable {
* Append the given query parameter to the existing query parameters. The
* given name or any of the values may contain URI template variables. If no
* values are given, the resulting URI will contain the query parameter name
* only (i.e. {@code ?foo} instead of {@code ?foo=bar}.
* only (i.e. {@code ?foo} instead of {@code ?foo=bar}).
* @param name the query parameter name
* @param values the query parameter values
* @return this UriComponentsBuilder
@@ -704,7 +708,7 @@ public class UriComponentsBuilder implements Cloneable {
}
}
if ((this.scheme != null) && ((this.scheme.equals("http") && "80".equals(this.port)) ||
if (this.scheme != null && ((this.scheme.equals("http") && "80".equals(this.port)) ||
(this.scheme.equals("https") && "443".equals(this.port)))) {
port(null);
}
@@ -740,7 +744,6 @@ public class UriComponentsBuilder implements Cloneable {
/**
* Public declaration of Object's {@code clone()} method.
* Delegates to {@link #cloneBuilder()}.
* @see Object#clone()
*/
@Override
public Object clone() {

View File

@@ -185,7 +185,7 @@ public class UriComponentsBuilderTests {
}
@Test // SPR-9832
public void fromUriStringQueryParamWithReservedCharInValue() throws URISyntaxException {
public void fromUriStringQueryParamWithReservedCharInValue() {
String uri = "http://www.google.com/ig/calculator?q=1USD=?EUR";
UriComponents result = UriComponentsBuilder.fromUriString(uri).build();
@@ -494,7 +494,7 @@ public class UriComponentsBuilderTests {
}
@Test
public void path() throws URISyntaxException {
public void path() {
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar");
UriComponents result = builder.build();
@@ -503,7 +503,7 @@ public class UriComponentsBuilderTests {
}
@Test
public void pathSegments() throws URISyntaxException {
public void pathSegments() {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
UriComponents result = builder.pathSegment("foo").pathSegment("bar").build();
@@ -593,7 +593,7 @@ public class UriComponentsBuilderTests {
}
@Test
public void queryParams() throws URISyntaxException {
public void queryParams() {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
UriComponents result = builder.queryParam("baz", "qux", 42).build();
@@ -605,7 +605,7 @@ public class UriComponentsBuilderTests {
}
@Test
public void emptyQueryParam() throws URISyntaxException {
public void emptyQueryParam() {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();
UriComponents result = builder.queryParam("baz").build();