Use String#isEmpty()

Closes gh-1335
This commit is contained in:
stonio
2017-02-21 16:23:40 +01:00
committed by Stephane Nicoll
parent c85f063d92
commit 7d062df992
17 changed files with 45 additions and 43 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -160,7 +160,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
*/
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
String name = info.name;
if (info.name.length() == 0) {
if (info.name.isEmpty()) {
name = parameter.getParameterName();
if (name == null) {
throw new IllegalArgumentException(

View File

@@ -21,6 +21,7 @@ import java.util.HashMap;
import java.util.Map;
import org.springframework.util.PathMatcher;
import static org.springframework.util.StringUtils.hasLength;
/**
* Represents a parsed path pattern. Includes a chain of path elements
@@ -132,9 +133,9 @@ public class PathPattern implements Comparable<PathPattern> {
*/
public boolean matches(String path) {
if (head == null) {
return (path == null) || (path.length() == 0);
return !hasLength(path);
}
else if (path == null || path.length() == 0) {
else if (!hasLength(path)) {
if (head instanceof WildcardTheRestPathElement || head instanceof CaptureTheRestPathElement) {
path = ""; // Will allow CaptureTheRest to bind the variable to empty
}
@@ -152,9 +153,9 @@ public class PathPattern implements Comparable<PathPattern> {
*/
public boolean matchStart(String path) {
if (head == null) {
return (path == null || path.length() == 0);
return !hasLength(path);
}
else if (path == null || path.length() == 0) {
else if (!hasLength(path)) {
return true;
}
MatchingContext matchingContext = new MatchingContext(path, false);
@@ -172,7 +173,7 @@ public class PathPattern implements Comparable<PathPattern> {
return matchingContext.getExtractedVariables();
}
else {
if (path == null || path.length() == 0) {
if (!hasLength(path)) {
return NO_VARIABLES_MAP;
}
else {
@@ -434,15 +435,15 @@ public class PathPattern implements Comparable<PathPattern> {
*/
public String combine(String pattern2string) {
// If one of them is empty the result is the other. If both empty the result is ""
if (patternString == null || patternString.length() == 0) {
if (pattern2string == null || pattern2string.length() == 0) {
if (!hasLength(patternString)) {
if (!hasLength(pattern2string)) {
return "";
}
else {
return pattern2string;
}
}
else if (pattern2string == null || pattern2string.length() == 0) {
else if (!hasLength(pattern2string)) {
return patternString;
}
@@ -504,4 +505,4 @@ public class PathPattern implements Comparable<PathPattern> {
}
}
}
}