提交 fb7ae010 编写于 作者: J Juergen Hoeller

Avoid unnecessary generics on emptyMap/Set/List

上级 a6b0b6e2
......@@ -555,7 +555,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
public Collection<CacheOperationContext> get(Class<? extends CacheOperation> operationClass) {
Collection<CacheOperationContext> result = this.contexts.get(operationClass);
return (result != null ? result : Collections.<CacheOperationContext>emptyList());
return (result != null ? result : Collections.emptyList());
}
public boolean isSynchronized() {
......
......@@ -134,7 +134,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean
*/
public List<TriggerTask> getTriggerTaskList() {
return (this.triggerTasks != null? Collections.unmodifiableList(this.triggerTasks) :
Collections.<TriggerTask>emptyList());
Collections.emptyList());
}
/**
......@@ -165,7 +165,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean
*/
public List<CronTask> getCronTaskList() {
return (this.cronTasks != null ? Collections.unmodifiableList(this.cronTasks) :
Collections.<CronTask>emptyList());
Collections.emptyList());
}
/**
......@@ -196,7 +196,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean
*/
public List<IntervalTask> getFixedRateTaskList() {
return (this.fixedRateTasks != null ? Collections.unmodifiableList(this.fixedRateTasks) :
Collections.<IntervalTask>emptyList());
Collections.emptyList());
}
/**
......@@ -227,7 +227,7 @@ public class ScheduledTaskRegistrar implements InitializingBean, DisposableBean
*/
public List<IntervalTask> getFixedDelayTaskList() {
return (this.fixedDelayTasks != null ? Collections.unmodifiableList(this.fixedDelayTasks) :
Collections.<IntervalTask>emptyList());
Collections.emptyList());
}
......
......@@ -50,13 +50,10 @@ public abstract class Conventions {
* when searching for the 'primary' interface of a proxy.
*/
private static final Set<Class<?>> IGNORED_INTERFACES;
static {
IGNORED_INTERFACES = Collections.unmodifiableSet(
new HashSet<>(Arrays.<Class<?>>asList(
Serializable.class,
Externalizable.class,
Cloneable.class,
Comparable.class)));
IGNORED_INTERFACES = Collections.unmodifiableSet(new HashSet<>(
Arrays.asList(Serializable.class, Externalizable.class, Cloneable.class, Comparable.class)));
}
......
......@@ -101,7 +101,7 @@ public class JOptCommandLinePropertySource extends CommandLinePropertySource<Opt
stringArgValues.add(argValue instanceof String ? (String) argValue : argValue.toString());
}
if (stringArgValues.isEmpty()) {
return (this.source.has(name) ? Collections.<String>emptyList() : null);
return (this.source.has(name) ? Collections.emptyList() : null);
}
return Collections.unmodifiableList(stringArgValues);
}
......@@ -114,7 +114,7 @@ public class JOptCommandLinePropertySource extends CommandLinePropertySource<Opt
Assert.isInstanceOf(String.class, argValue, "Argument values must be of type String");
stringArgValues.add((String) argValue);
}
return (stringArgValues.isEmpty() ? Collections.<String>emptyList() :
return (stringArgValues.isEmpty() ? Collections.emptyList() :
Collections.unmodifiableList(stringArgValues));
}
......
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
......@@ -54,8 +54,8 @@ public class InstanceFilter<T> {
public InstanceFilter(Collection<? extends T> includes,
Collection<? extends T> excludes, boolean matchIfEmpty) {
this.includes = includes != null ? includes : Collections.<T>emptyList();
this.excludes = excludes != null ? excludes : Collections.<T>emptyList();
this.includes = (includes != null ? includes : Collections.emptyList());
this.excludes = (excludes != null ? excludes : Collections.emptyList());
this.matchIfEmpty = matchIfEmpty;
}
......@@ -64,7 +64,7 @@ public class InstanceFilter<T> {
* Determine if the specified {code instance} matches this filter.
*/
public boolean match(T instance) {
Assert.notNull(instance, "The instance to match is mandatory");
Assert.notNull(instance, "Instance to match must not be null");
boolean includesSet = !this.includes.isEmpty();
boolean excludesSet = !this.excludes.isEmpty();
......@@ -74,11 +74,9 @@ public class InstanceFilter<T> {
boolean matchIncludes = match(instance, this.includes);
boolean matchExcludes = match(instance, this.excludes);
if (!includesSet) {
return !matchExcludes;
}
if (!excludesSet) {
return matchIncludes;
}
......
......@@ -120,7 +120,7 @@ public class MimeType implements Comparable<MimeType>, Serializable {
* @throws IllegalArgumentException if any of the parameters contains illegal characters
*/
public MimeType(String type, String subtype) {
this(type, subtype, Collections.<String, String>emptyMap());
this(type, subtype, Collections.emptyMap());
}
/**
......
......@@ -87,7 +87,7 @@ public class SimpleNamespaceContext implements NamespaceContext {
}
else {
Set<String> prefixes = this.namespaceUriToPrefixes.get(namespaceUri);
return (prefixes != null ? Collections.unmodifiableSet(prefixes) : Collections.<String>emptySet());
return (prefixes != null ? Collections.unmodifiableSet(prefixes) : Collections.emptySet());
}
}
......
......@@ -183,7 +183,7 @@ public class ExpressionState {
public void enterScope() {
ensureVariableScopesInitialized();
this.variableScopes.push(new VariableScope(Collections.<String,Object>emptyMap()));
this.variableScopes.push(new VariableScope(Collections.emptyMap()));
this.scopeRootObjects.push(getActiveContextObject());
}
......
......@@ -73,7 +73,7 @@ public class DestinationPatternsMessageCondition extends AbstractMessageConditio
private static List<String> asList(String... patterns) {
return (patterns != null ? Arrays.asList(patterns) : Collections.<String>emptyList());
return (patterns != null ? Arrays.asList(patterns) : Collections.emptyList());
}
private static Set<String> prependLeadingSlash(Collection<String> patterns, PathMatcher pathMatcher) {
......
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
......@@ -84,7 +84,7 @@ public abstract class AbstractBrokerMessageHandler
public AbstractBrokerMessageHandler(SubscribableChannel inboundChannel, MessageChannel outboundChannel,
SubscribableChannel brokerChannel) {
this(inboundChannel, outboundChannel, brokerChannel, Collections.<String>emptyList());
this(inboundChannel, outboundChannel, brokerChannel, Collections.emptyList());
}
/**
......@@ -105,7 +105,7 @@ public abstract class AbstractBrokerMessageHandler
this.clientOutboundChannel = outboundChannel;
this.brokerChannel = brokerChannel;
destinationPrefixes = (destinationPrefixes != null) ? destinationPrefixes : Collections.<String>emptyList();
destinationPrefixes = (destinationPrefixes != null) ? destinationPrefixes : Collections.emptyList();
this.destinationPrefixes = Collections.unmodifiableCollection(destinationPrefixes);
}
......
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 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.
......@@ -50,8 +50,8 @@ public abstract class AbstractBrokerRegistration {
this.clientInboundChannel = clientInboundChannel;
this.clientOutboundChannel = clientOutboundChannel;
this.destinationPrefixes = (destinationPrefixes != null)
? Arrays.<String>asList(destinationPrefixes) : Collections.<String>emptyList();
this.destinationPrefixes = (destinationPrefixes != null ?
Arrays.asList(destinationPrefixes) : Collections.emptyList());
}
......@@ -67,6 +67,7 @@ public abstract class AbstractBrokerRegistration {
return this.destinationPrefixes;
}
protected abstract AbstractBrokerMessageHandler getMessageHandler(SubscribableChannel brokerChannel);
}
......@@ -182,7 +182,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
Map<String, List<String>> getNativeHeaders() {
@SuppressWarnings("unchecked")
Map<String, List<String>> map = (Map<String, List<String>>) getHeader(NATIVE_HEADERS);
return (map != null ? map : Collections.<String, List<String>>emptyMap());
return (map != null ? map : Collections.emptyMap());
}
public StompCommand updateStompCommandAsClientMessage() {
......@@ -242,7 +242,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
public Set<String> getAcceptVersion() {
String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER);
return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.<String>emptySet());
return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.emptySet());
}
public void setHost(String host) {
......
......@@ -188,7 +188,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver {
}
}
else {
sessionIds = Collections.<String>emptySet();
sessionIds = Collections.emptySet();
}
}
if (!this.keepLeadingSlash) {
......
......@@ -94,7 +94,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor {
*/
public Map<String, List<String>> toNativeHeaderMap() {
Map<String, List<String>> map = getNativeHeaders();
return (map != null ? new LinkedMultiValueMap<>(map) : Collections.<String, List<String>>emptyMap());
return (map != null ? new LinkedMultiValueMap<>(map) : Collections.emptyMap());
}
@Override
......
......@@ -299,8 +299,7 @@ public class Reactor2TcpClient<P> implements TcpOperations<P> {
@Override
public ReactorConfiguration read() {
return new ReactorConfiguration(
Collections.<DispatcherConfiguration>emptyList(), "sync", new Properties());
return new ReactorConfiguration(Collections.emptyList(), "sync", new Properties());
}
}
......
......@@ -425,13 +425,13 @@ public class MockServletContext implements ServletContext {
@Override
@Deprecated
public Enumeration<Servlet> getServlets() {
return Collections.enumeration(Collections.<Servlet>emptySet());
return Collections.enumeration(Collections.emptySet());
}
@Override
@Deprecated
public Enumeration<String> getServletNames() {
return Collections.enumeration(Collections.<String>emptySet());
return Collections.enumeration(Collections.emptySet());
}
@Override
......
......@@ -132,7 +132,7 @@ public abstract class TestPropertySourceUtils {
if (logger.isTraceEnabled()) {
logger.trace(String.format("Processing inlined properties for TestPropertySource attributes %s", attrs));
}
properties.addAll(0, Arrays.<String>asList(attrs.getProperties()));
properties.addAll(0, Arrays.asList(attrs.getProperties()));
if (!attrs.isInheritProperties()) {
break;
}
......
......@@ -269,7 +269,7 @@ public class MediaType extends MimeType implements Serializable {
* @throws IllegalArgumentException if any of the parameters contain illegal characters
*/
public MediaType(String type, String subtype) {
super(type, subtype, Collections.<String, String>emptyMap());
super(type, subtype, Collections.emptyMap());
}
/**
......@@ -463,7 +463,7 @@ public class MediaType extends MimeType implements Serializable {
*/
public static List<MediaType> parseMediaTypes(List<String> mediaTypes) {
if (CollectionUtils.isEmpty(mediaTypes)) {
return Collections.<MediaType>emptyList();
return Collections.emptyList();
}
else if (mediaTypes.size() == 1) {
return parseMediaTypes(mediaTypes.get(0));
......
......@@ -47,7 +47,7 @@ public class InterceptingAsyncClientHttpRequestFactory implements AsyncClientHtt
List<AsyncClientHttpRequestInterceptor> interceptors) {
this.delegate = delegate;
this.interceptors = (interceptors != null ? interceptors : Collections.<AsyncClientHttpRequestInterceptor>emptyList());
this.interceptors = (interceptors != null ? interceptors : Collections.emptyList());
}
......
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
......@@ -42,7 +42,7 @@ public class InterceptingClientHttpRequestFactory extends AbstractClientHttpRequ
List<ClientHttpRequestInterceptor> interceptors) {
super(requestFactory);
this.interceptors = (interceptors != null ? interceptors : Collections.<ClientHttpRequestInterceptor>emptyList());
this.interceptors = (interceptors != null ? interceptors : Collections.emptyList());
}
@Override
......
......@@ -45,7 +45,7 @@ public class HeaderContentNegotiationStrategy implements ContentNegotiationStrat
String[] headerValueArray = request.getHeaderValues(HttpHeaders.ACCEPT);
if (headerValueArray == null) {
return Collections.<MediaType>emptyList();
return Collections.emptyList();
}
List<String> headerValues = Arrays.asList(headerValueArray);
......
......@@ -90,7 +90,7 @@ public class MappingMediaTypeFileExtensionResolver implements MediaTypeFileExten
@Override
public List<String> resolveFileExtensions(MediaType mediaType) {
List<String> fileExtensions = this.fileExtensions.get(mediaType);
return (fileExtensions != null) ? fileExtensions : Collections.<String>emptyList();
return (fileExtensions != null) ? fileExtensions : Collections.emptyList();
}
@Override
......
......@@ -213,7 +213,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter {
@Override
public Enumeration<String> getHeaders(String name) {
List<String> value = this.headers.get(name);
return (Collections.enumeration(value != null ? value : Collections.<String>emptySet()));
return (Collections.enumeration(value != null ? value : Collections.emptySet()));
}
@Override
......
......@@ -590,7 +590,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
private void addMappingName(String name, HandlerMethod handlerMethod) {
List<HandlerMethod> oldList = this.nameLookup.get(name);
if (oldList == null) {
oldList = Collections.<HandlerMethod>emptyList();
oldList = Collections.emptyList();
}
for (HandlerMethod current : oldList) {
......@@ -685,7 +685,7 @@ public abstract class AbstractHandlerMethodMapping<T> extends AbstractHandlerMap
Assert.notNull(handlerMethod);
this.mapping = mapping;
this.handlerMethod = handlerMethod;
this.directUrls = (directUrls != null ? directUrls : Collections.<String>emptyList());
this.directUrls = (directUrls != null ? directUrls : Collections.emptyList());
this.mappingName = mappingName;
}
......
......@@ -163,7 +163,7 @@ public class SimpleServletPostProcessor implements
@Override
public Enumeration<String> getInitParameterNames() {
return Collections.enumeration(Collections.<String>emptySet());
return Collections.enumeration(Collections.emptySet());
}
}
......
......@@ -119,7 +119,7 @@ public final class PatternsRequestCondition extends AbstractRequestCondition<Pat
private static List<String> asList(String... patterns) {
return (patterns != null ? Arrays.asList(patterns) : Collections.<String>emptyList());
return (patterns != null ? Arrays.asList(patterns) : Collections.emptyList());
}
private static Set<String> prependLeadingSlash(Collection<String> patterns) {
......
......@@ -62,7 +62,7 @@ public final class RequestMethodsRequestCondition extends AbstractRequestConditi
private static List<RequestMethod> asList(RequestMethod... requestMethods) {
return (requestMethods != null ? Arrays.asList(requestMethods) : Collections.<RequestMethod>emptyList());
return (requestMethods != null ? Arrays.asList(requestMethods) : Collections.emptyList());
}
......
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
......@@ -106,7 +106,7 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr
protected final Map<String, String> getUriTemplateVariables(NativeWebRequest request) {
Map<String, String> variables = (Map<String, String>) request.getAttribute(
HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);
return (variables != null ? variables : Collections.<String, String>emptyMap());
return (variables != null ? variables : Collections.emptyMap());
}
/**
......
......@@ -235,7 +235,7 @@ public class SseEmitter extends ResponseBodyEmitter {
@Override
public Set<DataWithMediaType> build() {
if ((this.sb == null || this.sb.length() == 0) && this.dataToSend.isEmpty()) {
return Collections.<DataWithMediaType>emptySet();
return Collections.emptySet();
}
append("\n");
saveAppendedText();
......
......@@ -405,7 +405,7 @@ public class FreeMarkerView extends AbstractTemplateView {
@Override
public Enumeration<String> getInitParameterNames() {
return Collections.enumeration(Collections.<String>emptySet());
return Collections.enumeration(Collections.emptySet());
}
}
......
......@@ -43,8 +43,6 @@ import org.springframework.web.util.UriComponentsBuilder;
*/
public abstract class AbstractWebSocketClient implements WebSocketClient {
protected final Log logger = LogFactory.getLog(getClass());
private static final Set<String> specialHeaders = new HashSet<>();
static {
......@@ -60,11 +58,14 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
}
protected final Log logger = LogFactory.getLog(getClass());
@Override
public ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler,
String uriTemplate, Object... uriVars) {
Assert.notNull(uriTemplate, "uriTemplate must not be null");
Assert.notNull(uriTemplate, "'uriTemplate' must not be null");
URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVars).encode().toUri();
return doHandshake(webSocketHandler, null, uri);
}
......@@ -73,7 +74,7 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
public final ListenableFuture<WebSocketSession> doHandshake(WebSocketHandler webSocketHandler,
WebSocketHttpHeaders headers, URI uri) {
Assert.notNull(webSocketHandler, "webSocketHandler must not be null");
Assert.notNull(webSocketHandler, "WebSocketHandler must not be null");
assertUri(uri);
if (logger.isDebugEnabled()) {
......@@ -89,25 +90,26 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
}
}
List<String> subProtocols = ((headers != null) && (headers.getSecWebSocketProtocol() != null)) ?
headers.getSecWebSocketProtocol() : Collections.<String>emptyList();
List<String> subProtocols = (headers != null && headers.getSecWebSocketProtocol() != null ?
headers.getSecWebSocketProtocol() : Collections.emptyList());
List<WebSocketExtension> extensions = ((headers != null) && (headers.getSecWebSocketExtensions() != null)) ?
headers.getSecWebSocketExtensions() : Collections.<WebSocketExtension>emptyList();
List<WebSocketExtension> extensions = (headers != null && headers.getSecWebSocketExtensions() != null ?
headers.getSecWebSocketExtensions() : Collections.emptyList());
return doHandshakeInternal(webSocketHandler, headersToUse, uri, subProtocols, extensions,
Collections.<String, Object>emptyMap());
Collections.emptyMap());
}
protected void assertUri(URI uri) {
Assert.notNull(uri, "uri must not be null");
Assert.notNull(uri, "URI must not be null");
String scheme = uri.getScheme();
Assert.isTrue(scheme != null && ("ws".equals(scheme) || "wss".equals(scheme)), "Invalid scheme: " + scheme);
if (!"ws".equals(scheme) && !"wss".equals(scheme)) {
throw new IllegalArgumentException("Invalid scheme: " + scheme);
}
}
/**
* Perform the actual handshake to establish a connection to the server.
*
* @param webSocketHandler the client-side handler for WebSocket messages
* @param headers HTTP headers to use for the handshake, with unwanted (forbidden)
* headers filtered out, never {@code null}
......@@ -116,7 +118,6 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
* @param extensions requested WebSocket extensions, or an empty list
* @param attributes attributes to associate with the WebSocketSession, i.e. via
* {@link WebSocketSession#getAttributes()}; currently always an empty map.
*
* @return the established WebSocket session wrapped in a ListenableFuture.
*/
protected abstract ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler webSocketHandler,
......
......@@ -468,7 +468,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
}
public List<Message<byte[]>> decode(WebSocketMessage<?> webSocketMessage) {
List<Message<byte[]>> result = Collections.<Message<byte[]>>emptyList();
List<Message<byte[]>> result = Collections.emptyList();
ByteBuffer byteBuffer;
if (webSocketMessage instanceof TextMessage) {
byteBuffer = ByteBuffer.wrap(((TextMessage) webSocketMessage).asBytes());
......
......@@ -66,7 +66,7 @@ public class UndertowRequestUpgradeStrategy extends AbstractStandardUpgradeStrat
StringBuffer requestUrl = servletRequest.getRequestURL();
String path = servletRequest.getRequestURI(); // shouldn't matter
Map<String, String> pathParams = Collections.<String, String>emptyMap();
Map<String, String> pathParams = Collections.emptyMap();
ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint);
endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol));
......
......@@ -367,7 +367,7 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
if (handlerToCheck instanceof SubProtocolCapable) {
subProtocols = ((SubProtocolCapable) handlerToCheck).getSubProtocols();
}
return (subProtocols != null ? subProtocols : Collections.<String>emptyList());
return (subProtocols != null ? subProtocols : Collections.emptyList());
}
/**
......
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
......@@ -46,7 +46,7 @@ public class HandshakeInterceptorChain {
public HandshakeInterceptorChain(List<HandshakeInterceptor> interceptors, WebSocketHandler wsHandler) {
this.interceptors = (interceptors != null ? interceptors : Collections.<HandshakeInterceptor>emptyList());
this.interceptors = (interceptors != null ? interceptors : Collections.emptyList());
this.wsHandler = wsHandler;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册