Use diamond type

This commit is contained in:
Johnny Lim
2017-11-20 02:25:30 +09:00
committed by Rob Winch
parent cfe40358bd
commit 57353d18e5
221 changed files with 423 additions and 428 deletions

View File

@@ -76,7 +76,7 @@ public class SecurityConfig implements ConfigAttribute {
public static List<ConfigAttribute> createList(String... attributeNames) {
Assert.notNull(attributeNames, "You must supply an array of attribute names");
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>(
List<ConfigAttribute> attributes = new ArrayList<>(
attributeNames.length);
for (String attribute : attributeNames) {

View File

@@ -75,7 +75,7 @@ public class Jsr250MethodSecurityMetadataSource extends
if (annotations == null || annotations.length == 0) {
return null;
}
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>();
List<ConfigAttribute> attributes = new ArrayList<>();
for (Annotation a : annotations) {
if (a instanceof DenyAll) {

View File

@@ -84,7 +84,7 @@ class SecuredAnnotationMetadataExtractor implements AnnotationMetadataExtractor<
public Collection<ConfigAttribute> extractAttributes(Secured secured) {
String[] attributeTokens = secured.value();
List<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>(
List<ConfigAttribute> attributes = new ArrayList<>(
attributeTokens.length);
for (String token : attributeTokens) {

View File

@@ -158,7 +158,7 @@ public abstract class SecurityExpressionRoot implements SecurityExpressionOperat
private Set<String> getAuthoritySet() {
if (roles == null) {
roles = new HashSet<String>();
roles = new HashSet<>();
Collection<? extends GrantedAuthority> userAuthorities = authentication
.getAuthorities();

View File

@@ -115,7 +115,7 @@ public class RoleHierarchyImpl implements RoleHierarchy {
return AuthorityUtils.NO_AUTHORITIES;
}
Set<GrantedAuthority> reachableRoles = new HashSet<GrantedAuthority>();
Set<GrantedAuthority> reachableRoles = new HashSet<>();
for (GrantedAuthority authority : authorities) {
addReachableRoles(reachableRoles, authority);
@@ -132,7 +132,7 @@ public class RoleHierarchyImpl implements RoleHierarchy {
+ " in zero or more steps.");
}
List<GrantedAuthority> reachableRoleList = new ArrayList<GrantedAuthority>(
List<GrantedAuthority> reachableRoleList = new ArrayList<>(
reachableRoles.size());
reachableRoleList.addAll(reachableRoles);
@@ -190,7 +190,7 @@ public class RoleHierarchyImpl implements RoleHierarchy {
Set<GrantedAuthority> rolesReachableInOneStepSet;
if (!this.rolesReachableInOneStepMap.containsKey(higherRole)) {
rolesReachableInOneStepSet = new HashSet<GrantedAuthority>();
rolesReachableInOneStepSet = new HashSet<>();
this.rolesReachableInOneStepMap.put(higherRole,
rolesReachableInOneStepSet);
}
@@ -212,17 +212,17 @@ public class RoleHierarchyImpl implements RoleHierarchy {
* detected)
*/
private void buildRolesReachableInOneOrMoreStepsMap() {
this.rolesReachableInOneOrMoreStepsMap = new HashMap<GrantedAuthority, Set<GrantedAuthority>>();
this.rolesReachableInOneOrMoreStepsMap = new HashMap<>();
// iterate over all higher roles from rolesReachableInOneStepMap
for (GrantedAuthority role : this.rolesReachableInOneStepMap.keySet()) {
Set<GrantedAuthority> rolesToVisitSet = new HashSet<GrantedAuthority>();
Set<GrantedAuthority> rolesToVisitSet = new HashSet<>();
if (this.rolesReachableInOneStepMap.containsKey(role)) {
rolesToVisitSet.addAll(this.rolesReachableInOneStepMap.get(role));
}
Set<GrantedAuthority> visitedRolesSet = new HashSet<GrantedAuthority>();
Set<GrantedAuthority> visitedRolesSet = new HashSet<>();
while (!rolesToVisitSet.isEmpty()) {
// take a role from the rolesToVisit set

View File

@@ -161,7 +161,7 @@ public abstract class AbstractSecurityInterceptor implements InitializingBean,
return;
}
Set<ConfigAttribute> unsupportedAttrs = new HashSet<ConfigAttribute>();
Set<ConfigAttribute> unsupportedAttrs = new HashSet<>();
for (ConfigAttribute attr : attributeDefs) {
if (!this.runAsManager.supports(attr)

View File

@@ -91,7 +91,7 @@ public class AfterInvocationProviderManager implements AfterInvocationManager,
public void setProviders(List<?> newList) {
checkIfValidList(newList);
providers = new ArrayList<AfterInvocationProvider>(newList.size());
providers = new ArrayList<>(newList.size());
for (Object currentObject : newList) {
Assert.isInstanceOf(AfterInvocationProvider.class, currentObject,

View File

@@ -71,7 +71,7 @@ public class RunAsManagerImpl implements RunAsManager, InitializingBean {
public Authentication buildRunAs(Authentication authentication, Object object,
Collection<ConfigAttribute> attributes) {
List<GrantedAuthority> newAuthorities = new ArrayList<GrantedAuthority>();
List<GrantedAuthority> newAuthorities = new ArrayList<>();
for (ConfigAttribute attribute : attributes) {
if (this.supports(attribute)) {

View File

@@ -95,7 +95,7 @@ public final class DelegatingMethodSecurityMetadataSource extends
@Override
public Collection<ConfigAttribute> getAllConfigAttributes() {
Set<ConfigAttribute> set = new HashSet<ConfigAttribute>();
Set<ConfigAttribute> set = new HashSet<>();
for (MethodSecurityMetadataSource s : methodSecurityMetadataSources) {
Collection<ConfigAttribute> attrs = s.getAllConfigAttributes();
if (attrs != null) {

View File

@@ -50,10 +50,10 @@ public class MapBasedMethodSecurityMetadataSource extends
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
/** Map from RegisteredMethod to ConfigAttribute list */
protected final Map<RegisteredMethod, List<ConfigAttribute>> methodMap = new HashMap<RegisteredMethod, List<ConfigAttribute>>();
protected final Map<RegisteredMethod, List<ConfigAttribute>> methodMap = new HashMap<>();
/** Map from RegisteredMethod to name pattern used for registration */
private final Map<RegisteredMethod, String> nameMap = new HashMap<RegisteredMethod, String>();
private final Map<RegisteredMethod, String> nameMap = new HashMap<>();
// ~ Methods
// ========================================================================================================
@@ -150,7 +150,7 @@ public class MapBasedMethodSecurityMetadataSource extends
}
Method[] methods = javaType.getMethods();
List<Method> matchingMethods = new ArrayList<Method>();
List<Method> matchingMethods = new ArrayList<>();
for (Method m : methods) {
if (m.getName().equals(mappedName) || isMatch(m.getName(), mappedName)) {
@@ -236,7 +236,7 @@ public class MapBasedMethodSecurityMetadataSource extends
*/
@Override
public Collection<ConfigAttribute> getAllConfigAttributes() {
Set<ConfigAttribute> allAttributes = new HashSet<ConfigAttribute>();
Set<ConfigAttribute> allAttributes = new HashSet<>();
for (List<ConfigAttribute> attributeList : methodMap.values()) {
allAttributes.addAll(attributeList);

View File

@@ -84,7 +84,7 @@ public class PrePostAnnotationSecurityMetadataSource extends
String postAuthorizeAttribute = postAuthorize == null ? null : postAuthorize
.value();
ArrayList<ConfigAttribute> attrs = new ArrayList<ConfigAttribute>(2);
ArrayList<ConfigAttribute> attrs = new ArrayList<>(2);
PreInvocationAttribute pre = attributeFactory.createPreInvocationAttribute(
preFilterAttribute, filterObject, preAuthorizeAttribute);

View File

@@ -66,7 +66,7 @@ public class UnanimousBased extends AbstractAccessDecisionManager {
int grant = 0;
int abstain = 0;
List<ConfigAttribute> singleAttributeList = new ArrayList<ConfigAttribute>(1);
List<ConfigAttribute> singleAttributeList = new ArrayList<>(1);
singleAttributeList.add(null);
for (ConfigAttribute attribute : attributes) {

View File

@@ -66,7 +66,7 @@ public abstract class AbstractAuthenticationToken implements Authentication,
"Authorities collection cannot contain any null elements");
}
}
ArrayList<GrantedAuthority> temp = new ArrayList<GrantedAuthority>(
ArrayList<GrantedAuthority> temp = new ArrayList<>(
authorities.size());
temp.addAll(authorities);
this.authorities = Collections.unmodifiableList(temp);

View File

@@ -181,7 +181,7 @@ public abstract class AbstractJaasAuthenticationProvider
// Create a set to hold the authorities, and add any that have already been
// applied.
authorities = new HashSet<GrantedAuthority>();
authorities = new HashSet<>();
// Get the subject principals and pass them to each of the AuthorityGranters
Set<Principal> principals = loginContext.getSubject().getPrincipals();
@@ -203,7 +203,7 @@ public abstract class AbstractJaasAuthenticationProvider
// Convert the authorities set back to an array and apply it to the token.
JaasAuthenticationToken result = new JaasAuthenticationToken(
request.getPrincipal(), request.getCredentials(),
new ArrayList<GrantedAuthority>(authorities), loginContext);
new ArrayList<>(authorities), loginContext);
// Publish the success event
publishSuccessEvent(result);

View File

@@ -116,8 +116,8 @@ public final class DelegatingSecurityContextCallable<V> implements Callable<V> {
*/
public static <V> Callable<V> create(Callable<V> delegate,
SecurityContext securityContext) {
return securityContext == null ? new DelegatingSecurityContextCallable<V>(
delegate) : new DelegatingSecurityContextCallable<V>(delegate,
return securityContext == null ? new DelegatingSecurityContextCallable<>(
delegate) : new DelegatingSecurityContextCallable<>(delegate,
securityContext);
}
}

View File

@@ -354,7 +354,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
ListItem list = items;
Stack<Item> stack = new Stack<Item>();
Stack<Item> stack = new Stack<>();
stack.push(list);
boolean isDigit = false;

View File

@@ -55,7 +55,7 @@ public abstract class AuthorityUtils {
*/
public static Set<String> authorityListToSet(
Collection<? extends GrantedAuthority> userAuthorities) {
Set<String> set = new HashSet<String>(userAuthorities.size());
Set<String> set = new HashSet<>(userAuthorities.size());
for (GrantedAuthority authority : userAuthorities) {
set.add(authority.getAuthority());
@@ -65,7 +65,7 @@ public abstract class AuthorityUtils {
}
public static List<GrantedAuthority> createAuthorityList(String... roles) {
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(roles.length);
List<GrantedAuthority> authorities = new ArrayList<>(roles.length);
for (String role : roles) {
authorities.add(new SimpleGrantedAuthority(role));

View File

@@ -47,7 +47,7 @@ public class MapBasedAttributes2GrantedAuthoritiesMapper implements
* Map the given array of attributes to Spring Security GrantedAuthorities.
*/
public List<GrantedAuthority> getGrantedAuthorities(Collection<String> attributes) {
ArrayList<GrantedAuthority> gaList = new ArrayList<GrantedAuthority>();
ArrayList<GrantedAuthority> gaList = new ArrayList<>();
for (String attribute : attributes) {
Collection<GrantedAuthority> c = attributes2grantedAuthoritiesMap
.get(attribute);
@@ -107,7 +107,7 @@ public class MapBasedAttributes2GrantedAuthoritiesMapper implements
* @return Collection containing the GrantedAuthority Collection
*/
private Collection<GrantedAuthority> getGrantedAuthorityCollection(Object value) {
Collection<GrantedAuthority> result = new ArrayList<GrantedAuthority>();
Collection<GrantedAuthority> result = new ArrayList<>();
addGrantedAuthorityCollection(result, value);
return result;
}

View File

@@ -62,7 +62,7 @@ public class SimpleAttributes2GrantedAuthoritiesMapper implements
* GrantedAuthorities.
*/
public List<GrantedAuthority> getGrantedAuthorities(Collection<String> attributes) {
List<GrantedAuthority> result = new ArrayList<GrantedAuthority>(attributes.size());
List<GrantedAuthority> result = new ArrayList<>(attributes.size());
for (String attribute : attributes) {
result.add(getGrantedAuthority(attribute));
}

View File

@@ -54,7 +54,7 @@ public final class SimpleAuthorityMapper implements GrantedAuthoritiesMapper,
*/
public Set<GrantedAuthority> mapAuthorities(
Collection<? extends GrantedAuthority> authorities) {
HashSet<GrantedAuthority> mapped = new HashSet<GrantedAuthority>(
HashSet<GrantedAuthority> mapped = new HashSet<>(
authorities.size());
for (GrantedAuthority authority : authorities) {
mapped.add(mapAuthority(authority.getAuthority()));

View File

@@ -41,7 +41,7 @@ public class SimpleMappableAttributesRetriever implements MappableAttributesRetr
}
public void setMappableAttributes(Set<String> aMappableRoles) {
this.mappableAttributes = new HashSet<String>();
this.mappableAttributes = new HashSet<>();
this.mappableAttributes.addAll(aMappableRoles);
this.mappableAttributes = Collections.unmodifiableSet(this.mappableAttributes);
}

View File

@@ -31,7 +31,7 @@ final class InheritableThreadLocalSecurityContextHolderStrategy implements
// ~ Static fields/initializers
// =====================================================================================
private static final ThreadLocal<SecurityContext> contextHolder = new InheritableThreadLocal<SecurityContext>();
private static final ThreadLocal<SecurityContext> contextHolder = new InheritableThreadLocal<>();
// ~ Methods
// ========================================================================================================

View File

@@ -32,7 +32,7 @@ final class ThreadLocalSecurityContextHolderStrategy implements
// ~ Static fields/initializers
// =====================================================================================
private static final ThreadLocal<SecurityContext> contextHolder = new ThreadLocal<SecurityContext>();
private static final ThreadLocal<SecurityContext> contextHolder = new ThreadLocal<>();
// ~ Methods
// ========================================================================================================

View File

@@ -91,7 +91,7 @@ public class AnnotationParameterNameDiscoverer implements ParameterNameDiscovere
private final Set<String> annotationClassesToUse;
public AnnotationParameterNameDiscoverer(String... annotationClassToUse) {
this(new HashSet<String>(Arrays.asList(annotationClassToUse)));
this(new HashSet<>(Arrays.asList(annotationClassToUse)));
}
public AnnotationParameterNameDiscoverer(Set<String> annotationClassesToUse) {
@@ -210,4 +210,4 @@ public class AnnotationParameterNameDiscoverer implements ParameterNameDiscovere
*/
Annotation[][] findParameterAnnotations(T t);
}
}
}

View File

@@ -81,7 +81,7 @@ public class DefaultSecurityParameterNameDiscoverer extends
addDiscoverer(discover);
}
Set<String> annotationClassesToUse = new HashSet<String>(2);
Set<String> annotationClassesToUse = new HashSet<>(2);
annotationClassesToUse.add("org.springframework.security.access.method.P");
annotationClassesToUse.add(P.class.getName());
if (DATA_PARAM_PRESENT) {
@@ -91,4 +91,4 @@ public class DefaultSecurityParameterNameDiscoverer extends
addDiscoverer(new AnnotationParameterNameDiscoverer(annotationClassesToUse));
addDiscoverer(new DefaultParameterNameDiscoverer());
}
}
}

View File

@@ -56,8 +56,8 @@ public class SessionRegistryImpl implements SessionRegistry,
// ========================================================================================================
public SessionRegistryImpl() {
this.principals = new ConcurrentHashMap<Object, Set<String>>();
this.sessionIds = new ConcurrentHashMap<String, SessionInformation>();
this.principals = new ConcurrentHashMap<>();
this.sessionIds = new ConcurrentHashMap<>();
}
public SessionRegistryImpl(ConcurrentMap<Object, Set<String>> principals, Map<String, SessionInformation> sessionIds) {
@@ -66,7 +66,7 @@ public class SessionRegistryImpl implements SessionRegistry,
}
public List<Object> getAllPrincipals() {
return new ArrayList<Object>(principals.keySet());
return new ArrayList<>(principals.keySet());
}
public List<SessionInformation> getAllSessions(Object principal,
@@ -77,7 +77,7 @@ public class SessionRegistryImpl implements SessionRegistry,
return Collections.emptyList();
}
List<SessionInformation> list = new ArrayList<SessionInformation>(
List<SessionInformation> list = new ArrayList<>(
sessionsUsedByPrincipal.size());
for (String sessionId : sessionsUsedByPrincipal) {
@@ -135,7 +135,7 @@ public class SessionRegistryImpl implements SessionRegistry,
Set<String> sessionsUsedByPrincipal = principals.get(principal);
if (sessionsUsedByPrincipal == null) {
sessionsUsedByPrincipal = new CopyOnWriteArraySet<String>();
sessionsUsedByPrincipal = new CopyOnWriteArraySet<>();
Set<String> prevSessionsUsedByPrincipal = principals.putIfAbsent(principal,
sessionsUsedByPrincipal);
if (prevSessionsUsedByPrincipal != null) {

View File

@@ -159,7 +159,7 @@ public class User implements UserDetails, CredentialsContainer {
Assert.notNull(authorities, "Cannot pass a null GrantedAuthority collection");
// Ensure array iteration order is predictable (as per
// UserDetails.getAuthorities() contract and SEC-717)
SortedSet<GrantedAuthority> sortedAuthorities = new TreeSet<GrantedAuthority>(
SortedSet<GrantedAuthority> sortedAuthorities = new TreeSet<>(
new AuthorityComparator());
for (GrantedAuthority grantedAuthority : authorities) {
@@ -367,7 +367,7 @@ public class User implements UserDetails, CredentialsContainer {
* additional attributes for this user)
*/
public UserBuilder roles(String... roles) {
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(
List<GrantedAuthority> authorities = new ArrayList<>(
roles.length);
for (String role : roles) {
Assert.isTrue(!role.startsWith("ROLE_"), role
@@ -400,7 +400,7 @@ public class User implements UserDetails, CredentialsContainer {
* @see #roles(String...)
*/
public UserBuilder authorities(Collection<? extends GrantedAuthority> authorities) {
this.authorities = new ArrayList<GrantedAuthority>(authorities);
this.authorities = new ArrayList<>(authorities);
return this;
}

View File

@@ -193,7 +193,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport
UserDetails user = users.get(0); // contains no GrantedAuthority[]
Set<GrantedAuthority> dbAuthsSet = new HashSet<GrantedAuthority>();
Set<GrantedAuthority> dbAuthsSet = new HashSet<>();
if (this.enableAuthorities) {
dbAuthsSet.addAll(loadUserAuthorities(user.getUsername()));
@@ -203,7 +203,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport
dbAuthsSet.addAll(loadGroupAuthorities(user.getUsername()));
}
List<GrantedAuthority> dbAuths = new ArrayList<GrantedAuthority>(dbAuthsSet);
List<GrantedAuthority> dbAuths = new ArrayList<>(dbAuthsSet);
addCustomAuthorities(user.getUsername(), dbAuths);

View File

@@ -33,7 +33,7 @@ public class UserAttribute {
// ~ Instance fields
// ================================================================================================
private List<GrantedAuthority> authorities = new Vector<GrantedAuthority>();
private List<GrantedAuthority> authorities = new Vector<>();
private String password;
private boolean enabled = true;
@@ -66,7 +66,7 @@ public class UserAttribute {
* @since 1.1
*/
public void setAuthoritiesAsString(List<String> authoritiesAsStrings) {
setAuthorities(new ArrayList<GrantedAuthority>(authoritiesAsStrings.size()));
setAuthorities(new ArrayList<>(authoritiesAsStrings.size()));
for (String authority : authoritiesAsStrings) {
addAuthority(new SimpleGrantedAuthority(authority));
}

View File

@@ -37,7 +37,7 @@ public class UserAttributeEditor extends PropertyEditorSupport {
String[] tokens = StringUtils.commaDelimitedListToStringArray(s);
UserAttribute userAttrib = new UserAttribute();
List<String> authoritiesAsStrings = new ArrayList<String>();
List<String> authoritiesAsStrings = new ArrayList<>();
for (int i = 0; i < tokens.length; i++) {
String currentToken = tokens[i].trim();

View File

@@ -95,7 +95,7 @@ public final class SecurityJackson2Modules {
* @return List of available security modules in classpath.
*/
public static List<Module> getModules(ClassLoader loader) {
List<Module> modules = new ArrayList<Module>();
List<Module> modules = new ArrayList<>();
for (String className : securityJackson2ModuleClasses) {
Module module = loadAndGetInstance(className, loader);
if (module != null) {

View File

@@ -43,7 +43,7 @@ class UnmodifiableSetDeserializer extends JsonDeserializer<Set> {
public Set deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
JsonNode node = mapper.readTree(jp);
Set<Object> resultSet = new HashSet<Object>();
Set<Object> resultSet = new HashSet<>();
if (node != null) {
if (node instanceof ArrayNode) {
ArrayNode arrayNode = (ArrayNode) node;

View File

@@ -48,7 +48,7 @@ import org.springframework.util.Assert;
public class InMemoryUserDetailsManager implements UserDetailsManager {
protected final Log logger = LogFactory.getLog(getClass());
private final Map<String, MutableUserDetails> users = new HashMap<String, MutableUserDetails>();
private final Map<String, MutableUserDetails> users = new HashMap<>();
private AuthenticationManager authenticationManager;