1
0
mirror of synced 2026-05-22 21:33:16 +00:00

Improve readability of empty collection checks

This commit is contained in:
kwonyonghyun
2024-10-15 03:49:39 +09:00
committed by Josh Cummings
parent 31bdaf720d
commit b8aa78829c
9 changed files with 16 additions and 16 deletions
@@ -202,7 +202,7 @@ public class AclImpl implements Acl, MutableAcl, AuditableAcl, OwnershipAcl {
public boolean isSidLoaded(List<Sid> sids) { public boolean isSidLoaded(List<Sid> sids) {
// If loadedSides is null, this indicates all SIDs were loaded // If loadedSides is null, this indicates all SIDs were loaded
// Also return true if the caller didn't specify a SID to find // Also return true if the caller didn't specify a SID to find
if ((this.loadedSids == null) || (sids == null) || (sids.size() == 0)) { if ((this.loadedSids == null) || (sids == null) || sids.isEmpty()) {
return true; return true;
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -140,7 +140,7 @@ public class DefaultPermissionFactory implements PermissionFactory {
@Override @Override
public List<Permission> buildFromNames(List<String> names) { public List<Permission> buildFromNames(List<String> names) {
if ((names == null) || (names.size() == 0)) { if ((names == null) || names.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
List<Permission> permissions = new ArrayList<>(names.size()); List<Permission> permissions = new ArrayList<>(names.size());
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -101,10 +101,10 @@ public class UserDetailsServiceFactoryBean implements ApplicationContextAware {
*/ */
private UserDetailsService getUserDetailsService() { private UserDetailsService getUserDetailsService() {
Map<String, ?> beans = getBeansOfType(CachingUserDetailsService.class); Map<String, ?> beans = getBeansOfType(CachingUserDetailsService.class);
if (beans.size() == 0) { if (beans.isEmpty()) {
beans = getBeansOfType(UserDetailsService.class); beans = getBeansOfType(UserDetailsService.class);
} }
if (beans.size() == 0) { if (beans.isEmpty()) {
throw new ApplicationContextException("No UserDetailsService registered."); throw new ApplicationContextException("No UserDetailsService registered.");
} }
if (beans.size() > 1) { if (beans.size() > 1) {
@@ -124,7 +124,7 @@ public class UserDetailsServiceFactoryBean implements ApplicationContextAware {
// Check ancestor bean factories if they exist and the current one has none of the // Check ancestor bean factories if they exist and the current one has none of the
// required type // required type
BeanFactory parent = this.beanFactory.getParentBeanFactory(); BeanFactory parent = this.beanFactory.getParentBeanFactory();
while (parent != null && beans.size() == 0) { while (parent != null && beans.isEmpty()) {
if (parent instanceof ListableBeanFactory) { if (parent instanceof ListableBeanFactory) {
beans = ((ListableBeanFactory) parent).getBeansOfType(type); beans = ((ListableBeanFactory) parent).getBeansOfType(type);
} }
@@ -80,7 +80,7 @@ public class RunAsManagerImpl implements RunAsManager, InitializingBean {
newAuthorities.add(extraAuthority); newAuthorities.add(extraAuthority);
} }
} }
if (newAuthorities.size() == 0) { if (newAuthorities.isEmpty()) {
return null; return null;
} }
// Add existing authorities // Add existing authorities
@@ -182,7 +182,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService, M
@Override @Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
List<UserDetails> users = loadUsersByUsername(username); List<UserDetails> users = loadUsersByUsername(username);
if (users.size() == 0) { if (users.isEmpty()) {
this.logger.debug("Query returned no results for user '" + username + "'"); this.logger.debug("Query returned no results for user '" + username + "'");
throw new UsernameNotFoundException(this.messages.getMessage("JdbcDaoImpl.notFound", throw new UsernameNotFoundException(this.messages.getMessage("JdbcDaoImpl.notFound",
new Object[] { username }, "Username {0} not found")); new Object[] { username }, "Username {0} not found"));
@@ -197,7 +197,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService, M
} }
List<GrantedAuthority> dbAuths = new ArrayList<>(dbAuthsSet); List<GrantedAuthority> dbAuths = new ArrayList<>(dbAuthsSet);
addCustomAuthorities(user.getUsername(), dbAuths); addCustomAuthorities(user.getUsername(), dbAuths);
if (dbAuths.size() == 0) { if (dbAuths.isEmpty()) {
this.logger.debug("User '" + username + "' has no authorities and will be treated as 'not found'"); this.logger.debug("User '" + username + "' has no authorities and will be treated as 'not found'");
throw new UsernameNotFoundException(this.messages.getMessage("JdbcDaoImpl.noAuthority", throw new UsernameNotFoundException(this.messages.getMessage("JdbcDaoImpl.noAuthority",
new Object[] { username }, "User {0} has no GrantedAuthority")); new Object[] { username }, "User {0} has no GrantedAuthority"));
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2021 the original author or authors. * Copyright 2002-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -73,7 +73,7 @@ public class ArrayMarshaller<E> implements Marshaller<ArrayTree<E>> {
* @param tree the tree to be marshalled * @param tree the tree to be marshalled
*/ */
public byte[] serialize(ArrayTree<E> tree) { public byte[] serialize(ArrayTree<E> tree) {
if ((tree == null) || (tree.size() == 0)) { if ((tree == null) || tree.isEmpty()) {
return EMPTY_TREE; return EMPTY_TREE;
} }
@@ -1,5 +1,5 @@
/* /*
* Copyright 2004-2022 the original author or authors. * Copyright 2004-2024 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -207,7 +207,7 @@ public abstract class AbstractAuthorizeTag {
ApplicationContext ctx = SecurityWebApplicationContextUtils ApplicationContext ctx = SecurityWebApplicationContextUtils
.findRequiredWebApplicationContext(getServletContext()); .findRequiredWebApplicationContext(getServletContext());
Map<String, WebInvocationPrivilegeEvaluator> wipes = ctx.getBeansOfType(WebInvocationPrivilegeEvaluator.class); Map<String, WebInvocationPrivilegeEvaluator> wipes = ctx.getBeansOfType(WebInvocationPrivilegeEvaluator.class);
if (wipes.size() == 0) { if (wipes.isEmpty()) {
throw new IOException( throw new IOException(
"No visible WebInvocationPrivilegeEvaluator instance could be found in the application " "No visible WebInvocationPrivilegeEvaluator instance could be found in the application "
+ "context. There must be at least one in order to support the use of URL access checks in 'authorize' tags."); + "context. There must be at least one in order to support the use of URL access checks in 'authorize' tags.");
@@ -163,7 +163,7 @@ public class AccessControlListTag extends TagSupport {
.getParent()) { .getParent()) {
map.putAll(context.getBeansOfType(type)); map.putAll(context.getBeansOfType(type));
} }
if (map.size() == 0) { if (map.isEmpty()) {
return null; return null;
} }
if (map.size() == 1) { if (map.size() == 1) {
@@ -211,7 +211,7 @@ public class FilterChainProxy extends GenericFilterBean {
FirewalledRequest firewallRequest = this.firewall.getFirewalledRequest((HttpServletRequest) request); FirewalledRequest firewallRequest = this.firewall.getFirewalledRequest((HttpServletRequest) request);
HttpServletResponse firewallResponse = this.firewall.getFirewalledResponse((HttpServletResponse) response); HttpServletResponse firewallResponse = this.firewall.getFirewalledResponse((HttpServletResponse) response);
List<Filter> filters = getFilters(firewallRequest); List<Filter> filters = getFilters(firewallRequest);
if (filters == null || filters.size() == 0) { if (filters == null || filters.isEmpty()) {
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace(LogMessage.of(() -> "No security for " + requestLine(firewallRequest))); logger.trace(LogMessage.of(() -> "No security for " + requestLine(firewallRequest)));
} }