Consistent use of StringUtils.hasLength(String) vs isEmpty(Object)

This commit is contained in:
Juergen Hoeller
2019-05-03 17:29:14 +02:00
parent 84266d71e9
commit a7949ac84a
18 changed files with 49 additions and 42 deletions

View File

@@ -699,7 +699,7 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
*/
public Set<HttpMethod> getAllow() {
String value = getFirst(ALLOW);
if (!StringUtils.isEmpty(value)) {
if (StringUtils.hasLength(value)) {
String[] tokens = StringUtils.tokenizeToStringArray(value, ",");
List<HttpMethod> result = new ArrayList<>(tokens.length);
for (String token : tokens) {

View File

@@ -74,7 +74,7 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
Assert.notNull(exchange, "HttpServerExchange is required.");
String requestURL = exchange.getRequestURL();
String query = exchange.getQueryString();
String requestUriAndQuery = StringUtils.isEmpty(query) ? requestURL : requestURL + "?" + query;
String requestUriAndQuery = (StringUtils.hasLength(query) ? requestURL + "?" + query : requestURL);
return new URI(requestUriAndQuery);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -213,8 +213,8 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod
}
RequestParam requestParam = parameter.getParameterAnnotation(RequestParam.class);
String name = (requestParam == null || StringUtils.isEmpty(requestParam.name()) ?
parameter.getParameterName() : requestParam.name());
String name = (requestParam != null && StringUtils.hasLength(requestParam.name()) ?
requestParam.name() : parameter.getParameterName());
Assert.state(name != null, "Unresolvable parameter name");
if (value == null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -33,7 +33,6 @@ import org.springframework.util.StringUtils;
* <p>Provides options to create {@link UriBuilder} instances with a common
* base URI, alternative encoding mode strategies, among others.
*
*
* @author Rossen Stoyanchev
* @since 5.0
* @see UriComponentsBuilder
@@ -222,31 +221,27 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory {
private final UriComponentsBuilder uriComponentsBuilder;
public DefaultUriBuilder(String uriTemplate) {
this.uriComponentsBuilder = initUriComponentsBuilder(uriTemplate);
}
private UriComponentsBuilder initUriComponentsBuilder(String uriTemplate) {
UriComponentsBuilder result;
if (StringUtils.isEmpty(uriTemplate)) {
result = baseUri != null ? baseUri.cloneBuilder() : UriComponentsBuilder.newInstance();
if (!StringUtils.hasLength(uriTemplate)) {
result = (baseUri != null ? baseUri.cloneBuilder() : UriComponentsBuilder.newInstance());
}
else if (baseUri != null) {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uriTemplate);
UriComponents uri = builder.build();
result = uri.getHost() == null ? baseUri.cloneBuilder().uriComponents(uri) : builder;
result = (uri.getHost() == null ? baseUri.cloneBuilder().uriComponents(uri) : builder);
}
else {
result = UriComponentsBuilder.fromUriString(uriTemplate);
}
if (encodingMode.equals(EncodingMode.TEMPLATE_AND_VALUES)) {
result.encode();
}
parsePathIfNecessary(result);
return result;
}