Collection.isEmpty() should be used to test for emptiness

Closes gh-1670
This commit is contained in:
igor-suhorukov 2018-02-09 00:31:43 +03:00 committed by Stephane Nicoll
parent 7da40abba5
commit e381514b07
14 changed files with 17 additions and 17 deletions

View File

@ -72,7 +72,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
CacheNamespaceHandler.parseKeyGenerator(element, builder.getBeanDefinition()); CacheNamespaceHandler.parseKeyGenerator(element, builder.getBeanDefinition());
List<Element> cacheDefs = DomUtils.getChildElementsByTagName(element, DEFS_ELEMENT); List<Element> cacheDefs = DomUtils.getChildElementsByTagName(element, DEFS_ELEMENT);
if (cacheDefs.size() >= 1) { if (!cacheDefs.isEmpty()) {
// Using attributes source. // Using attributes source.
List<RootBeanDefinition> attributeSourceDefinitions = parseDefinitionsSources(cacheDefs, parserContext); List<RootBeanDefinition> attributeSourceDefinitions = parseDefinitionsSources(cacheDefs, parserContext);
builder.addPropertyValue("cacheOperationSources", attributeSourceDefinitions); builder.addPropertyValue("cacheOperationSources", attributeSourceDefinitions);

View File

@ -95,7 +95,7 @@ public abstract class JmxUtils {
// null means any registered server, but "" specifically means the platform server // null means any registered server, but "" specifically means the platform server
if (!"".equals(agentId)) { if (!"".equals(agentId)) {
List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(agentId); List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(agentId);
if (servers != null && servers.size() > 0) { if (servers != null && !servers.isEmpty()) {
// Check to see if an MBeanServer is registered. // Check to see if an MBeanServer is registered.
if (servers.size() > 1 && logger.isWarnEnabled()) { if (servers.size() > 1 && logger.isWarnEnabled()) {
logger.warn("Found more than one MBeanServer instance" + logger.warn("Found more than one MBeanServer instance" +

View File

@ -568,7 +568,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
*/ */
@Nullable @Nullable
public Validator getValidator() { public Validator getValidator() {
return (this.validators.size() > 0 ? this.validators.get(0) : null); return (!this.validators.isEmpty() ? this.validators.get(0) : null);
} }
/** /**

View File

@ -188,7 +188,7 @@ public class StringDecoder extends AbstractDataBufferDecoder<String> {
* Joins the given list of buffers into a single buffer. * Joins the given list of buffers into a single buffer.
*/ */
private static Mono<DataBuffer> joinUntilEndFrame(List<DataBuffer> dataBuffers) { private static Mono<DataBuffer> joinUntilEndFrame(List<DataBuffer> dataBuffers) {
if (dataBuffers.size() > 0) { if (!dataBuffers.isEmpty()) {
int lastIdx = dataBuffers.size() - 1; int lastIdx = dataBuffers.size() - 1;
if (isEndFrame(dataBuffers.get(lastIdx))) { if (isEndFrame(dataBuffers.get(lastIdx))) {
dataBuffers.remove(lastIdx); dataBuffers.remove(lastIdx);

View File

@ -40,7 +40,7 @@ class DatabasePopulatorConfigUtils {
public static void setDatabasePopulator(Element element, BeanDefinitionBuilder builder) { public static void setDatabasePopulator(Element element, BeanDefinitionBuilder builder) {
List<Element> scripts = DomUtils.getChildElementsByTagName(element, "script"); List<Element> scripts = DomUtils.getChildElementsByTagName(element, "script");
if (scripts.size() > 0) { if (!scripts.isEmpty()) {
builder.addPropertyValue("databasePopulator", createDatabasePopulator(element, scripts, "INIT")); builder.addPropertyValue("databasePopulator", createDatabasePopulator(element, scripts, "INIT"));
builder.addPropertyValue("databaseCleaner", createDatabasePopulator(element, scripts, "DESTROY")); builder.addPropertyValue("databaseCleaner", createDatabasePopulator(element, scripts, "DESTROY"));
} }

View File

@ -293,7 +293,7 @@ public class CallMetaDataContext {
if (this.outParameterNames.size() > 1) { if (this.outParameterNames.size() > 1) {
logger.warn("Accessing single output value when procedure has more than one output parameter"); logger.warn("Accessing single output value when procedure has more than one output parameter");
} }
return (this.outParameterNames.size() > 0 ? this.outParameterNames.get(0) : null); return (!this.outParameterNames.isEmpty() ? this.outParameterNames.get(0) : null);
} }
} }
@ -388,7 +388,7 @@ public class CallMetaDataContext {
SqlParameter param; SqlParameter param;
if (meta.getParameterType() == DatabaseMetaData.procedureColumnReturn) { if (meta.getParameterType() == DatabaseMetaData.procedureColumnReturn) {
param = declaredParams.get(getFunctionReturnName()); param = declaredParams.get(getFunctionReturnName());
if (param == null && getOutParameterNames().size() > 0) { if (param == null && !getOutParameterNames().isEmpty()) {
param = declaredParams.get(getOutParameterNames().get(0).toLowerCase()); param = declaredParams.get(getOutParameterNames().get(0).toLowerCase());
} }
if (param == null) { if (param == null) {

View File

@ -184,7 +184,7 @@ public class TableMetaDataContext {
if (generatedKeyNames.length > 0) { if (generatedKeyNames.length > 0) {
this.generatedKeyColumnsUsed = true; this.generatedKeyColumnsUsed = true;
} }
if (declaredColumns.size() > 0) { if (!declaredColumns.isEmpty()) {
return new ArrayList<>(declaredColumns); return new ArrayList<>(declaredColumns);
} }
Set<String> keys = new LinkedHashSet<>(generatedKeyNames.length); Set<String> keys = new LinkedHashSet<>(generatedKeyNames.length);

View File

@ -61,7 +61,7 @@ public class GeneratedKeyHolder implements KeyHolder {
@Override @Override
@Nullable @Nullable
public Number getKey() throws InvalidDataAccessApiUsageException, DataRetrievalFailureException { public Number getKey() throws InvalidDataAccessApiUsageException, DataRetrievalFailureException {
if (this.keyList.size() == 0) { if (this.keyList.isEmpty()) {
return null; return null;
} }
if (this.keyList.size() > 1 || this.keyList.get(0).size() > 1) { if (this.keyList.size() > 1 || this.keyList.get(0).size() > 1) {
@ -89,7 +89,7 @@ public class GeneratedKeyHolder implements KeyHolder {
@Override @Override
@Nullable @Nullable
public Map<String, Object> getKeys() throws InvalidDataAccessApiUsageException { public Map<String, Object> getKeys() throws InvalidDataAccessApiUsageException {
if (this.keyList.size() == 0) { if (this.keyList.isEmpty()) {
return null; return null;
} }
if (this.keyList.size() > 1) if (this.keyList.size() > 1)

View File

@ -151,7 +151,7 @@ abstract class BootstrapUtils {
@Nullable @Nullable
private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) {
Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class);
if (annotations.size() < 1) { if (annotations.isEmpty()) {
return null; return null;
} }
Assert.state(annotations.size() <= 1, () -> String.format( Assert.state(annotations.size() <= 1, () -> String.format(

View File

@ -201,7 +201,7 @@ public abstract class ModelAndViewAssert {
tempSet.addAll(incorrectSet); tempSet.addAll(incorrectSet);
tempSet.removeAll(assertionSet); tempSet.removeAll(assertionSet);
if (tempSet.size() > 0) { if (!tempSet.isEmpty()) {
sb.append("Set has too many elements:\n"); sb.append("Set has too many elements:\n");
for (Object element : tempSet) { for (Object element : tempSet) {
sb.append('-'); sb.append('-');
@ -214,7 +214,7 @@ public abstract class ModelAndViewAssert {
tempSet.addAll(assertionSet); tempSet.addAll(assertionSet);
tempSet.removeAll(incorrectSet); tempSet.removeAll(incorrectSet);
if (tempSet.size() > 0) { if (!tempSet.isEmpty()) {
sb.append("Set is missing elements:\n"); sb.append("Set is missing elements:\n");
for (Object element : tempSet) { for (Object element : tempSet) {
sb.append('-'); sb.append('-');

View File

@ -136,7 +136,7 @@ class RegexPathElement extends PathElement {
if (matches) { if (matches) {
if (isNoMorePattern()) { if (isNoMorePattern()) {
if (matchingContext.determineRemainingPath && if (matchingContext.determineRemainingPath &&
((this.variableNames.size() == 0) ? true : textToMatch.length() > 0)) { (this.variableNames.isEmpty() ? true : textToMatch.length() > 0)) {
matchingContext.remainingPathIndex = pathIndex + 1; matchingContext.remainingPathIndex = pathIndex + 1;
matches = true; matches = true;
} }

View File

@ -79,7 +79,7 @@ class InitBinderBindingContext extends BindingContext {
InitBinder ann = binderMethod.getMethodAnnotation(InitBinder.class); InitBinder ann = binderMethod.getMethodAnnotation(InitBinder.class);
Assert.state(ann != null, "No InitBinder annotation"); Assert.state(ann != null, "No InitBinder annotation");
Collection<String> names = Arrays.asList(ann.value()); Collection<String> names = Arrays.asList(ann.value());
return (names.size() == 0 || names.contains(dataBinder.getObjectName())); return (names.isEmpty() || names.contains(dataBinder.getObjectName()));
}) })
.forEach(method -> invokeBinderMethod(dataBinder, exchange, method)); .forEach(method -> invokeBinderMethod(dataBinder, exchange, method));

View File

@ -191,7 +191,7 @@ public class TagWriter {
} }
private boolean inTag() { private boolean inTag() {
return this.tagState.size() > 0; return !this.tagState.isEmpty();
} }
private TagStateEntry currentState() { private TagStateEntry currentState() {

View File

@ -180,7 +180,7 @@ public class GroovyMarkupConfigurer extends TemplateConfiguration
} }
ClassLoader classLoader = getApplicationContext().getClassLoader(); ClassLoader classLoader = getApplicationContext().getClassLoader();
Assert.state(classLoader != null, "No ClassLoader"); Assert.state(classLoader != null, "No ClassLoader");
return (urls.size() > 0 ? new URLClassLoader(urls.toArray(new URL[urls.size()]), classLoader) : classLoader); return (!urls.isEmpty() ? new URLClassLoader(urls.toArray(new URL[urls.size()]), classLoader) : classLoader);
} }
/** /**