Skip to content

Commit bfddbbe

Browse files
committed
Polishing
1 parent 4781627 commit bfddbbe

File tree

6 files changed

+51
-57
lines changed

6 files changed

+51
-57
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -161,6 +161,7 @@ public GroovyBeanDefinitionWrapper addProperty(String propertyName, Object prope
161161
return this;
162162
}
163163

164+
164165
@Override
165166
public Object getProperty(String property) {
166167
if (this.definitionWrapper.isReadableProperty(property)) {

spring-test/src/main/java/org/springframework/test/context/TestContextManager.java

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,8 @@ public class TestContextManager {
9494

9595
private final TestContext testContext;
9696

97-
private final ThreadLocal<TestContext> testContextHolder = new ThreadLocal<TestContext>() {
98-
99-
@Override
100-
protected TestContext initialValue() {
101-
return copyTestContext(TestContextManager.this.testContext);
102-
}
103-
};
97+
private final ThreadLocal<TestContext> testContextHolder =
98+
ThreadLocal.withInitial(() -> copyTestContext(TestContextManager.this.testContext));
10499

105100
private final List<TestExecutionListener> testExecutionListeners = new ArrayList<>();
106101

@@ -364,11 +359,13 @@ public void beforeTestExecution(Object testInstance, Method testMethod) throws E
364359
* @see #getTestExecutionListeners()
365360
* @see Throwable#addSuppressed(Throwable)
366361
*/
367-
public void afterTestExecution(Object testInstance, Method testMethod, @Nullable Throwable exception) throws Exception {
362+
public void afterTestExecution(Object testInstance, Method testMethod, @Nullable Throwable exception)
363+
throws Exception {
364+
368365
String callbackName = "afterTestExecution";
369366
prepareForAfterCallback(callbackName, testInstance, testMethod, exception);
370-
371367
Throwable afterTestExecutionException = null;
368+
372369
// Traverse the TestExecutionListeners in reverse order to ensure proper
373370
// "wrapper"-style execution of listeners.
374371
for (TestExecutionListener testExecutionListener : getReversedTestExecutionListeners()) {
@@ -385,6 +382,7 @@ public void afterTestExecution(Object testInstance, Method testMethod, @Nullable
385382
}
386383
}
387384
}
385+
388386
if (afterTestExecutionException != null) {
389387
ReflectionUtils.rethrowException(afterTestExecutionException);
390388
}
@@ -414,21 +412,22 @@ public void afterTestExecution(Object testInstance, Method testMethod, @Nullable
414412
* @param testInstance the current test instance (never {@code null})
415413
* @param testMethod the test method which has just been executed on the
416414
* test instance
417-
* @param exception the exception that was thrown during execution of the
418-
* test method or by a TestExecutionListener, or {@code null} if none
419-
* was thrown
415+
* @param exception the exception that was thrown during execution of the test
416+
* method or by a TestExecutionListener, or {@code null} if none was thrown
420417
* @throws Exception if a registered TestExecutionListener throws an exception
421418
* @see #beforeTestMethod
422419
* @see #beforeTestExecution
423420
* @see #afterTestExecution
424421
* @see #getTestExecutionListeners()
425422
* @see Throwable#addSuppressed(Throwable)
426423
*/
427-
public void afterTestMethod(Object testInstance, Method testMethod, @Nullable Throwable exception) throws Exception {
424+
public void afterTestMethod(Object testInstance, Method testMethod, @Nullable Throwable exception)
425+
throws Exception {
426+
428427
String callbackName = "afterTestMethod";
429428
prepareForAfterCallback(callbackName, testInstance, testMethod, exception);
430-
431429
Throwable afterTestMethodException = null;
430+
432431
// Traverse the TestExecutionListeners in reverse order to ensure proper
433432
// "wrapper"-style execution of listeners.
434433
for (TestExecutionListener testExecutionListener : getReversedTestExecutionListeners()) {
@@ -445,6 +444,7 @@ public void afterTestMethod(Object testInstance, Method testMethod, @Nullable Th
445444
}
446445
}
447446
}
447+
448448
if (afterTestMethodException != null) {
449449
ReflectionUtils.rethrowException(afterTestMethodException);
450450
}
@@ -510,33 +510,36 @@ private void prepareForAfterCallback(String callbackName, Object testInstance, M
510510
@Nullable Throwable exception) {
511511

512512
if (logger.isTraceEnabled()) {
513-
logger.trace(String.format("%s(): instance [%s], method [%s], exception [%s]", callbackName, testInstance,
514-
testMethod, exception));
513+
logger.trace(String.format("%s(): instance [%s], method [%s], exception [%s]",
514+
callbackName, testInstance, testMethod, exception));
515515
}
516516
getTestContext().updateState(testInstance, testMethod, exception);
517517
}
518518

519519
private void handleBeforeException(Throwable ex, String callbackName, TestExecutionListener testExecutionListener,
520520
Object testInstance, Method testMethod) throws Exception {
521+
521522
logException(ex, callbackName, testExecutionListener, testInstance, testMethod);
522523
ReflectionUtils.rethrowException(ex);
523524
}
524525

525-
private void logException(Throwable ex, String callbackName, TestExecutionListener testExecutionListener,
526-
Class<?> testClass) {
526+
private void logException(
527+
Throwable ex, String callbackName, TestExecutionListener testExecutionListener, Class<?> testClass) {
528+
527529
if (logger.isWarnEnabled()) {
528530
logger.warn(String.format("Caught exception while invoking '%s' callback on " +
529-
"TestExecutionListener [%s] for test class [%s]", callbackName, testExecutionListener,
530-
testClass), ex);
531+
"TestExecutionListener [%s] for test class [%s]", callbackName, testExecutionListener,
532+
testClass), ex);
531533
}
532534
}
533535

534536
private void logException(Throwable ex, String callbackName, TestExecutionListener testExecutionListener,
535537
Object testInstance, Method testMethod) {
538+
536539
if (logger.isWarnEnabled()) {
537540
logger.warn(String.format("Caught exception while invoking '%s' callback on " +
538-
"TestExecutionListener [%s] for test method [%s] and test instance [%s]",
539-
callbackName, testExecutionListener, testMethod, testInstance), ex);
541+
"TestExecutionListener [%s] for test method [%s] and test instance [%s]",
542+
callbackName, testExecutionListener, testMethod, testInstance), ex);
540543
}
541544
}
542545

@@ -546,8 +549,8 @@ private void logException(Throwable ex, String callbackName, TestExecutionListen
546549
* <em>copy constructor</em>.
547550
*/
548551
private static TestContext copyTestContext(TestContext testContext) {
549-
Constructor<? extends TestContext> constructor = ClassUtils.getConstructorIfAvailable(testContext.getClass(),
550-
testContext.getClass());
552+
Constructor<? extends TestContext> constructor =
553+
ClassUtils.getConstructorIfAvailable(testContext.getClass(), testContext.getClass());
551554

552555
if (constructor != null) {
553556
try {
@@ -563,7 +566,7 @@ private static TestContext copyTestContext(TestContext testContext) {
563566
}
564567
}
565568

566-
// fallback to original instance
569+
// Fallback to original instance
567570
return testContext;
568571
}
569572

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/CompositeRequestCondition.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -20,7 +20,6 @@
2020
import java.util.Collection;
2121
import java.util.Collections;
2222
import java.util.List;
23-
2423
import javax.servlet.http.HttpServletRequest;
2524

2625
import org.springframework.lang.Nullable;
@@ -77,7 +76,7 @@ public boolean isEmpty() {
7776
}
7877

7978
/**
80-
* Return the underlying conditions, possibly empty but never {@code null}.
79+
* Return the underlying conditions (possibly empty but never {@code null}).
8180
*/
8281
public List<RequestCondition<?>> getConditions() {
8382
return unwrap();

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ConsumesRequestCondition.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -19,7 +19,6 @@
1919
import java.util.ArrayList;
2020
import java.util.Collection;
2121
import java.util.Collections;
22-
import java.util.Iterator;
2322
import java.util.LinkedHashSet;
2423
import java.util.List;
2524
import java.util.Set;
@@ -49,7 +48,6 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition<Con
4948

5049
private final static ConsumesRequestCondition PRE_FLIGHT_MATCH = new ConsumesRequestCondition();
5150

52-
5351
private final List<ConsumeMediaTypeExpression> expressions;
5452

5553

@@ -159,7 +157,7 @@ public ConsumesRequestCondition combine(ConsumesRequestCondition other) {
159157
* @param request the current request
160158
* @return the same instance if the condition contains no expressions;
161159
* or a new condition with matching expressions only;
162-
* or {@code null} if no expressions match.
160+
* or {@code null} if no expressions match
163161
*/
164162
@Override
165163
@Nullable
@@ -170,23 +168,20 @@ public ConsumesRequestCondition getMatchingCondition(HttpServletRequest request)
170168
if (isEmpty()) {
171169
return this;
172170
}
171+
173172
MediaType contentType;
174173
try {
175-
contentType = StringUtils.hasLength(request.getContentType()) ?
174+
contentType = (StringUtils.hasLength(request.getContentType()) ?
176175
MediaType.parseMediaType(request.getContentType()) :
177-
MediaType.APPLICATION_OCTET_STREAM;
176+
MediaType.APPLICATION_OCTET_STREAM);
178177
}
179178
catch (InvalidMediaTypeException ex) {
180179
return null;
181180
}
181+
182182
Set<ConsumeMediaTypeExpression> result = new LinkedHashSet<>(this.expressions);
183-
for (Iterator<ConsumeMediaTypeExpression> iterator = result.iterator(); iterator.hasNext();) {
184-
ConsumeMediaTypeExpression expression = iterator.next();
185-
if (!expression.match(contentType)) {
186-
iterator.remove();
187-
}
188-
}
189-
return (result.isEmpty()) ? null : new ConsumesRequestCondition(result);
183+
result.removeIf(expression -> !expression.match(contentType));
184+
return (!result.isEmpty() ? new ConsumesRequestCondition(result) : null);
190185
}
191186

192187
/**

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -19,7 +19,6 @@
1919
import java.util.ArrayList;
2020
import java.util.Collection;
2121
import java.util.Collections;
22-
import java.util.Iterator;
2322
import java.util.LinkedHashSet;
2423
import java.util.List;
2524
import java.util.Set;
@@ -48,14 +47,14 @@
4847
*/
4948
public final class ProducesRequestCondition extends AbstractRequestCondition<ProducesRequestCondition> {
5049

51-
private final static ProducesRequestCondition PRE_FLIGHT_MATCH = new ProducesRequestCondition();
50+
private static final ProducesRequestCondition PRE_FLIGHT_MATCH = new ProducesRequestCondition();
5251

5352
private static final ProducesRequestCondition EMPTY_CONDITION = new ProducesRequestCondition();
5453

55-
5654
private static final List<ProduceMediaTypeExpression> MEDIA_TYPE_ALL_LIST =
5755
Collections.singletonList(new ProduceMediaTypeExpression("*/*"));
5856

57+
5958
private final List<ProduceMediaTypeExpression> expressions;
6059

6160
private final ContentNegotiationManager contentNegotiationManager;
@@ -194,20 +193,17 @@ public ProducesRequestCondition getMatchingCondition(HttpServletRequest request)
194193
if (isEmpty()) {
195194
return this;
196195
}
196+
197197
List<MediaType> acceptedMediaTypes;
198198
try {
199199
acceptedMediaTypes = getAcceptedMediaTypes(request);
200200
}
201201
catch (HttpMediaTypeException ex) {
202202
return null;
203203
}
204-
Set<ProduceMediaTypeExpression> result = new LinkedHashSet<>(expressions);
205-
for (Iterator<ProduceMediaTypeExpression> iterator = result.iterator(); iterator.hasNext();) {
206-
ProduceMediaTypeExpression expression = iterator.next();
207-
if (!expression.match(acceptedMediaTypes)) {
208-
iterator.remove();
209-
}
210-
}
204+
205+
Set<ProduceMediaTypeExpression> result = new LinkedHashSet<>(this.expressions);
206+
result.removeIf(expression -> !expression.match(acceptedMediaTypes));
211207
if (!result.isEmpty()) {
212208
return new ProducesRequestCondition(result, this.contentNegotiationManager);
213209
}

spring-websocket/src/main/java/org/springframework/web/socket/handler/ConcurrentWebSocketSessionDecorator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -112,6 +112,7 @@ public long getTimeSinceSendStarted() {
112112
return (start > 0 ? (System.currentTimeMillis() - start) : 0);
113113
}
114114

115+
115116
@Override
116117
public void sendMessage(WebSocketMessage<?> message) throws IOException {
117118
if (shouldNotSend()) {
@@ -124,10 +125,9 @@ public void sendMessage(WebSocketMessage<?> message) throws IOException {
124125
do {
125126
if (!tryFlushMessageBuffer()) {
126127
if (logger.isTraceEnabled()) {
127-
String text = String.format("Another send already in progress: " +
128+
logger.trace(String.format("Another send already in progress: " +
128129
"session id '%s':, \"in-progress\" send time %d (ms), buffer size %d bytes",
129-
getId(), getTimeSinceSendStarted(), getBufferSize());
130-
logger.trace(text);
130+
getId(), getTimeSinceSendStarted(), getBufferSize()));
131131
}
132132
checkSessionLimits();
133133
break;

0 commit comments

Comments
 (0)