Polishing contribution
Closes gh-25951
This commit is contained in:
@@ -336,14 +336,20 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultUriBuilder queryParamIfPresent(String name, Optional<?> optionalValue) {
|
||||
this.uriComponentsBuilder.queryParamIfPresent(name, optionalValue);
|
||||
public DefaultUriBuilder queryParam(String name, @Nullable Collection<?> values) {
|
||||
this.uriComponentsBuilder.queryParam(name, values);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultUriBuilder queryParam(String name, @Nullable Collection<?> values) {
|
||||
this.uriComponentsBuilder.queryParam(name, values);
|
||||
public DefaultUriBuilder queryParamIfPresent(String name, Optional<?> value) {
|
||||
this.uriComponentsBuilder.queryParamIfPresent(name, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultUriBuilder queryParams(MultiValueMap<String, String> params) {
|
||||
this.uriComponentsBuilder.queryParams(params);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -359,12 +365,6 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultUriBuilder queryParams(MultiValueMap<String, String> params) {
|
||||
this.uriComponentsBuilder.queryParams(params);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultUriBuilder replaceQueryParams(MultiValueMap<String, String> params) {
|
||||
this.uriComponentsBuilder.replaceQueryParams(params);
|
||||
|
||||
@@ -186,15 +186,6 @@ public interface UriBuilder {
|
||||
*/
|
||||
UriBuilder queryParam(String name, Object... values);
|
||||
|
||||
/**
|
||||
* Delegates to {@link #queryParam(String, Object...)} or {@link #queryParam(String, Object...)} if and only if optionalValue has a value.
|
||||
* No action will be taken, and the query parameter name will not be added, if optionalValue is empty.
|
||||
* @param name the query parameter name
|
||||
* @param optionalValue an Optional, either empty or holding the query parameter value.
|
||||
* @return
|
||||
*/
|
||||
UriBuilder queryParamIfPresent(String name, Optional<?> optionalValue);
|
||||
|
||||
/**
|
||||
* Variant of {@link #queryParam(String, Object...)} with a Collection.
|
||||
* <p><strong>Note: </strong> please, review the Javadoc of
|
||||
@@ -207,6 +198,16 @@ public interface UriBuilder {
|
||||
*/
|
||||
UriBuilder queryParam(String name, @Nullable Collection<?> values);
|
||||
|
||||
/**
|
||||
* Delegates to either {@link #queryParam(String, Object...)} or
|
||||
* {@link #queryParam(String, Collection)} if the given {@link Optional} has
|
||||
* a value, or else if it is empty, no query parameter is added at all.
|
||||
* @param name the query parameter name
|
||||
* @param value an Optional, either empty or holding the query parameter value.
|
||||
* @since 5.3
|
||||
*/
|
||||
UriBuilder queryParamIfPresent(String name, Optional<?> value);
|
||||
|
||||
/**
|
||||
* Add multiple query parameters and values.
|
||||
* <p><strong>Note: </strong> please, review the Javadoc of
|
||||
|
||||
@@ -710,22 +710,21 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public UriComponentsBuilder queryParamIfPresent(String name, Optional<?> optionalValue) {
|
||||
if (optionalValue.isPresent()) {
|
||||
Object value = optionalValue.get();
|
||||
if (value instanceof Collection) {
|
||||
queryParam(name, (Collection) value);
|
||||
}
|
||||
else {
|
||||
queryParam(name, value);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
public UriComponentsBuilder queryParam(String name, @Nullable Collection<?> values) {
|
||||
return queryParam(name, (CollectionUtils.isEmpty(values) ? EMPTY_VALUES : values.toArray()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public UriComponentsBuilder queryParam(String name, @Nullable Collection<?> values) {
|
||||
return queryParam(name, (CollectionUtils.isEmpty(values) ? EMPTY_VALUES : values.toArray()));
|
||||
public UriComponentsBuilder queryParamIfPresent(String name, Optional<?> value) {
|
||||
value.ifPresent(o -> {
|
||||
if (o instanceof Collection) {
|
||||
queryParam(name, (Collection<?>) o);
|
||||
}
|
||||
else {
|
||||
queryParam(name, o);
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user