From d04567b99c47ce5ed9cddcf4c5ad6911b337e859 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 26 Sep 2016 18:19:04 +0200 Subject: [PATCH] Polishing --- .../org/springframework/core/Conventions.java | 11 +++----- .../springframework/util/InstanceFilter.java | 10 +++---- .../config/AbstractBrokerRegistration.java | 7 ++--- .../client/AbstractWebSocketClient.java | 27 ++++++++++--------- 4 files changed, 26 insertions(+), 29 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/Conventions.java b/spring-core/src/main/java/org/springframework/core/Conventions.java index 2c4152ff194..86d125248d4 100644 --- a/spring-core/src/main/java/org/springframework/core/Conventions.java +++ b/spring-core/src/main/java/org/springframework/core/Conventions.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 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,13 +50,10 @@ public abstract class Conventions { * when searching for the 'primary' interface of a proxy. */ private static final Set> IGNORED_INTERFACES; + static { - IGNORED_INTERFACES = Collections.unmodifiableSet( - new HashSet>(Arrays.> 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))); } diff --git a/spring-core/src/main/java/org/springframework/util/InstanceFilter.java b/spring-core/src/main/java/org/springframework/util/InstanceFilter.java index 6aa84612389..e700101822a 100644 --- a/spring-core/src/main/java/org/springframework/util/InstanceFilter.java +++ b/spring-core/src/main/java/org/springframework/util/InstanceFilter.java @@ -1,5 +1,5 @@ /* - * 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 { public InstanceFilter(Collection includes, Collection excludes, boolean matchIfEmpty) { - this.includes = includes != null ? includes : Collections.emptyList(); - this.excludes = excludes != null ? excludes : Collections.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 { * 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 { boolean matchIncludes = match(instance, this.includes); boolean matchExcludes = match(instance, this.excludes); - if (!includesSet) { return !matchExcludes; } - if (!excludesSet) { return matchIncludes; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractBrokerRegistration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractBrokerRegistration.java index 93a25239cb3..21f225eb331 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractBrokerRegistration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractBrokerRegistration.java @@ -1,5 +1,5 @@ /* - * 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.asList(destinationPrefixes) : Collections.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); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java index 92577e1cbae..8629f201f04 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java @@ -1,5 +1,5 @@ /* - * 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. @@ -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 specialHeaders = new HashSet(); static { @@ -60,11 +58,14 @@ public abstract class AbstractWebSocketClient implements WebSocketClient { } + protected final Log logger = LogFactory.getLog(getClass()); + + @Override public ListenableFuture 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 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 subProtocols = ((headers != null) && (headers.getSecWebSocketProtocol() != null)) ? - headers.getSecWebSocketProtocol() : Collections.emptyList(); + List subProtocols = (headers != null && headers.getSecWebSocketProtocol() != null ? + headers.getSecWebSocketProtocol() : Collections.emptyList()); - List extensions = ((headers != null) && (headers.getSecWebSocketExtensions() != null)) ? - headers.getSecWebSocketExtensions() : Collections.emptyList(); + List extensions = (headers != null && headers.getSecWebSocketExtensions() != null ? + headers.getSecWebSocketExtensions() : Collections.emptyList()); return doHandshakeInternal(webSocketHandler, headersToUse, uri, subProtocols, extensions, 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 doHandshakeInternal(WebSocketHandler webSocketHandler,