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

This commit is contained in:
Juergen Hoeller
2019-05-03 18:02:53 +02:00
parent 5be693dd04
commit 9198e037c1
17 changed files with 76 additions and 76 deletions

View File

@@ -700,7 +700,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

@@ -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.
@@ -70,10 +70,10 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
}
private static URI initUri(HttpServerExchange exchange) throws URISyntaxException {
Assert.notNull(exchange, "HttpServerExchange is required.");
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);
}
@@ -171,12 +171,10 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
boolean release = true;
try {
ByteBuffer byteBuffer = pooledByteBuffer.getBuffer();
int read = this.channel.read(byteBuffer);
if (logger.isTraceEnabled()) {
logger.trace("Channel read returned " + read + (read != -1 ? " bytes" : ""));
}
if (read > 0) {
byteBuffer.flip();
DataBuffer dataBuffer = this.bufferFactory.wrap(byteBuffer);
@@ -187,7 +185,8 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
onAllDataRead();
}
return null;
} finally {
}
finally {
if (release && pooledByteBuffer.isOpen()) {
pooledByteBuffer.close();
}
@@ -200,6 +199,7 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
}
}
private static class UndertowDataBuffer implements PooledDataBuffer {
private final DataBuffer dataBuffer;
@@ -299,8 +299,7 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
}
@Override
public DataBuffer read(byte[] destination, int offset,
int length) {
public DataBuffer read(byte[] destination, int offset, int length) {
return this.dataBuffer.read(destination, offset, length);
}
@@ -315,20 +314,17 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
}
@Override
public DataBuffer write(byte[] source, int offset,
int length) {
public DataBuffer write(byte[] source, int offset, int length) {
return this.dataBuffer.write(source, offset, length);
}
@Override
public DataBuffer write(
DataBuffer... buffers) {
public DataBuffer write(DataBuffer... buffers) {
return this.dataBuffer.write(buffers);
}
@Override
public DataBuffer write(
ByteBuffer... byteBuffers) {
public DataBuffer write(ByteBuffer... byteBuffers) {
return this.dataBuffer.write(byteBuffers);
}
@@ -362,4 +358,5 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest {
return this.dataBuffer.asOutputStream();
}
}
}

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