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
pull/4783/merge
Kirill Vlasov 9 years ago committed by Phillip Webb
parent 6113643cbe
commit 786aacf2e9

@ -39,7 +39,7 @@ public class HealthIndicatorAutoConfigurationProperties {
}
public void setOrder(List<String> statusOrder) {
if (statusOrder != null && statusOrder.size() > 0) {
if (statusOrder != null && !statusOrder.isEmpty()) {
this.order = statusOrder;
}
}

@ -76,7 +76,7 @@ public class OrderedHealthAggregator extends AbstractHealthAggregator {
}
}
// If no status is given return UNKNOWN
if (filteredCandidates.size() == 0) {
if (filteredCandidates.isEmpty()) {
return Status.UNKNOWN;
}
// Sort given Status instances by configured order

@ -50,7 +50,7 @@ public abstract class AnyNestedCondition extends AbstractNestedCondition {
@Override
protected ConditionOutcome getFinalMatchOutcome(MemberMatchOutcomes memberOutcomes) {
return new ConditionOutcome(memberOutcomes.getMatches().size() > 0,
return new ConditionOutcome(!memberOutcomes.getMatches().isEmpty(),
"nested any match resulted in " + memberOutcomes.getMatches()
+ " matches and " + memberOutcomes.getNonMatches()
+ " non matches");

@ -47,7 +47,7 @@ class OnResourceCondition extends SpringBootCondition {
? this.defaultResourceLoader : context.getResourceLoader();
List<String> locations = new ArrayList<String>();
collectValues(locations, attributes.get("resources"));
Assert.isTrue(locations.size() > 0,
Assert.isTrue(!locations.isEmpty(),
"@ConditionalOnResource annotations must specify at least one resource location");
for (String location : locations) {
if (!loader

@ -106,7 +106,7 @@ public class AutoConfigurationReportLoggingInitializer
this.report = ConditionEvaluationReport
.get(this.applicationContext.getBeanFactory());
}
if (this.report.getConditionAndOutcomesBySource().size() > 0) {
if (!this.report.getConditionAndOutcomesBySource().isEmpty()) {
if (isCrashReport && this.logger.isInfoEnabled()
&& !this.logger.isDebugEnabled()) {
this.logger.info("\n\nError starting ApplicationContext. "

@ -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);

@ -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)");

@ -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);
}

@ -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()]);
}

@ -42,7 +42,7 @@ public class SnakeTimer {
private static final ConcurrentHashMap<Integer, Snake> snakes = new ConcurrentHashMap<Integer, Snake>();
public static synchronized void addSnake(Snake snake) {
if (snakes.size() == 0) {
if (snakes.isEmpty()) {
startTimer();
}
snakes.put(Integer.valueOf(snake.getId()), snake);
@ -54,7 +54,7 @@ public class SnakeTimer {
public static synchronized void removeSnake(Snake snake) {
snakes.remove(Integer.valueOf(snake.getId()));
if (snakes.size() == 0) {
if (snakes.isEmpty()) {
stopTimer();
}
}

@ -42,7 +42,7 @@ public class SnakeTimer {
private static final ConcurrentHashMap<Integer, Snake> snakes = new ConcurrentHashMap<Integer, Snake>();
public static synchronized void addSnake(Snake snake) {
if (snakes.size() == 0) {
if (snakes.isEmpty()) {
startTimer();
}
snakes.put(Integer.valueOf(snake.getId()), snake);
@ -54,7 +54,7 @@ public class SnakeTimer {
public static synchronized void removeSnake(Snake snake) {
snakes.remove(Integer.valueOf(snake.getId()));
if (snakes.size() == 0) {
if (snakes.isEmpty()) {
stopTimer();
}
}

@ -42,7 +42,7 @@ public class SnakeTimer {
private static final ConcurrentHashMap<Integer, Snake> snakes = new ConcurrentHashMap<Integer, Snake>();
public static synchronized void addSnake(Snake snake) {
if (snakes.size() == 0) {
if (snakes.isEmpty()) {
startTimer();
}
snakes.put(Integer.valueOf(snake.getId()), snake);
@ -54,7 +54,7 @@ public class SnakeTimer {
public static synchronized void removeSnake(Snake snake) {
snakes.remove(Integer.valueOf(snake.getId()));
if (snakes.size() == 0) {
if (snakes.isEmpty()) {
stopTimer();
}
}

@ -73,7 +73,7 @@ public class PropertiesMergingResourceTransformer implements ResourceTransformer
@Override
public boolean hasTransformedResource() {
return this.data.size() > 0;
return !this.data.isEmpty();
}
@Override

@ -504,7 +504,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor,
}
return;
}
if (profiles.size() > 0) {
if (!profiles.isEmpty()) {
addProfiles(profiles);
this.logger.debug("Activated profiles "
+ StringUtils.collectionToCommaDelimitedString(profiles));

@ -52,7 +52,7 @@ public class DelegatingApplicationContextInitializer implements
public void initialize(ConfigurableApplicationContext context) {
ConfigurableEnvironment environment = context.getEnvironment();
List<Class<?>> initializerClasses = getInitializerClasses(environment);
if (initializerClasses.size() > 0) {
if (!initializerClasses.isEmpty()) {
applyInitializerClasses(context, initializerClasses);
}
}

@ -261,13 +261,13 @@ abstract class AbstractFilterRegistrationBean extends RegistrationBean {
DEFAULT_URL_MAPPINGS);
}
else {
if (servletNames.size() > 0) {
if (!servletNames.isEmpty()) {
this.logger.info("Mapping filter: '" + registration.getName()
+ "' to servlets: " + servletNames);
registration.addMappingForServletNames(dispatcherTypes, this.matchAfter,
servletNames.toArray(new String[servletNames.size()]));
}
if (this.urlPatterns.size() > 0) {
if (!this.urlPatterns.isEmpty()) {
this.logger.info("Mapping filter: '" + registration.getName()
+ "' to urls: " + this.urlPatterns);
registration.addMappingForUrlPatterns(dispatcherTypes, this.matchAfter,

@ -137,7 +137,7 @@ public abstract class RegistrationBean implements ServletContextInitializer, Ord
"Registration is null. Was something already registered for name=["
+ this.name + "]?");
registration.setAsyncSupported(this.asyncSupported);
if (this.initParameters.size() > 0) {
if (!this.initParameters.isEmpty()) {
registration.setInitParameters(this.initParameters);
}
}

@ -119,7 +119,7 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit
.findAnnotation(getClass(), Configuration.class) != null) {
application.getSources().add(getClass());
}
Assert.state(application.getSources().size() > 0,
Assert.state(!application.getSources().isEmpty(),
"No SpringApplication sources have been defined. Either override the "
+ "configure method or add an @Configuration annotation");
// Ensure error pages are registered

@ -123,7 +123,7 @@ public class SpringApplicationContextLoader extends AbstractContextLoader {
Set<Object> sources = new LinkedHashSet<Object>();
sources.addAll(Arrays.asList(mergedConfig.getClasses()));
sources.addAll(Arrays.asList(mergedConfig.getLocations()));
Assert.state(sources.size() > 0, "No configuration classes "
Assert.state(!sources.isEmpty(), "No configuration classes "
+ "or locations found in @SpringApplicationConfiguration. "
+ "For default configuration detection to work you need "
+ "Spring 4.0.3 or better (found " + SpringVersion.getVersion() + ").");

Loading…
Cancel
Save