Polishing (includes varargs for selected String array setters)

This commit is contained in:
Juergen Hoeller
2014-08-09 00:19:56 +02:00
parent d61353db51
commit c08ded769a
34 changed files with 376 additions and 390 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.
@@ -55,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;
}
@@ -81,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) {
@@ -132,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.
@@ -26,32 +26,32 @@ import org.springframework.util.Assert;
* Base class for cache operations.
*
* @author Costin Leau
* @since 3.1
*/
public abstract class CacheOperation {
private Set<String> cacheNames = Collections.emptySet();
private String name = "";
private String condition = "";
private Set<String> cacheNames = Collections.emptySet();
private String key = "";
private String name = "";
private String keyGenerator = "";
private String cacheManager = "";
private String cacheResolver = "";
private String condition = "";
public Set<String> getCacheNames() {
return cacheNames;
}
public String getCondition() {
return 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) {
@@ -59,17 +59,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) {
@@ -77,11 +76,47 @@ 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 setKeyGenerator(String keyGenerator) {
Assert.notNull(keyGenerator);
this.keyGenerator = keyGenerator;
}
public String getKeyGenerator() {
return this.keyGenerator;
}
public void setCacheManager(String cacheManager) {
Assert.notNull(cacheManager);
this.cacheManager = cacheManager;
}
public String getCacheManager() {
return this.cacheManager;
}
public void setCacheResolver(String cacheResolver) {
Assert.notNull(cacheManager);
this.cacheResolver = cacheResolver;
}
public String getCacheResolver() {
return this.cacheResolver;
}
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()
@@ -116,17 +151,15 @@ 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("' | keyGenerator='").append(this.keyGenerator);
result.append("' | cacheManager='").append(this.cacheManager);
result.append("' | cacheResolver='").append(this.cacheResolver);
result.append("' | condition='").append(this.condition).append("'");
return result;
}
}

View File

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

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