Skip to content

Commit fc64b80

Browse files
committed
Polish "Replace relevant code with lambda"
Closes spring-projectsgh-1454
1 parent 4b1478d commit fc64b80

File tree

29 files changed

+186
-189
lines changed

29 files changed

+186
-189
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 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.

spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

Lines changed: 2 additions & 3 deletions
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-2017 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.
@@ -28,7 +28,6 @@
2828
import java.lang.reflect.Method;
2929
import java.lang.reflect.Modifier;
3030
import java.util.ArrayList;
31-
import java.util.Collections;
3231
import java.util.Comparator;
3332
import java.util.List;
3433
import java.util.Set;
@@ -139,7 +138,7 @@ private List<Method> findCandidateWriteMethods(MethodDescriptor[] methodDescript
139138
// Sort non-void returning write methods to guard against the ill effects of
140139
// non-deterministic sorting of methods returned from Class#getDeclaredMethods
141140
// under JDK 7. See http://bugs.sun.com/view_bug.do?bug_id=7023180
142-
Collections.sort(matches, (m1, m2) -> m2.toString().compareTo(m1.toString()));
141+
matches.sort((m1, m2) -> m2.toString().compareTo(m1.toString()));
143142
return matches;
144143
}
145144

spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -412,43 +412,43 @@ private InjectionMetadata buildAutowiringMetadata(final Class<?> clazz) {
412412
final LinkedList<InjectionMetadata.InjectedElement> currElements = new LinkedList<>();
413413

414414
ReflectionUtils.doWithLocalFields(targetClass, field -> {
415-
AnnotationAttributes ann = findAutowiredAnnotation(field);
416-
if (ann != null) {
417-
if (Modifier.isStatic(field.getModifiers())) {
418-
if (logger.isWarnEnabled()) {
419-
logger.warn("Autowired annotation is not supported on static fields: " + field);
420-
}
421-
return;
422-
}
423-
boolean required = determineRequiredStatus(ann);
424-
currElements.add(new AutowiredFieldElement(field, required));
425-
}
426-
});
415+
AnnotationAttributes ann = findAutowiredAnnotation(field);
416+
if (ann != null) {
417+
if (Modifier.isStatic(field.getModifiers())) {
418+
if (logger.isWarnEnabled()) {
419+
logger.warn("Autowired annotation is not supported on static fields: " + field);
420+
}
421+
return;
422+
}
423+
boolean required = determineRequiredStatus(ann);
424+
currElements.add(new AutowiredFieldElement(field, required));
425+
}
426+
});
427427

428428
ReflectionUtils.doWithLocalMethods(targetClass, method -> {
429-
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
430-
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
431-
return;
432-
}
433-
AnnotationAttributes ann = findAutowiredAnnotation(bridgedMethod);
434-
if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
435-
if (Modifier.isStatic(method.getModifiers())) {
436-
if (logger.isWarnEnabled()) {
437-
logger.warn("Autowired annotation is not supported on static methods: " + method);
438-
}
439-
return;
440-
}
441-
if (method.getParameterCount() == 0) {
442-
if (logger.isWarnEnabled()) {
443-
logger.warn("Autowired annotation should only be used on methods with parameters: " +
444-
method);
445-
}
446-
}
447-
boolean required = determineRequiredStatus(ann);
448-
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
449-
currElements.add(new AutowiredMethodElement(method, required, pd));
450-
}
451-
});
429+
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(method);
430+
if (!BridgeMethodResolver.isVisibilityBridgeMethodPair(method, bridgedMethod)) {
431+
return;
432+
}
433+
AnnotationAttributes ann = findAutowiredAnnotation(bridgedMethod);
434+
if (ann != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
435+
if (Modifier.isStatic(method.getModifiers())) {
436+
if (logger.isWarnEnabled()) {
437+
logger.warn("Autowired annotation is not supported on static methods: " + method);
438+
}
439+
return;
440+
}
441+
if (method.getParameterCount() == 0) {
442+
if (logger.isWarnEnabled()) {
443+
logger.warn("Autowired annotation should only be used on methods with parameters: " +
444+
method);
445+
}
446+
}
447+
boolean required = determineRequiredStatus(ann);
448+
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, clazz);
449+
currElements.add(new AutowiredMethodElement(method, required, pd));
450+
}
451+
});
452452

453453
elements.addAll(0, currElements);
454454
targetClass = targetClass.getSuperclass();

spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java

Lines changed: 1 addition & 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-2017 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.

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2017 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.

spring-context/src/main/java/org/springframework/cache/annotation/AnnotationCacheOperationSource.java

Lines changed: 1 addition & 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-2017 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.

spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 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.

spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ else if (ejbRefClass != null && field.isAnnotationPresent(ejbRefClass)) {
363363
throw new IllegalStateException("@EJB annotation is not supported on static fields");
364364
}
365365
currElements.add(new EjbRefElement(field, field, null));
366-
}
366+
}
367367
else if (field.isAnnotationPresent(Resource.class)) {
368368
if (Modifier.isStatic(field.getModifiers())) {
369369
throw new IllegalStateException("@Resource annotation is not supported on static fields");

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import java.beans.PropertyDescriptor;
2020
import java.util.ArrayList;
2121
import java.util.Arrays;
22-
import java.util.Collections;
23-
import java.util.Comparator;
2422
import java.util.HashSet;
2523
import java.util.LinkedHashMap;
2624
import java.util.LinkedHashSet;
@@ -280,7 +278,7 @@ else if (ConfigurationClassUtils.checkConfigurationClassCandidate(beanDef, this.
280278
}
281279

282280
// Sort by previously determined @Order value, if applicable
283-
Collections.sort(configCandidates, (bd1, bd2) -> {
281+
configCandidates.sort((bd1, bd2) -> {
284282
int i1 = ConfigurationClassUtils.getOrder(bd1.getBeanDefinition());
285283
int i2 = ConfigurationClassUtils.getOrder(bd2.getBeanDefinition());
286284
return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0;

spring-core/src/main/java/org/springframework/util/ReflectionUtils.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@
4747
*/
4848
public abstract class ReflectionUtils {
4949

50-
/**
51-
* Pre-built FieldFilter that matches all non-static, non-final fields.
52-
*/
53-
public static final FieldFilter COPYABLE_FIELDS =
54-
field -> !(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()));
55-
5650
/**
5751
* Naming prefix for CGLIB-renamed methods.
5852
* @see #isCglibRenamedMethod
@@ -851,6 +845,13 @@ public interface FieldFilter {
851845
}
852846

853847

848+
/**
849+
* Pre-built FieldFilter that matches all non-static, non-final fields.
850+
*/
851+
public static final FieldFilter COPYABLE_FIELDS =
852+
field -> !(Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers()));
853+
854+
854855
/**
855856
* Pre-built MethodFilter that matches all non-bridge methods.
856857
*/

spring-core/src/main/java/org/springframework/util/concurrent/CompletableToListenableFutureAdapter.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import java.util.concurrent.ExecutionException;
2222
import java.util.concurrent.TimeUnit;
2323
import java.util.concurrent.TimeoutException;
24-
import java.util.function.BiFunction;
25-
26-
import org.springframework.lang.Nullable;
2724

2825
/**
2926
* Adapts a {@link CompletableFuture} or {@link CompletionStage} into a
@@ -53,9 +50,9 @@ public CompletableToListenableFutureAdapter(CompletionStage<T> completionStage)
5350
*/
5451
public CompletableToListenableFutureAdapter(CompletableFuture<T> completableFuture) {
5552
this.completableFuture = completableFuture;
56-
this.completableFuture.handle((result, exception) -> {
57-
if (exception != null) {
58-
callbacks.failure(exception);
53+
this.completableFuture.handle((result, ex) -> {
54+
if (ex != null) {
55+
callbacks.failure(ex);
5956
}
6057
else {
6158
callbacks.success(result);

spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Collections;
2121
import java.util.List;
2222

23-
import org.springframework.asm.ClassWriter;
2423
import org.springframework.asm.MethodVisitor;
2524
import org.springframework.expression.EvaluationException;
2625
import org.springframework.expression.TypedValue;
@@ -137,10 +136,11 @@ public void generateCode(MethodVisitor mv, CodeFlow codeflow) {
137136
final String constantFieldName = "inlineList$" + codeflow.nextFieldId();
138137
final String className = codeflow.getClassName();
139138

140-
codeflow.registerNewField((cw, codeflow1)
141-
-> cw.visitField(ACC_PRIVATE|ACC_STATIC|ACC_FINAL, constantFieldName, "Ljava/util/List;", null, null));
142-
143-
codeflow.registerNewClinit((mv1, codeflow12) -> generateClinitCode(className, constantFieldName, mv1, codeflow12, false));
139+
codeflow.registerNewField((cw, cflow) ->
140+
cw.visitField(ACC_PRIVATE | ACC_STATIC | ACC_FINAL, constantFieldName, "Ljava/util/List;", null, null));
141+
142+
codeflow.registerNewClinit((mVisitor, cflow) ->
143+
generateClinitCode(className, constantFieldName, mVisitor, cflow, false));
144144

145145
mv.visitFieldInsn(GETSTATIC, className, constantFieldName, "Ljava/util/List;");
146146
codeflow.pushDescriptor("Ljava/util/List");

spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.util.ArrayList;
2222
import java.util.Arrays;
2323
import java.util.Collection;
24-
import java.util.Collections;
25-
import java.util.Comparator;
2624
import java.util.HashMap;
2725
import java.util.LinkedHashSet;
2826
import java.util.List;
@@ -121,7 +119,7 @@ public MethodExecutor resolve(EvaluationContext context, Object targetObject, St
121119

122120
// Sort methods into a sensible order
123121
if (methods.size() > 1) {
124-
Collections.sort(methods, (m1, m2) -> {
122+
methods.sort((m1, m2) -> {
125123
int m1pl = m1.getParameterCount();
126124
int m2pl = m2.getParameterCount();
127125
// varargs methods go last

spring-jdbc/src/main/java/org/springframework/jdbc/config/SortedResourcesFactoryBean.java

Lines changed: 1 addition & 2 deletions
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-2017 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.ArrayList;
2121
import java.util.Arrays;
2222
import java.util.Collections;
23-
import java.util.Comparator;
2423
import java.util.List;
2524

2625
import org.springframework.beans.factory.FactoryBean;

spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@
1616

1717
package org.springframework.jdbc.core.support;
1818

19-
import java.sql.ResultSet;
20-
import java.sql.SQLException;
2119
import java.util.Properties;
2220
import javax.sql.DataSource;
2321

2422
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
2523
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
2624
import org.springframework.jdbc.core.JdbcTemplate;
27-
import org.springframework.jdbc.core.RowCallbackHandler;
2825
import org.springframework.util.Assert;
2926

3027
/**
@@ -105,10 +102,10 @@ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
105102
public void loadBeanDefinitions(String sql) {
106103
Assert.notNull(this.jdbcTemplate, "Not fully configured - specify DataSource or JdbcTemplate");
107104
final Properties props = new Properties();
108-
this.jdbcTemplate.query(sql, resultSet -> {
109-
String beanName = resultSet.getString(1);
110-
String property = resultSet.getString(2);
111-
String value = resultSet.getString(3);
105+
this.jdbcTemplate.query(sql, rs -> {
106+
String beanName = rs.getString(1);
107+
String property = rs.getString(2);
108+
String value = rs.getString(3);
112109
// Make a properties entry by combining bean name and property.
113110
props.setProperty(beanName + '.' + property, value);
114111
});

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,9 @@ public void afterConnected(TcpConnection<byte[]> connection) {
586586
}
587587
this.tcpConnection = connection;
588588
this.tcpConnection.onReadInactivity(() -> {
589-
if (tcpConnection != null && !isStompConnected) {
589+
if (this.tcpConnection != null && !this.isStompConnected) {
590590
handleTcpConnectionFailure("No CONNECTED frame received in " +
591-
MAX_TIME_TO_CONNECTED_FRAME + " ms.", null);
591+
MAX_TIME_TO_CONNECTED_FRAME + " ms.", null);
592592
}
593593
}, MAX_TIME_TO_CONNECTED_FRAME);
594594
connection.send(MessageBuilder.createMessage(EMPTY_PAYLOAD, this.connectHeaders.getMessageHeaders()));
@@ -697,18 +697,19 @@ private void initHeartbeats(StompHeaderAccessor connectedHeaders) {
697697
long serverReceiveInterval = connectedHeaders.getHeartbeat()[1];
698698

699699
if (clientSendInterval > 0 && serverReceiveInterval > 0) {
700-
long interval = Math.max(clientSendInterval, serverReceiveInterval);
700+
long interval = Math.max(clientSendInterval, serverReceiveInterval);
701701
this.tcpConnection.onWriteInactivity(() -> {
702-
TcpConnection<byte[]> conn = tcpConnection;
702+
TcpConnection<byte[]> conn = this.tcpConnection;
703703
if (conn != null) {
704704
conn.send(HEARTBEAT_MESSAGE).addCallback(
705-
new ListenableFutureCallback<Void>() {
706-
public void onSuccess(Void result) {
707-
}
708-
public void onFailure(Throwable ex) {
709-
handleTcpConnectionFailure("Failed to forward heartbeat: " + ex.getMessage(), ex);
710-
}
711-
});
705+
new ListenableFutureCallback<Void>() {
706+
public void onSuccess(Void result) {
707+
}
708+
709+
public void onFailure(Throwable ex) {
710+
handleTcpConnectionFailure("Failed to forward heartbeat: " + ex.getMessage(), ex);
711+
}
712+
});
712713
}
713714
}, interval);
714715
}

spring-orm/src/main/java/org/springframework/orm/jpa/AbstractEntityManagerFactoryBean.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.Map;
3131
import java.util.Properties;
3232
import java.util.Set;
33-
import java.util.concurrent.Callable;
3433
import java.util.concurrent.ExecutionException;
3534
import java.util.concurrent.Future;
3635
import javax.persistence.EntityManager;
@@ -350,7 +349,8 @@ public final void afterPropertiesSet() throws PersistenceException {
350349
}
351350

352351
if (this.bootstrapExecutor != null) {
353-
this.nativeEntityManagerFactoryFuture = this.bootstrapExecutor.submit(this::buildNativeEntityManagerFactory);
352+
this.nativeEntityManagerFactoryFuture = this.bootstrapExecutor.submit(
353+
this::buildNativeEntityManagerFactory);
354354
}
355355
else {
356356
this.nativeEntityManagerFactory = buildNativeEntityManagerFactory();

0 commit comments

Comments
 (0)