[ISSUE#8485] (module-common) replace the type specification in this constructor call with the diamond operator ("<>") (#8554)

This commit is contained in:
david6969xin 2022-06-13 10:32:58 +08:00 committed by GitHub
parent 9e53f7c6ee
commit fa5fbd79e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 30 additions and 30 deletions

View File

@ -68,7 +68,7 @@ public final class ExecutorFactory {
public static ThreadPoolExecutor newCustomerThreadExecutor(final int coreThreads, final int maxThreads, public static ThreadPoolExecutor newCustomerThreadExecutor(final int coreThreads, final int maxThreads,
final long keepAliveTimeMs, final ThreadFactory threadFactory) { final long keepAliveTimeMs, final ThreadFactory threadFactory) {
return new ThreadPoolExecutor(coreThreads, maxThreads, keepAliveTimeMs, TimeUnit.MILLISECONDS, return new ThreadPoolExecutor(coreThreads, maxThreads, keepAliveTimeMs, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(), threadFactory); new LinkedBlockingQueue<>(), threadFactory);
} }
public static final class Managed { public static final class Managed {
@ -172,7 +172,7 @@ public final class ExecutorFactory {
public static ThreadPoolExecutor newCustomerThreadExecutor(final String group, final int coreThreads, public static ThreadPoolExecutor newCustomerThreadExecutor(final String group, final int coreThreads,
final int maxThreads, final long keepAliveTimeMs, final ThreadFactory threadFactory) { final int maxThreads, final long keepAliveTimeMs, final ThreadFactory threadFactory) {
ThreadPoolExecutor executor = new ThreadPoolExecutor(coreThreads, maxThreads, keepAliveTimeMs, ThreadPoolExecutor executor = new ThreadPoolExecutor(coreThreads, maxThreads, keepAliveTimeMs,
TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory); TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), threadFactory);
THREAD_POOL_MANAGER.register(DEFAULT_NAMESPACE, group, executor); THREAD_POOL_MANAGER.register(DEFAULT_NAMESPACE, group, executor);
return executor; return executor;
} }

View File

@ -44,7 +44,7 @@ public final class ThreadPoolManager {
private Map<String, Map<String, Set<ExecutorService>>> resourcesManager; private Map<String, Map<String, Set<ExecutorService>>> resourcesManager;
private Map<String, Object> lockers = new ConcurrentHashMap<String, Object>(8); private Map<String, Object> lockers = new ConcurrentHashMap<>(8);
private static final ThreadPoolManager INSTANCE = new ThreadPoolManager(); private static final ThreadPoolManager INSTANCE = new ThreadPoolManager();
@ -67,7 +67,7 @@ public final class ThreadPoolManager {
} }
private void init() { private void init() {
resourcesManager = new ConcurrentHashMap<String, Map<String, Set<ExecutorService>>>(8); resourcesManager = new ConcurrentHashMap<>(8);
} }
/** /**
@ -85,7 +85,7 @@ public final class ThreadPoolManager {
synchronized (monitor) { synchronized (monitor) {
Map<String, Set<ExecutorService>> map = resourcesManager.get(namespace); Map<String, Set<ExecutorService>> map = resourcesManager.get(namespace);
if (map == null) { if (map == null) {
map = new HashMap<String, Set<ExecutorService>>(8); map = new HashMap<>(8);
map.computeIfAbsent(group, key -> new HashSet<>()).add(executor); map.computeIfAbsent(group, key -> new HashSet<>()).add(executor);
resourcesManager.put(namespace, map); resourcesManager.put(namespace, map);
return; return;

View File

@ -36,9 +36,9 @@ public final class HttpClientBeanHolder {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientBeanHolder.class); private static final Logger LOGGER = LoggerFactory.getLogger(HttpClientBeanHolder.class);
private static final Map<String, NacosRestTemplate> SINGLETON_REST = new HashMap<String, NacosRestTemplate>(10); private static final Map<String, NacosRestTemplate> SINGLETON_REST = new HashMap<>(10);
private static final Map<String, NacosAsyncRestTemplate> SINGLETON_ASYNC_REST = new HashMap<String, NacosAsyncRestTemplate>( private static final Map<String, NacosAsyncRestTemplate> SINGLETON_ASYNC_REST = new HashMap<>(
10); 10);
private static final AtomicBoolean ALREADY_SHUTDOWN = new AtomicBoolean(false); private static final AtomicBoolean ALREADY_SHUTDOWN = new AtomicBoolean(false);

View File

@ -114,7 +114,7 @@ public final class HttpUtils {
if (body == null || body.isEmpty()) { if (body == null || body.isEmpty()) {
return; return;
} }
List<NameValuePair> params = new ArrayList<NameValuePair>(body.size()); List<NameValuePair> params = new ArrayList<>(body.size());
for (Map.Entry<String, String> entry : body.entrySet()) { for (Map.Entry<String, String> entry : body.entrySet()) {
params.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
} }
@ -176,7 +176,7 @@ public final class HttpUtils {
* @throws Exception exception * @throws Exception exception
*/ */
public static Map<String, String> translateParameterMap(Map<String, String[]> parameterMap) throws Exception { public static Map<String, String> translateParameterMap(Map<String, String[]> parameterMap) throws Exception {
Map<String, String> map = new HashMap<String, String>(16); Map<String, String> map = new HashMap<>(16);
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) { for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
map.put(entry.getKey(), entry.getValue()[0]); map.put(entry.getKey(), entry.getValue()[0]);
} }

View File

@ -49,7 +49,7 @@ public class NacosRestTemplate extends AbstractNacosRestTemplate {
private final HttpClientRequest requestClient; private final HttpClientRequest requestClient;
private final List<HttpClientRequestInterceptor> interceptors = new ArrayList<HttpClientRequestInterceptor>(); private final List<HttpClientRequestInterceptor> interceptors = new ArrayList<>();
public NacosRestTemplate(Logger logger, HttpClientRequest requestClient) { public NacosRestTemplate(Logger logger, HttpClientRequest requestClient) {
super(logger); super(logger);

View File

@ -49,7 +49,7 @@ public abstract class AbstractResponseHandler<T> implements ResponseHandler<T> {
private HttpRestResult<T> handleError(HttpClientResponse response) throws Exception { private HttpRestResult<T> handleError(HttpClientResponse response) throws Exception {
Header headers = response.getHeaders(); Header headers = response.getHeaders();
String message = IoUtils.toString(response.getBody(), headers.getCharset()); String message = IoUtils.toString(response.getBody(), headers.getCharset());
return new HttpRestResult<T>(headers, response.getStatusCode(), null, message); return new HttpRestResult<>(headers, response.getStatusCode(), null, message);
} }
/** /**

View File

@ -37,6 +37,6 @@ public class BeanResponseHandler<T> extends AbstractResponseHandler<T> {
final Header headers = response.getHeaders(); final Header headers = response.getHeaders();
InputStream body = response.getBody(); InputStream body = response.getBody();
T extractBody = JacksonUtils.toObj(body, responseType); T extractBody = JacksonUtils.toObj(body, responseType);
return new HttpRestResult<T>(headers, response.getStatusCode(), extractBody, null); return new HttpRestResult<>(headers, response.getStatusCode(), extractBody, null);
} }
} }

View File

@ -44,7 +44,7 @@ public class RestResultResponseHandler<T> extends AbstractResponseHandler<T> {
} }
private static <T> HttpRestResult<T> convert(RestResult<T> restResult) { private static <T> HttpRestResult<T> convert(RestResult<T> restResult) {
HttpRestResult<T> httpRestResult = new HttpRestResult<T>(); HttpRestResult<T> httpRestResult = new HttpRestResult<>();
httpRestResult.setCode(restResult.getCode()); httpRestResult.setCode(restResult.getCode());
httpRestResult.setData(restResult.getData()); httpRestResult.setData(restResult.getData());
httpRestResult.setMessage(restResult.getMessage()); httpRestResult.setMessage(restResult.getMessage());

View File

@ -34,6 +34,6 @@ public class StringResponseHandler extends AbstractResponseHandler<String> {
public HttpRestResult<String> convertResult(HttpClientResponse response, Type responseType) throws Exception { public HttpRestResult<String> convertResult(HttpClientResponse response, Type responseType) throws Exception {
final Header headers = response.getHeaders(); final Header headers = response.getHeaders();
String extractBody = IoUtils.toString(response.getBody(), headers.getCharset()); String extractBody = IoUtils.toString(response.getBody(), headers.getCharset());
return new HttpRestResult<String>(headers, response.getStatusCode(), extractBody, null); return new HttpRestResult<>(headers, response.getStatusCode(), extractBody, null);
} }
} }

View File

@ -45,8 +45,8 @@ public class Header {
private static final String DEFAULT_ENCODING = "gzip"; private static final String DEFAULT_ENCODING = "gzip";
private Header() { private Header() {
header = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER); header = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
originalResponseHeader = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER); originalResponseHeader = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
addParam(HttpHeaderConsts.CONTENT_TYPE, MediaType.APPLICATION_JSON); addParam(HttpHeaderConsts.CONTENT_TYPE, MediaType.APPLICATION_JSON);
addParam(HttpHeaderConsts.ACCEPT_CHARSET, DEFAULT_CHARSET); addParam(HttpHeaderConsts.ACCEPT_CHARSET, DEFAULT_CHARSET);
//addParam(HttpHeaderConsts.ACCEPT_ENCODING, DEFAULT_ENCODING); //addParam(HttpHeaderConsts.ACCEPT_ENCODING, DEFAULT_ENCODING);
@ -99,7 +99,7 @@ public class Header {
* @return KV string list * @return KV string list
*/ */
public List<String> toList() { public List<String> toList() {
List<String> list = new ArrayList<String>(header.size() * 2); List<String> list = new ArrayList<>(header.size() * 2);
Iterator<Map.Entry<String, String>> iterator = iterator(); Iterator<Map.Entry<String, String>> iterator = iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next(); Map.Entry<String, String> entry = iterator.next();

View File

@ -41,7 +41,7 @@ public class Query {
private static final String DEFAULT_ENC = "UTF-8"; private static final String DEFAULT_ENC = "UTF-8";
public Query() { public Query() {
params = new LinkedHashMap<String, Object>(); params = new LinkedHashMap<>();
} }
public static Query newInstance() { public static Query newInstance() {

View File

@ -86,7 +86,7 @@ public class RestResult<T> implements Serializable {
} }
public static <T> ResResultBuilder<T> builder() { public static <T> ResResultBuilder<T> builder() {
return new ResResultBuilder<T>(); return new ResResultBuilder<>();
} }
public static final class ResResultBuilder<T> { public static final class ResResultBuilder<T> {
@ -121,7 +121,7 @@ public class RestResult<T> implements Serializable {
* @return result * @return result
*/ */
public RestResult<T> build() { public RestResult<T> build() {
RestResult<T> restResult = new RestResult<T>(); RestResult<T> restResult = new RestResult<>();
restResult.setCode(code); restResult.setCode(code);
restResult.setMessage(errMsg); restResult.setMessage(errMsg);
restResult.setData(data); restResult.setData(data);

View File

@ -47,7 +47,7 @@ public class DefaultSharePublisher extends DefaultPublisher implements ShardedEv
try { try {
Set<Subscriber> sets = subMappings.get(subSlowEventType); Set<Subscriber> sets = subMappings.get(subSlowEventType);
if (sets == null) { if (sets == null) {
Set<Subscriber> newSet = new ConcurrentHashSet<Subscriber>(); Set<Subscriber> newSet = new ConcurrentHashSet<>();
newSet.add(subscriber); newSet.add(subscriber);
subMappings.put(subSlowEventType, newSet); subMappings.put(subSlowEventType, newSet);
return; return;

View File

@ -30,7 +30,7 @@ import java.util.concurrent.ConcurrentHashMap;
*/ */
public class NacosServiceLoader { public class NacosServiceLoader {
private static final Map<Class<?>, Collection<Class<?>>> SERVICES = new ConcurrentHashMap<Class<?>, Collection<Class<?>>>(); private static final Map<Class<?>, Collection<Class<?>>> SERVICES = new ConcurrentHashMap<>();
/** /**
* Load service. * Load service.
@ -45,7 +45,7 @@ public class NacosServiceLoader {
if (SERVICES.containsKey(service)) { if (SERVICES.containsKey(service)) {
return newServiceInstances(service); return newServiceInstances(service);
} }
Collection<T> result = new LinkedHashSet<T>(); Collection<T> result = new LinkedHashSet<>();
for (T each : ServiceLoader.load(service)) { for (T each : ServiceLoader.load(service)) {
result.add(each); result.add(each);
cacheServiceClass(service, each); cacheServiceClass(service, each);
@ -55,7 +55,7 @@ public class NacosServiceLoader {
private static <T> void cacheServiceClass(final Class<T> service, final T instance) { private static <T> void cacheServiceClass(final Class<T> service, final T instance) {
if (!SERVICES.containsKey(service)) { if (!SERVICES.containsKey(service)) {
SERVICES.put(service, new LinkedHashSet<Class<?>>()); SERVICES.put(service, new LinkedHashSet<>());
} }
SERVICES.get(service).add(instance.getClass()); SERVICES.get(service).add(instance.getClass());
} }
@ -73,7 +73,7 @@ public class NacosServiceLoader {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static <T> Collection<T> newServiceInstancesFromCache(Class<T> service) { private static <T> Collection<T> newServiceInstancesFromCache(Class<T> service) {
Collection<T> result = new LinkedHashSet<T>(); Collection<T> result = new LinkedHashSet<>();
for (Class<?> each : SERVICES.get(service)) { for (Class<?> each : SERVICES.get(service)) {
result.add((T) newServiceInstance(each)); result.add((T) newServiceInstance(each));
} }

View File

@ -104,7 +104,7 @@ public class NacosDelayTaskExecuteEngine extends AbstractNacosTaskExecuteEngine<
@Override @Override
public Collection<Object> getAllTaskKeys() { public Collection<Object> getAllTaskKeys() {
Collection<Object> keys = new HashSet<Object>(); Collection<Object> keys = new HashSet<>();
lock.lock(); lock.lock();
try { try {
keys.addAll(tasks.keySet()); keys.addAll(tasks.keySet());

View File

@ -54,7 +54,7 @@ public final class TaskExecuteWorker implements NacosTaskProcessor, Closeable {
public TaskExecuteWorker(final String name, final int mod, final int total, final Logger logger) { public TaskExecuteWorker(final String name, final int mod, final int total, final Logger logger) {
this.name = name + "_" + mod + "%" + total; this.name = name + "_" + mod + "%" + total;
this.queue = new ArrayBlockingQueue<Runnable>(QUEUE_CAPACITY); this.queue = new ArrayBlockingQueue<>(QUEUE_CAPACITY);
this.closed = new AtomicBoolean(false); this.closed = new AtomicBoolean(false);
this.log = null == logger ? LoggerFactory.getLogger(TaskExecuteWorker.class) : logger; this.log = null == logger ? LoggerFactory.getLogger(TaskExecuteWorker.class) : logger;
new InnerWorker(name).start(); new InnerWorker(name).start();

View File

@ -31,7 +31,7 @@ public class ConcurrentHashSet<E> extends AbstractSet<E> {
public ConcurrentHashSet() { public ConcurrentHashSet() {
super(); super();
map = new ConcurrentHashMap<E, Boolean>(); map = new ConcurrentHashMap<>();
} }
@Override @Override

View File

@ -149,7 +149,7 @@ public class IoUtils {
*/ */
public static List<String> readLines(Reader input) throws IOException { public static List<String> readLines(Reader input) throws IOException {
BufferedReader reader = toBufferedReader(input); BufferedReader reader = toBufferedReader(input);
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
String line = null; String line = null;
for (; ; ) { for (; ; ) {
line = reader.readLine(); line = reader.readLine();

View File

@ -28,7 +28,7 @@ public class Observable {
private transient boolean changed = false; private transient boolean changed = false;
private transient Set<Observer> obs = new ConcurrentHashSet<Observer>(); private transient Set<Observer> obs = new ConcurrentHashSet<>();
private volatile int observerCnt = 0; private volatile int observerCnt = 0;