Polishing (includes varargs for selected setters)

This commit is contained in:
Juergen Hoeller
2014-08-11 22:12:26 +02:00
parent 6639320e8e
commit 36918d6bb7
44 changed files with 482 additions and 490 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@ import org.springframework.util.ObjectUtils;
@SuppressWarnings("serial")
public class SpringCacheAnnotationParser implements CacheAnnotationParser, Serializable {
@Override
public Collection<CacheOperation> parseCacheAnnotations(AnnotatedElement ae) {
Collection<CacheOperation> ops = null;
@@ -54,24 +55,25 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
Collection<CacheEvict> evicts = getAnnotations(ae, CacheEvict.class);
if (evicts != null) {
ops = lazyInit(ops);
for (CacheEvict e : evicts) {
ops.add(parseEvictAnnotation(ae, e));
for (CacheEvict evict : evicts) {
ops.add(parseEvictAnnotation(ae, evict));
}
}
Collection<CachePut> updates = getAnnotations(ae, CachePut.class);
if (updates != null) {
Collection<CachePut> puts = getAnnotations(ae, CachePut.class);
if (puts != null) {
ops = lazyInit(ops);
for (CachePut p : updates) {
ops.add(parseUpdateAnnotation(ae, p));
for (CachePut put : puts) {
ops.add(parsePutAnnotation(ae, put));
}
}
Collection<Caching> caching = getAnnotations(ae, Caching.class);
if (caching != null) {
Collection<Caching> cachings = getAnnotations(ae, Caching.class);
if (cachings != null) {
ops = lazyInit(ops);
for (Caching c : caching) {
ops.addAll(parseCachingAnnotation(ae, c));
for (Caching caching : cachings) {
ops.addAll(parseCachingAnnotation(ae, caching));
}
}
return ops;
}
@@ -80,34 +82,34 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
}
CacheableOperation parseCacheableAnnotation(AnnotatedElement ae, Cacheable caching) {
CacheableOperation cuo = new CacheableOperation();
cuo.setCacheNames(caching.value());
cuo.setCondition(caching.condition());
cuo.setUnless(caching.unless());
cuo.setKey(caching.key());
cuo.setName(ae.toString());
return cuo;
CacheableOperation op = new CacheableOperation();
op.setCacheNames(caching.value());
op.setCondition(caching.condition());
op.setUnless(caching.unless());
op.setKey(caching.key());
op.setName(ae.toString());
return op;
}
CacheEvictOperation parseEvictAnnotation(AnnotatedElement ae, CacheEvict caching) {
CacheEvictOperation ceo = new CacheEvictOperation();
ceo.setCacheNames(caching.value());
ceo.setCondition(caching.condition());
ceo.setKey(caching.key());
ceo.setCacheWide(caching.allEntries());
ceo.setBeforeInvocation(caching.beforeInvocation());
ceo.setName(ae.toString());
return ceo;
CacheEvictOperation op = new CacheEvictOperation();
op.setCacheNames(caching.value());
op.setCondition(caching.condition());
op.setKey(caching.key());
op.setCacheWide(caching.allEntries());
op.setBeforeInvocation(caching.beforeInvocation());
op.setName(ae.toString());
return op;
}
CacheOperation parseUpdateAnnotation(AnnotatedElement ae, CachePut caching) {
CachePutOperation cuo = new CachePutOperation();
cuo.setCacheNames(caching.value());
cuo.setCondition(caching.condition());
cuo.setUnless(caching.unless());
cuo.setKey(caching.key());
cuo.setName(ae.toString());
return cuo;
CacheOperation parsePutAnnotation(AnnotatedElement ae, CachePut caching) {
CachePutOperation op = new CachePutOperation();
op.setCacheNames(caching.value());
op.setCondition(caching.condition());
op.setUnless(caching.unless());
op.setKey(caching.key());
op.setName(ae.toString());
return op;
}
Collection<CacheOperation> parseCachingAnnotation(AnnotatedElement ae, Caching caching) {
@@ -131,7 +133,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
if (!ObjectUtils.isEmpty(updates)) {
ops = lazyInit(ops);
for (CachePut update : updates) {
ops.add(parseUpdateAnnotation(ae, update));
ops.add(parsePutAnnotation(ae, update));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,32 +23,29 @@ import java.util.Set;
import org.springframework.util.Assert;
/**
* Base class implementing {@link CacheOperation}.
* Base class for cache operations.
*
* @author Costin Leau
* @since 3.1
*/
public abstract class CacheOperation {
private Set<String> cacheNames = Collections.emptySet();
private String condition = "";
private String key = "";
private String name = "";
private Set<String> cacheNames = Collections.emptySet();
public Set<String> getCacheNames() {
return cacheNames;
}
private String key = "";
public String getCondition() {
return condition;
}
private String condition = "";
public String getKey() {
return key;
public void setName(String name) {
Assert.hasText(name);
this.name = name;
}
public String getName() {
return name;
return this.name;
}
public void setCacheName(String cacheName) {
@@ -56,17 +53,16 @@ public abstract class CacheOperation {
this.cacheNames = Collections.singleton(cacheName);
}
public void setCacheNames(String[] cacheNames) {
Assert.notEmpty(cacheNames);
public void setCacheNames(String... cacheNames) {
this.cacheNames = new LinkedHashSet<String>(cacheNames.length);
for (String string : cacheNames) {
this.cacheNames.add(string);
for (String cacheName : cacheNames) {
Assert.hasText(cacheName, "Cache name must be non-null if specified");
this.cacheNames.add(cacheName);
}
}
public void setCondition(String condition) {
Assert.notNull(condition);
this.condition = condition;
public Set<String> getCacheNames() {
return this.cacheNames;
}
public void setKey(String key) {
@@ -74,11 +70,20 @@ public abstract class CacheOperation {
this.key = key;
}
public void setName(String name) {
Assert.hasText(name);
this.name = name;
public String getKey() {
return this.key;
}
public void setCondition(String condition) {
Assert.notNull(condition);
this.condition = condition;
}
public String getCondition() {
return this.condition;
}
/**
* This implementation compares the {@code toString()} results.
* @see #toString()
@@ -113,17 +118,12 @@ public abstract class CacheOperation {
* <p>Available to subclasses, for inclusion in their {@code toString()} result.
*/
protected StringBuilder getOperationDescription() {
StringBuilder result = new StringBuilder();
result.append(getClass().getSimpleName());
result.append("[");
result.append(this.name);
result.append("] caches=");
result.append(this.cacheNames);
result.append(" | key='");
result.append(this.key);
result.append("' | condition='");
result.append(this.condition);
result.append("'");
StringBuilder result = new StringBuilder(getClass().getSimpleName());
result.append("[").append(this.name);
result.append("] caches=").append(this.cacheNames);
result.append(" | key='").append(this.key);
result.append("' | condition='").append(this.condition).append("'");
return result;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -167,7 +167,7 @@ public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateCo
* Set the name-matching patterns for determining autowire candidates.
* @param autowireCandidatePatterns the patterns to match against
*/
public void setAutowireCandidatePatterns(String[] autowireCandidatePatterns) {
public void setAutowireCandidatePatterns(String... autowireCandidatePatterns) {
this.autowireCandidatePatterns = autowireCandidatePatterns;
}
@@ -224,7 +224,7 @@ public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateCo
AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
}
return this.registry.getBeanDefinitionCount() - beanCountAtScanStart;
return (this.registry.getBeanDefinitionCount() - beanCountAtScanStart);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -68,7 +68,7 @@ public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBean
* that bean is found in the {@code ignoredMethodsMappings} property.
* @see #setIgnoredMethodMappings(java.util.Properties)
*/
public void setIgnoredMethods(String[] ignoredMethodNames) {
public void setIgnoredMethods(String... ignoredMethodNames) {
this.ignoredMethods = new HashSet<String>(Arrays.asList(ignoredMethodNames));
}
@@ -81,7 +81,7 @@ public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBean
*/
public void setIgnoredMethodMappings(Properties mappings) {
this.ignoredMethodMappings = new HashMap<String, Set<String>>();
for (Enumeration en = mappings.keys(); en.hasMoreElements();) {
for (Enumeration<?> en = mappings.keys(); en.hasMoreElements();) {
String beanKey = (String) en.nextElement();
String[] methodNames = StringUtils.commaDelimitedListToStringArray(mappings.getProperty(beanKey));
this.ignoredMethodMappings.put(beanKey, new HashSet<String>(Arrays.asList(methodNames)));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ public class ManagedNotification {
/**
* Set a list of notification types.
*/
public void setNotificationTypes(String[] notificationTypes) {
public void setNotificationTypes(String... notificationTypes) {
this.notificationTypes = notificationTypes;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
@@ -66,7 +65,7 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
private final Map<String, Object> singletonObjects = new HashMap<String, Object>();
/** Cache of the types of nonshareable resources: bean name --> bean type */
private final Map<String, Class> resourceTypes = new HashMap<String, Class>();
private final Map<String, Class<?>> resourceTypes = new HashMap<String, Class<?>>();
public SimpleJndiBeanFactory() {
@@ -74,16 +73,6 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
}
/**
* Set a list of names of shareable JNDI resources,
* which this factory is allowed to cache once obtained.
* @param shareableResources the JNDI names
* (typically within the "java:comp/env/" namespace)
*/
public void setShareableResources(String[] shareableResources) {
this.shareableResources.addAll(Arrays.asList(shareableResources));
}
/**
* Add the name of a shareable JNDI resource,
* which this factory is allowed to cache once obtained.
@@ -94,6 +83,16 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
this.shareableResources.add(shareableResource);
}
/**
* Set a list of names of shareable JNDI resources,
* which this factory is allowed to cache once obtained.
* @param shareableResources the JNDI names
* (typically within the "java:comp/env/" namespace)
*/
public void setShareableResources(String... shareableResources) {
this.shareableResources.addAll(Arrays.asList(shareableResources));
}
//---------------------------------------------------------------------
// Implementation of BeanFactory interface
@@ -157,8 +156,8 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
return !this.shareableResources.contains(name);
}
public boolean isTypeMatch(String name, Class targetType) throws NoSuchBeanDefinitionException {
Class type = getType(name);
public boolean isTypeMatch(String name, Class<?> targetType) throws NoSuchBeanDefinitionException {
Class<?> type = getType(name);
return (targetType == null || (type != null && targetType.isAssignableFrom(type)));
}
@@ -196,7 +195,7 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
}
}
private Class doGetType(String name) throws NamingException {
private Class<?> doGetType(String name) throws NamingException {
if (isSingleton(name)) {
Object jndiObject = doGetSingleton(name, null);
return (jndiObject != null ? jndiObject.getClass() : null);
@@ -208,7 +207,7 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac
}
else {
Object jndiObject = lookup(name, null);
Class type = (jndiObject != null ? jndiObject.getClass() : null);
Class<?> type = (jndiObject != null ? jndiObject.getClass() : null);
this.resourceTypes.put(name, type);
return type;
}