Skip to content

Commit f83bb71

Browse files
committed
Polishing
1 parent 1745a3f commit f83bb71

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

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

Lines changed: 2 additions & 3 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.
@@ -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) {

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-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,8 @@ public final MockHttpServletRequest buildRequest(ServletContext servletContext)
700700

701701
String query = this.url.getRawQuery();
702702
if (!this.queryParams.isEmpty()) {
703-
String s = UriComponentsBuilder.newInstance().queryParams(this.queryParams).build().encode().getQuery();
704-
query = StringUtils.isEmpty(query) ? s : query + "&" + s;
703+
String str = UriComponentsBuilder.newInstance().queryParams(this.queryParams).build().encode().getQuery();
704+
query = StringUtils.hasLength(query) ? (query + "&" + str) : str;
705705
}
706706
if (query != null) {
707707
request.setQueryString(query);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ public ResponseCookieBuilder domain(String domain) {
245245

246246
@Nullable
247247
private String initDomain(String domain) {
248-
if (lenient && !StringUtils.isEmpty(domain)) {
249-
String s = domain.trim();
250-
if (s.startsWith("\"") && s.endsWith("\"")) {
251-
if (s.substring(1, s.length() - 1).trim().isEmpty()) {
248+
if (lenient && StringUtils.hasLength(domain)) {
249+
String str = domain.trim();
250+
if (str.startsWith("\"") && str.endsWith("\"")) {
251+
if (str.substring(1, str.length() - 1).trim().isEmpty()) {
252252
return null;
253253
}
254254
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.springframework.http.HttpHeaders;
3939
import org.springframework.http.HttpMethod;
4040
import org.springframework.http.MediaType;
41-
import org.springframework.util.Assert;
4241

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

6362
@Override
6463
public HttpMethod getMethod() {
65-
HttpMethod method = HttpMethod.resolve(this.jettyRequest.getMethod());
66-
Assert.state(method != null, "Method must not be null");
67-
return method;
64+
return HttpMethod.valueOf(this.jettyRequest.getMethod());
6865
}
6966

7067
@Override
@@ -117,7 +114,6 @@ private ContentChunk toContentChunk(DataBuffer buffer) {
117114
public void succeeded() {
118115
DataBufferUtils.release(buffer);
119116
}
120-
121117
@Override
122118
public void failed(Throwable x) {
123119
DataBufferUtils.release(buffer);

0 commit comments

Comments
 (0)