Use Collections.isEmpty() instead of .size() == 0

Ensure that Collections.isEmpty() is used to check if there are no
elements in a collections. This is more explicit and can be faster than
calling .size().

Closes gh-4783
This commit is contained in:
Kirill Vlasov
2015-12-09 15:23:19 +05:00
committed by Phillip Webb
parent 6113643cbe
commit 786aacf2e9
19 changed files with 23 additions and 23 deletions

View File

@@ -57,7 +57,7 @@ public class HintCommand extends AbstractCommand {
if (index == 0) {
showCommandHints(starting);
}
else if ((arguments.size() > 0) && (starting.length() > 0)) {
else if (!arguments.isEmpty() && (starting.length() > 0)) {
String command = arguments.remove(0);
showCommandOptionHints(command, Collections.unmodifiableList(arguments),
starting);

View File

@@ -385,7 +385,7 @@ class ProjectGenerationRequest {
if (types.size() == 1) {
return types.values().iterator().next();
}
else if (types.size() == 0) {
else if (types.isEmpty()) {
throw new ReportableException("No type found with build '" + this.build
+ "' and format '" + this.format
+ "' check the service capabilities (--list)");

View File

@@ -96,7 +96,7 @@ public class SourceOptions {
}
this.args = Collections.unmodifiableList(
nonOptionArguments.subList(sourceArgCount, nonOptionArguments.size()));
Assert.isTrue(sources.size() > 0, "Please specify at least one file");
Assert.isTrue(!sources.isEmpty(), "Please specify at least one file");
this.sources = Collections.unmodifiableList(sources);
}

View File

@@ -187,7 +187,7 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader {
if (urls.isEmpty()) {
findGroovyJarsFromClassPath(parent, urls);
}
Assert.state(urls.size() > 0, "Unable to find groovy JAR");
Assert.state(!urls.isEmpty(), "Unable to find groovy JAR");
return new ArrayList<URL>(urls).toArray(new URL[urls.size()]);
}