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-2012 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.
@@ -28,7 +28,7 @@ final class StringToCharacterConverter implements Converter<String, Character> {
@Override
public Character convert(String source) {
if (source.length() == 0) {
if (source.isEmpty()) {
return null;
}
if (source.length() > 1) {

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.
@@ -45,7 +45,7 @@ final class StringToEnumConverterFactory implements ConverterFactory<String, Enu
@Override
public T convert(String source) {
if (source.length() == 0) {
if (source.isEmpty()) {
// It's an empty enum identifier: reset the enum value to null.
return null;
}

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.
@@ -56,7 +56,7 @@ final class StringToNumberConverterFactory implements ConverterFactory<String, N
@Override
public T convert(String source) {
if (source.length() == 0) {
if (source.isEmpty()) {
return null;
}
return NumberUtils.parseNumber(source, this.targetType);

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.
@@ -809,7 +809,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
public PatternVirtualFileVisitor(String rootPath, String subPattern, PathMatcher pathMatcher) {
this.subPattern = subPattern;
this.pathMatcher = pathMatcher;
this.rootPath = (rootPath.length() == 0 || rootPath.endsWith("/") ? rootPath : rootPath + "/");
this.rootPath = (rootPath.isEmpty() || rootPath.endsWith("/") ? rootPath : rootPath + "/");
}
@Override

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.
@@ -120,7 +120,7 @@ public abstract class Base64Utils {
if (src == null) {
return null;
}
if (src.length() == 0) {
if (src.isEmpty()) {
return new byte[0];
}
return decode(src.getBytes(DEFAULT_CHARSET));

View File

@@ -180,7 +180,7 @@ public abstract class MimeTypeUtils {
int index = mimeType.indexOf(';');
String fullType = (index >= 0 ? mimeType.substring(0, index) : mimeType).trim();
if (fullType.length() == 0) {
if (fullType.isEmpty()) {
throw new InvalidMimeTypeException(mimeType, "'mimeType' must not be empty");
}

View File

@@ -373,7 +373,7 @@ public abstract class StringUtils {
* @param sub string to search for. Return 0 if this is {@code null}.
*/
public static int countOccurrencesOf(String str, String sub) {
if (str == null || sub == null || str.length() == 0 || sub.length() == 0) {
if (!hasLength(str) || !hasLength(sub)) {
return 0;
}
int count = 0;
@@ -515,7 +515,7 @@ public abstract class StringUtils {
}
private static String changeFirstCharacterCase(String str, boolean capitalize) {
if (str == null || str.length() == 0) {
if (!hasLength(str)) {
return str;
}
else {

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.
@@ -223,8 +223,8 @@ abstract class AbstractStaxHandler implements ContentHandler, LexicalHandler {
protected boolean isNamespaceDeclaration(QName qName) {
String prefix = qName.getPrefix();
String localPart = qName.getLocalPart();
return (XMLConstants.XMLNS_ATTRIBUTE.equals(localPart) && prefix.length() == 0) ||
(XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) && localPart.length() != 0);
return (XMLConstants.XMLNS_ATTRIBUTE.equals(localPart) && prefix.isEmpty()) ||
(XMLConstants.XMLNS_ATTRIBUTE.equals(prefix) && !localPart.isEmpty());
}