Skip to content

Commit 21ae169

Browse files
committed
Merge pull request #1335 from stonio:patch-4
* pr/1335: Use String#isEmpty()
2 parents c85f063 + 7d062df commit 21ae169

File tree

17 files changed

+45
-43
lines changed

17 files changed

+45
-43
lines changed

spring-beans/src/main/java/org/springframework/beans/PropertyMatches.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -150,10 +150,10 @@ else if (i == this.possibleMatches.length - 2) {
150150
* @return the distance value
151151
*/
152152
private static int calculateStringDistance(String s1, String s2) {
153-
if (s1.length() == 0) {
153+
if (s1.isEmpty()) {
154154
return s2.length();
155155
}
156-
if (s2.length() == 0) {
156+
if (s2.isEmpty()) {
157157
return s1.length();
158158
}
159159
int d[][] = new int[s1.length() + 1][s2.length() + 1];

spring-core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ final class StringToCharacterConverter implements Converter<String, Character> {
2828

2929
@Override
3030
public Character convert(String source) {
31-
if (source.length() == 0) {
31+
if (source.isEmpty()) {
3232
return null;
3333
}
3434
if (source.length() > 1) {

spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ public StringToEnum(Class<T> enumType) {
4545

4646
@Override
4747
public T convert(String source) {
48-
if (source.length() == 0) {
48+
if (source.isEmpty()) {
4949
// It's an empty enum identifier: reset the enum value to null.
5050
return null;
5151
}

spring-core/src/main/java/org/springframework/core/convert/support/StringToNumberConverterFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ public StringToNumber(Class<T> targetType) {
5656

5757
@Override
5858
public T convert(String source) {
59-
if (source.length() == 0) {
59+
if (source.isEmpty()) {
6060
return null;
6161
}
6262
return NumberUtils.parseNumber(source, this.targetType);

spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -809,7 +809,7 @@ private static class PatternVirtualFileVisitor implements InvocationHandler {
809809
public PatternVirtualFileVisitor(String rootPath, String subPattern, PathMatcher pathMatcher) {
810810
this.subPattern = subPattern;
811811
this.pathMatcher = pathMatcher;
812-
this.rootPath = (rootPath.length() == 0 || rootPath.endsWith("/") ? rootPath : rootPath + "/");
812+
this.rootPath = (rootPath.isEmpty() || rootPath.endsWith("/") ? rootPath : rootPath + "/");
813813
}
814814

815815
@Override

spring-core/src/main/java/org/springframework/util/Base64Utils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -120,7 +120,7 @@ public static byte[] decodeFromString(String src) {
120120
if (src == null) {
121121
return null;
122122
}
123-
if (src.length() == 0) {
123+
if (src.isEmpty()) {
124124
return new byte[0];
125125
}
126126
return decode(src.getBytes(DEFAULT_CHARSET));

spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public static MimeType parseMimeType(String mimeType) {
180180

181181
int index = mimeType.indexOf(';');
182182
String fullType = (index >= 0 ? mimeType.substring(0, index) : mimeType).trim();
183-
if (fullType.length() == 0) {
183+
if (fullType.isEmpty()) {
184184
throw new InvalidMimeTypeException(mimeType, "'mimeType' must not be empty");
185185
}
186186

spring-core/src/main/java/org/springframework/util/StringUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ public static boolean substringMatch(CharSequence str, int index, CharSequence s
373373
* @param sub string to search for. Return 0 if this is {@code null}.
374374
*/
375375
public static int countOccurrencesOf(String str, String sub) {
376-
if (str == null || sub == null || str.length() == 0 || sub.length() == 0) {
376+
if (!hasLength(str) || !hasLength(sub)) {
377377
return 0;
378378
}
379379
int count = 0;
@@ -515,7 +515,7 @@ public static String uncapitalize(String str) {
515515
}
516516

517517
private static String changeFirstCharacterCase(String str, boolean capitalize) {
518-
if (str == null || str.length() == 0) {
518+
if (!hasLength(str)) {
519519
return str;
520520
}
521521
else {

spring-core/src/main/java/org/springframework/util/xml/AbstractStaxHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -223,8 +223,8 @@ protected QName toQName(String namespaceUri, String qualifiedName) {
223223
protected boolean isNamespaceDeclaration(QName qName) {
224224
String prefix = qName.getPrefix();
225225
String localPart = qName.getLocalPart();
226-
return (XMLConstants.XMLNS_ATTRIBUTE.equals(localPart) && prefix.length() == 0) ||
227-
(XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) && localPart.length() != 0);
226+
return (XMLConstants.XMLNS_ATTRIBUTE.equals(localPart) && prefix.isEmpty()) ||
227+
(XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) && !localPart.isEmpty());
228228
}
229229

230230

spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -79,7 +79,7 @@ public Expression parseExpression(String expressionString, ParserContext context
7979

8080
private Expression parseTemplate(String expressionString, ParserContext context)
8181
throws ParseException {
82-
if (expressionString.length() == 0) {
82+
if (expressionString.isEmpty()) {
8383
return new LiteralExpression("");
8484
}
8585
Expression[] expressions = parseExpressions(expressionString, context);
@@ -145,7 +145,7 @@ private Expression[] parseExpressions(String expressionString, ParserContext con
145145
suffixIndex);
146146
expr = expr.trim();
147147

148-
if (expr.length() == 0) {
148+
if (expr.isEmpty()) {
149149
throw new ParseException(expressionString, prefixIndex,
150150
"No expression defined within delimiter '" + prefix + suffix
151151
+ "' at character " + prefixIndex);

0 commit comments

Comments
 (0)