Polishing
This commit is contained in:
@@ -77,19 +77,17 @@ import org.springframework.util.StringUtils;
|
||||
@SuppressWarnings("serial")
|
||||
public final class ResolvableType implements Serializable {
|
||||
|
||||
private static ConcurrentReferenceHashMap<ResolvableType, ResolvableType> cache =
|
||||
new ConcurrentReferenceHashMap<ResolvableType, ResolvableType>();
|
||||
|
||||
|
||||
/**
|
||||
* {@code ResolvableType} returned when no value is available. {@code NONE} is used
|
||||
* in preference to {@code null} so that multiple method calls can be safely chained.
|
||||
*/
|
||||
public static final ResolvableType NONE = new ResolvableType(null, null, null, null);
|
||||
|
||||
|
||||
private static final ResolvableType[] EMPTY_TYPES_ARRAY = new ResolvableType[0];
|
||||
|
||||
private static final ConcurrentReferenceHashMap<ResolvableType, ResolvableType> cache =
|
||||
new ConcurrentReferenceHashMap<ResolvableType, ResolvableType>(256);
|
||||
|
||||
|
||||
/**
|
||||
* The underlying Java type being managed (only ever {@code null} for {@link #NONE}).
|
||||
@@ -1085,7 +1083,7 @@ public final class ResolvableType implements Serializable {
|
||||
* @see #forType(Type, ResolvableType)
|
||||
*/
|
||||
public static ResolvableType forType(Type type) {
|
||||
return forType(type, (VariableResolver) null);
|
||||
return forType(type, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
@@ -132,6 +132,15 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||
this(initialCapacity, DEFAULT_LOAD_FACTOR, concurrencyLevel, DEFAULT_REFERENCE_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code ConcurrentReferenceHashMap} instance.
|
||||
* @param initialCapacity the initial capacity of the map
|
||||
* @param referenceType the reference type used for entries (soft or weak)
|
||||
*/
|
||||
public ConcurrentReferenceHashMap(int initialCapacity, ReferenceType referenceType) {
|
||||
this(initialCapacity, DEFAULT_LOAD_FACTOR, DEFAULT_CONCURRENCY_LEVEL, referenceType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code ConcurrentReferenceHashMap} instance.
|
||||
* @param initialCapacity the initial capacity of the map
|
||||
@@ -151,7 +160,7 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||
* table exceeds this value, resize will be attempted.
|
||||
* @param concurrencyLevel the expected number of threads that will concurrently
|
||||
* write to the map
|
||||
* @param referenceType the reference type used for entries
|
||||
* @param referenceType the reference type used for entries (soft or weak)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel,
|
||||
@@ -165,10 +174,10 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||
this.shift = calculateShift(concurrencyLevel, MAXIMUM_CONCURRENCY_LEVEL);
|
||||
int size = 1 << this.shift;
|
||||
this.referenceType = referenceType;
|
||||
int roundedUpSegmentCapactity = (int) ((initialCapacity + size - 1L) / size);
|
||||
int roundedUpSegmentCapacity = (int) ((initialCapacity + size - 1L) / size);
|
||||
this.segments = (Segment[]) Array.newInstance(Segment.class, size);
|
||||
for (int i = 0; i < this.segments.length; i++) {
|
||||
this.segments[i] = new Segment(roundedUpSegmentCapactity);
|
||||
this.segments[i] = new Segment(roundedUpSegmentCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,8 +195,8 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method that returns the {@link ReferenceManager}. This method will be
|
||||
* called once for each {@link Segment}.
|
||||
* Factory method that returns the {@link ReferenceManager}.
|
||||
* This method will be called once for each {@link Segment}.
|
||||
* @return a new reference manager
|
||||
*/
|
||||
protected ReferenceManager createReferenceManager() {
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.io.Serializable;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Simple customizable helper class for creating threads. Provides various
|
||||
* bean properties, such as thread name prefix, thread priority, etc.
|
||||
* Simple customizable helper class for creating new {@link Thread} instances.
|
||||
* Provides various bean properties: thread name prefix, thread priority, etc.
|
||||
*
|
||||
* <p>Serves as base class for thread factories such as
|
||||
* {@link org.springframework.scheduling.concurrent.CustomizableThreadFactory}.
|
||||
@@ -41,7 +41,7 @@ public class CustomizableThreadCreator implements Serializable {
|
||||
|
||||
private ThreadGroup threadGroup;
|
||||
|
||||
private final AtomicInteger threadCount = new AtomicInteger();
|
||||
private final AtomicInteger threadCount = new AtomicInteger(0);
|
||||
|
||||
|
||||
/**
|
||||
@@ -95,11 +95,11 @@ public class CustomizableThreadCreator implements Serializable {
|
||||
/**
|
||||
* Set whether this factory is supposed to create daemon threads,
|
||||
* just executing as long as the application itself is running.
|
||||
* <p>Default is "false": Concrete factories usually support explicit
|
||||
* cancelling. Hence, if the application shuts down, Runnables will
|
||||
* by default finish their execution.
|
||||
* <p>Specify "true" for eager shutdown of threads which still
|
||||
* actively execute a Runnable.
|
||||
* <p>Default is "false": Concrete factories usually support explicit cancelling.
|
||||
* Hence, if the application shuts down, Runnables will by default finish their
|
||||
* execution.
|
||||
* <p>Specify "true" for eager shutdown of threads which still actively execute
|
||||
* a {@link Runnable} at the time that the application itself shuts down.
|
||||
* @see java.lang.Thread#setDaemon
|
||||
*/
|
||||
public void setDaemon(boolean daemon) {
|
||||
@@ -131,7 +131,7 @@ public class CustomizableThreadCreator implements Serializable {
|
||||
|
||||
/**
|
||||
* Return the thread group that threads should be created in
|
||||
* (or {@code null}) for the default group.
|
||||
* (or {@code null} for the default group).
|
||||
*/
|
||||
public ThreadGroup getThreadGroup() {
|
||||
return this.threadGroup;
|
||||
@@ -139,9 +139,9 @@ public class CustomizableThreadCreator implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* Template method for the creation of a Thread.
|
||||
* <p>Default implementation creates a new Thread for the given
|
||||
* Runnable, applying an appropriate thread name.
|
||||
* Template method for the creation of a new {@link Thread}.
|
||||
* <p>The default implementation creates a new Thread for the given
|
||||
* {@link Runnable}, applying an appropriate thread name.
|
||||
* @param runnable the Runnable to execute
|
||||
* @see #nextThreadName()
|
||||
*/
|
||||
@@ -153,10 +153,9 @@ public class CustomizableThreadCreator implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the thread name to use for a newly created thread.
|
||||
* <p>Default implementation returns the specified thread name prefix
|
||||
* with an increasing thread count appended: for example,
|
||||
* "SimpleAsyncTaskExecutor-0".
|
||||
* Return the thread name to use for a newly created {@link Thread}.
|
||||
* <p>The default implementation returns the specified thread name prefix
|
||||
* with an increasing thread count appended: e.g. "SimpleAsyncTaskExecutor-0".
|
||||
* @see #getThreadNamePrefix()
|
||||
*/
|
||||
protected String nextThreadName() {
|
||||
|
||||
@@ -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.
|
||||
@@ -44,8 +44,13 @@ import java.util.regex.Pattern;
|
||||
*/
|
||||
public abstract class ReflectionUtils {
|
||||
|
||||
/**
|
||||
* Pattern for detecting CGLIB-renamed methods.
|
||||
* @see #isCglibRenamedMethod
|
||||
*/
|
||||
private static final Pattern CGLIB_RENAMED_METHOD_PATTERN = Pattern.compile("CGLIB\\$(.+)\\$\\d+");
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to find a {@link Field field} on the supplied {@link Class} with the
|
||||
* supplied {@code name}. Searches all superclasses up to {@link Object}.
|
||||
@@ -373,19 +378,21 @@ public abstract class ReflectionUtils {
|
||||
* Determine whether the given method is originally declared by {@link java.lang.Object}.
|
||||
*/
|
||||
public static boolean isObjectMethod(Method method) {
|
||||
if (method == null) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
Object.class.getDeclaredMethod(method.getName(), method.getParameterTypes());
|
||||
return true;
|
||||
} catch (SecurityException ex) {
|
||||
return false;
|
||||
} catch (NoSuchMethodException ex) {
|
||||
}
|
||||
catch (Exception ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the given method is a CGLIB 'renamed' method, following
|
||||
* the pattern "CGLIB$methodName$0".
|
||||
* Determine whether the given method is a CGLIB 'renamed' method,
|
||||
* following the pattern "CGLIB$methodName$0".
|
||||
* @param renamedMethod the method to check
|
||||
* @see org.springframework.cglib.proxy.Enhancer#rename
|
||||
*/
|
||||
@@ -514,15 +521,15 @@ public abstract class ReflectionUtils {
|
||||
public void doWith(Method method) {
|
||||
boolean knownSignature = false;
|
||||
Method methodBeingOverriddenWithCovariantReturnType = null;
|
||||
|
||||
for (Method existingMethod : methods) {
|
||||
if (method.getName().equals(existingMethod.getName()) &&
|
||||
Arrays.equals(method.getParameterTypes(), existingMethod.getParameterTypes())) {
|
||||
// is this a covariant return type situation?
|
||||
// Is this a covariant return type situation?
|
||||
if (existingMethod.getReturnType() != method.getReturnType() &&
|
||||
existingMethod.getReturnType().isAssignableFrom(method.getReturnType())) {
|
||||
methodBeingOverriddenWithCovariantReturnType = existingMethod;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
knownSignature = true;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user