Polishing

This commit is contained in:
Juergen Hoeller
2014-07-01 20:30:31 +02:00
parent ec4e6e0b0e
commit b7984f21d8
4 changed files with 35 additions and 27 deletions

View File

@@ -92,12 +92,12 @@ public class BeanFactoryAnnotationUtils {
return matchingBean;
}
else if (bf.containsBean(qualifier)) {
// Fallback: target bean at least found by bean name.
// Fallback: target bean at least found by bean name - probably a manually registered singleton.
return bf.getBean(qualifier, beanType);
}
else {
throw new NoSuchBeanDefinitionException(qualifier, "No matching " + beanType.getSimpleName() +
" bean found for qualifier '" + qualifier + "' - neither qualifier " + "match nor bean name match!");
" bean found for qualifier '" + qualifier + "' - neither qualifier match nor bean name match!");
}
}
@@ -133,7 +133,7 @@ public class BeanFactoryAnnotationUtils {
}
}
catch (NoSuchBeanDefinitionException ex) {
// ignore - can't compare qualifiers for a manually registered singleton object
// Ignore - can't compare qualifiers for a manually registered singleton object
}
}
return false;

View File

@@ -46,19 +46,22 @@ public class GuavaCache implements Cache {
/**
* Create a {@link GuavaCache} instance.
* Create a {@link GuavaCache} instance with the specified name and the
* given internal {@link com.google.common.cache.Cache} to use.
* @param name the name of the cache
* @param cache backing Guava Cache instance
* @param cache the backing Guava Cache instance
*/
public GuavaCache(String name, com.google.common.cache.Cache<Object, Object> cache) {
this(name, cache, true);
}
/**
* Create a {@link GuavaCache} instance.
* Create a {@link GuavaCache} instance with the specified name and the
* given internal {@link com.google.common.cache.Cache} to use.
* @param name the name of the cache
* @param cache backing Guava Cache instance
* @param allowNullValues whether to accept and convert null values for this cache
* @param cache the backing Guava Cache instance
* @param allowNullValues whether to accept and convert {@code null}
* values for this cache
*/
public GuavaCache(String name, com.google.common.cache.Cache<Object, Object> cache, boolean allowNullValues) {
Assert.notNull(name, "Name must not be null");
@@ -110,8 +113,9 @@ public class GuavaCache implements Cache {
PutIfAbsentCallable callable = new PutIfAbsentCallable(value);
Object result = this.cache.get(key, callable);
return (callable.called ? null : toWrapper(result));
} catch (ExecutionException e) {
throw new IllegalArgumentException(e);
}
catch (ExecutionException ex) {
throw new IllegalStateException(ex);
}
}
@@ -161,19 +165,21 @@ public class GuavaCache implements Cache {
private static class NullHolder implements Serializable {
}
private class PutIfAbsentCallable implements Callable<Object> {
private boolean called;
private final Object value;
private PutIfAbsentCallable(Object value) {
private boolean called;
public PutIfAbsentCallable(Object value) {
this.value = value;
}
@Override
public Object call() throws Exception {
called = true;
return toStoreValue(value);
this.called = true;
return toStoreValue(this.value);
}
}

View File

@@ -81,8 +81,8 @@ public interface Cache {
void put(Object key, Object value);
/**
* Atomically associate the specified value with the specified key in this cache if
* it is not set already.
* Atomically associate the specified value with the specified key in this cache
* if it is not set already.
* <p>This is equivalent to:
* <pre><code>
* Object existingValue = cache.get(key);
@@ -93,17 +93,18 @@ public interface Cache {
* return existingValue;
* }
* </code></pre>
* except that the action is performed atomically. While all known providers are
* able to perform the put atomically, the returned value may be retrieved after
* the attempt to put (i.e. in a non atomic way). Check the documentation of
* the native cache implementation that you are using for more details.
* except that the action is performed atomically. While all out-of-the-box
* {@link CacheManager} implementations are able to perform the put atomically,
* the operation may also be implemented in two steps, e.g. with a check for
* presence and a subsequent put, in a non-atomic way. Check the documentation
* of the native cache implementation that you are using for more details.
* @param key the key with which the specified value is to be associated
* @param value the value to be associated with the specified key
* @return the value to which this cache maps the specified key (which may
* be {@code null} itself), or also {@code null} if the cache did not contain
* any mapping for that key prior to this call. Returning {@code null} is
* therefore an indicator that the given {@code value} has been associated
* with the key
* @return the value to which this cache maps the specified key (which may be
* {@code null} itself), or also {@code null} if the cache did not contain any
* mapping for that key prior to this call. Returning {@code null} is therefore
* an indicator that the given {@code value} has been associated with the key.
* @since 4.1
*/
ValueWrapper putIfAbsent(Object key, Object value);

View File

@@ -63,7 +63,8 @@ public class ConcurrentMapCache implements Cache {
/**
* Create a new ConcurrentMapCache with the specified name.
* @param name the name of the cache
* @param allowNullValues whether to accept and convert null values for this cache
* @param allowNullValues whether to accept and convert {@code null}
* values for this cache
*/
public ConcurrentMapCache(String name, boolean allowNullValues) {
this(name, new ConcurrentHashMap<Object, Object>(256), allowNullValues);
@@ -71,7 +72,7 @@ public class ConcurrentMapCache implements Cache {
/**
* Create a new ConcurrentMapCache with the specified name and the
* given internal ConcurrentMap to use.
* given internal {@link ConcurrentMap} to use.
* @param name the name of the cache
* @param store the ConcurrentMap to use as an internal store
* @param allowNullValues whether to allow {@code null} values