Skip to content

Commit 7861cfa

Browse files
committed
Polishing
1 parent 7ec6a9d commit 7861cfa

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -272,8 +272,7 @@ private Message<byte[]> createMessage(StompHeaderAccessor accessor, @Nullable Ob
272272
}
273273

274274
private boolean isEmpty(@Nullable Object payload) {
275-
return payload == null || StringUtils.isEmpty(payload) ||
276-
(payload instanceof byte[] && ((byte[]) payload).length == 0);
275+
return (StringUtils.isEmpty(payload) || (payload instanceof byte[] && ((byte[]) payload).length == 0));
277276
}
278277

279278
private void execute(Message<byte[]> message) {
@@ -689,8 +688,10 @@ public void run() {
689688
if (conn != null) {
690689
conn.send(HEARTBEAT).addCallback(
691690
new ListenableFutureCallback<Void>() {
691+
@Override
692692
public void onSuccess(@Nullable Void result) {
693693
}
694+
@Override
694695
public void onFailure(Throwable ex) {
695696
handleFailure(ex);
696697
}

spring-messaging/src/main/java/org/springframework/messaging/support/NativeMessageHeaderAccessor.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected NativeMessageHeaderAccessor(@Nullable Message<?> message) {
8282

8383

8484
/**
85-
* Sub-classes can use this method to access the "native" headers sub-map.
85+
* Subclasses can use this method to access the "native" headers sub-map.
8686
*/
8787
@SuppressWarnings("unchecked")
8888
@Nullable
@@ -139,14 +139,17 @@ public void copyHeaders(@Nullable Map<String, ?> headersToCopy) {
139139

140140
/**
141141
* Whether the native header map contains the give header name.
142+
* @param headerName the name of the header
142143
*/
143144
public boolean containsNativeHeader(String headerName) {
144145
Map<String, List<String>> map = getNativeHeaders();
145146
return (map != null && map.containsKey(headerName));
146147
}
147148

148149
/**
149-
* Return the values for the specified native header, if present.
150+
* Return all values for the specified native header, if present.
151+
* @param headerName the name of the header
152+
* @return the associated values, or {@code null} if none
150153
*/
151154
@Nullable
152155
public List<String> getNativeHeader(String headerName) {
@@ -156,13 +159,15 @@ public List<String> getNativeHeader(String headerName) {
156159

157160
/**
158161
* Return the first value for the specified native header, if present.
162+
* @param headerName the name of the header
163+
* @return the associated value, or {@code null} if none
159164
*/
160165
@Nullable
161166
public String getFirstNativeHeader(String headerName) {
162167
Map<String, List<String>> map = getNativeHeaders();
163168
if (map != null) {
164169
List<String> values = map.get(headerName);
165-
if (values != null) {
170+
if (!CollectionUtils.isEmpty(values)) {
166171
return values.get(0);
167172
}
168173
}
@@ -200,6 +205,8 @@ public void setNativeHeader(String name, @Nullable String value) {
200205
* Add the specified native header value to existing values.
201206
* <p>In order for this to work, the accessor must be {@link #isMutable()
202207
* mutable}. See {@link MessageHeaderAccessor} for details.
208+
* @param name the name of the header
209+
* @param value the header value to set
203210
*/
204211
public void addNativeHeader(String name, @Nullable String value) {
205212
Assert.state(isMutable(), "Already immutable");
@@ -216,6 +223,10 @@ public void addNativeHeader(String name, @Nullable String value) {
216223
setModified(true);
217224
}
218225

226+
/**
227+
* Add the specified native headers to existing values.
228+
* @param headers the headers to set
229+
*/
219230
public void addNativeHeaders(@Nullable MultiValueMap<String, String> headers) {
220231
if (headers == null) {
221232
return;
@@ -227,24 +238,34 @@ public void addNativeHeaders(@Nullable MultiValueMap<String, String> headers) {
227238
* Remove the specified native header value replacing existing values.
228239
* <p>In order for this to work, the accessor must be {@link #isMutable()
229240
* mutable}. See {@link MessageHeaderAccessor} for details.
241+
* @param headerName the name of the header
242+
* @return the associated values, or {@code null} if the header was not present
230243
*/
231244
@Nullable
232-
public List<String> removeNativeHeader(String name) {
245+
public List<String> removeNativeHeader(String headerName) {
233246
Assert.state(isMutable(), "Already immutable");
234247
Map<String, List<String>> nativeHeaders = getNativeHeaders();
235-
if (nativeHeaders == null) {
248+
if (CollectionUtils.isEmpty(nativeHeaders)) {
236249
return null;
237250
}
238-
return nativeHeaders.remove(name);
251+
return nativeHeaders.remove(headerName);
239252
}
240253

254+
255+
/**
256+
* Return the first value for the specified native header,
257+
* or {@code null} if none.
258+
* @param headerName the name of the header
259+
* @param headers the headers map to introspect
260+
* @return the associated value, or {@code null} if none
261+
*/
241262
@SuppressWarnings("unchecked")
242263
@Nullable
243264
public static String getFirstNativeHeader(String headerName, Map<String, Object> headers) {
244265
Map<String, List<String>> map = (Map<String, List<String>>) headers.get(NATIVE_HEADERS);
245266
if (map != null) {
246267
List<String> values = map.get(headerName);
247-
if (values != null) {
268+
if (!CollectionUtils.isEmpty(values)) {
248269
return values.get(0);
249270
}
250271
}

spring-web/src/main/java/org/springframework/http/ResponseCookie.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -185,7 +185,7 @@ public String toString() {
185185
* with a name-value pair and may also include attributes.
186186
* @param name the cookie name
187187
* @param value the cookie value
188-
* @return the created cookie instance
188+
* @return a builder to create the cookie with
189189
*/
190190
public static ResponseCookieBuilder from(final String name, final String value) {
191191

spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpRequest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,7 +38,6 @@
3838
import org.springframework.http.HttpMethod;
3939
import org.springframework.http.MediaType;
4040
import org.springframework.lang.Nullable;
41-
import org.springframework.util.Assert;
4241

4342
/**
4443
* {@link ClientHttpRequest} implementation for the Jetty ReactiveStreams HTTP client.
@@ -65,9 +64,7 @@ public JettyClientHttpRequest(Request jettyRequest, DataBufferFactory bufferFact
6564

6665
@Override
6766
public HttpMethod getMethod() {
68-
HttpMethod method = HttpMethod.resolve(this.jettyRequest.getMethod());
69-
Assert.state(method != null, "Method must not be null");
70-
return method;
67+
return HttpMethod.valueOf(this.jettyRequest.getMethod());
7168
}
7269

7370
@Override
@@ -119,7 +116,6 @@ private ContentChunk toContentChunk(DataBuffer buffer) {
119116
public void succeeded() {
120117
DataBufferUtils.release(buffer);
121118
}
122-
123119
@Override
124120
public void failed(Throwable x) {
125121
DataBufferUtils.release(buffer);

0 commit comments

Comments
 (0)