Polish: anonymous inner classes containing only one method should become lambdas,
use getOrDefault instead of ternary operator
This commit is contained in:
parent
aa4bcedad3
commit
2be4985b8f
|
|
@ -306,13 +306,8 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
|||
protected static class SyntheticInstantiationAdvisor extends DefaultPointcutAdvisor {
|
||||
|
||||
public SyntheticInstantiationAdvisor(final MetadataAwareAspectInstanceFactory aif) {
|
||||
super(aif.getAspectMetadata().getPerClausePointcut(), new MethodBeforeAdvice() {
|
||||
@Override
|
||||
public void before(Method method, Object[] args, @Nullable Object target) {
|
||||
// Simply instantiate the aspect
|
||||
aif.getAspectInstance();
|
||||
}
|
||||
});
|
||||
super(aif.getAspectMetadata().getPerClausePointcut(), (MethodBeforeAdvice)
|
||||
(method, args, target) -> aif.getAspectInstance());// Simply instantiate the aspect
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import java.lang.reflect.Proxy;
|
|||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.BeanMetadataElement;
|
||||
|
|
@ -58,19 +57,16 @@ abstract class AutowireUtils {
|
|||
* @param constructors the constructor array to sort
|
||||
*/
|
||||
public static void sortConstructors(Constructor<?>[] constructors) {
|
||||
Arrays.sort(constructors, new Comparator<Constructor<?>>() {
|
||||
@Override
|
||||
public int compare(Constructor<?> c1, Constructor<?> c2) {
|
||||
boolean p1 = Modifier.isPublic(c1.getModifiers());
|
||||
boolean p2 = Modifier.isPublic(c2.getModifiers());
|
||||
if (p1 != p2) {
|
||||
return (p1 ? -1 : 1);
|
||||
}
|
||||
int c1pl = c1.getParameterCount();
|
||||
int c2pl = c2.getParameterCount();
|
||||
return (c1pl < c2pl ? 1 : (c1pl > c2pl ? -1 : 0));
|
||||
}
|
||||
});
|
||||
Arrays.sort(constructors, (c1, c2) -> {
|
||||
boolean p1 = Modifier.isPublic(c1.getModifiers());
|
||||
boolean p2 = Modifier.isPublic(c2.getModifiers());
|
||||
if (p1 != p2) {
|
||||
return (p1 ? -1 : 1);
|
||||
}
|
||||
int c1pl = c1.getParameterCount();
|
||||
int c2pl = c2.getParameterCount();
|
||||
return (c1pl < c2pl ? 1 : (c1pl > c2pl ? -1 : 0));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,19 +77,16 @@ abstract class AutowireUtils {
|
|||
* @param factoryMethods the factory method array to sort
|
||||
*/
|
||||
public static void sortFactoryMethods(Method[] factoryMethods) {
|
||||
Arrays.sort(factoryMethods, new Comparator<Method>() {
|
||||
@Override
|
||||
public int compare(Method fm1, Method fm2) {
|
||||
boolean p1 = Modifier.isPublic(fm1.getModifiers());
|
||||
boolean p2 = Modifier.isPublic(fm2.getModifiers());
|
||||
if (p1 != p2) {
|
||||
return (p1 ? -1 : 1);
|
||||
}
|
||||
int c1pl = fm1.getParameterCount();
|
||||
int c2pl = fm2.getParameterCount();
|
||||
return (c1pl < c2pl ? 1 : (c1pl > c2pl ? -1 : 0));
|
||||
}
|
||||
});
|
||||
Arrays.sort(factoryMethods, (fm1, fm2) -> {
|
||||
boolean p1 = Modifier.isPublic(fm1.getModifiers());
|
||||
boolean p2 = Modifier.isPublic(fm2.getModifiers());
|
||||
if (p1 != p2) {
|
||||
return (p1 ? -1 : 1);
|
||||
}
|
||||
int c1pl = fm1.getParameterCount();
|
||||
int c2pl = fm2.getParameterCount();
|
||||
return (c1pl < c2pl ? 1 : (c1pl > c2pl ? -1 : 0));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -605,11 +605,7 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller {
|
|||
throws XmlMappingException, IOException;
|
||||
|
||||
|
||||
private static final EntityResolver NO_OP_ENTITY_RESOLVER = new EntityResolver() {
|
||||
@Override
|
||||
public InputSource resolveEntity(String publicId, String systemId) {
|
||||
return new InputSource(new StringReader(""));
|
||||
}
|
||||
};
|
||||
private static final EntityResolver NO_OP_ENTITY_RESOLVER =
|
||||
(publicId, systemId) -> new InputSource(new StringReader(""));
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
|
|||
* @see SimpleNamingContext
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public InitialContextFactory createInitialContextFactory(@Nullable Hashtable<?,?> environment) {
|
||||
if (activated == null && environment != null) {
|
||||
Object icf = environment.get(Context.INITIAL_CONTEXT_FACTORY);
|
||||
|
|
@ -225,13 +226,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder
|
|||
}
|
||||
|
||||
// Default case...
|
||||
return new InitialContextFactory() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Context getInitialContext(Hashtable<?,?> environment) {
|
||||
return new SimpleNamingContext("", boundObjects, (Hashtable<String, Object>) environment);
|
||||
}
|
||||
};
|
||||
return environment1 -> new SimpleNamingContext("", boundObjects, (Hashtable<String, Object>) environment1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package org.springframework.test.web.servlet.request;
|
|||
|
||||
import java.net.URI;
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
|
@ -269,15 +268,12 @@ public abstract class MockMvcRequestBuilders {
|
|||
// There must be an async result before dispatching
|
||||
mvcResult.getAsyncResult();
|
||||
|
||||
return new RequestBuilder() {
|
||||
@Override
|
||||
public MockHttpServletRequest buildRequest(ServletContext servletContext) {
|
||||
MockHttpServletRequest request = mvcResult.getRequest();
|
||||
request.setDispatcherType(DispatcherType.ASYNC);
|
||||
request.setAsyncStarted(false);
|
||||
return request;
|
||||
}
|
||||
};
|
||||
return servletContext -> {
|
||||
MockHttpServletRequest request = mvcResult.getRequest();
|
||||
request.setDispatcherType(DispatcherType.ASYNC);
|
||||
request.setAsyncStarted(false);
|
||||
return request;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,12 +99,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
|
|||
*/
|
||||
@Override
|
||||
protected Comparator<RequestMappingInfo> getMappingComparator(final HttpServletRequest request) {
|
||||
return new Comparator<RequestMappingInfo>() {
|
||||
@Override
|
||||
public int compare(RequestMappingInfo info1, RequestMappingInfo info2) {
|
||||
return info1.compareTo(info2, request);
|
||||
}
|
||||
};
|
||||
return (info1, info2) -> info1.compareTo(info2, request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -512,12 +512,7 @@ public class MvcUriComponentsBuilder {
|
|||
}
|
||||
|
||||
// We may not have all URI var values, expand only what we have
|
||||
return builder.build().expand(new UriComponents.UriTemplateVariables() {
|
||||
@Override
|
||||
public Object getValue(@Nullable String name) {
|
||||
return uriVars.containsKey(name) ? uriVars.get(name) : UriComponents.UriTemplateVariables.SKIP_VALUE;
|
||||
}
|
||||
});
|
||||
return builder.build().expand(name -> uriVars.getOrDefault(name, UriComponents.UriTemplateVariables.SKIP_VALUE));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
|||
|
|
@ -61,40 +61,20 @@ public class StandardWebSocketHandlerAdapter extends Endpoint {
|
|||
this.wsSession.initializeNativeSession(session);
|
||||
|
||||
if (this.handler.supportsPartialMessages()) {
|
||||
session.addMessageHandler(new MessageHandler.Partial<String>() {
|
||||
@Override
|
||||
public void onMessage(String message, boolean isLast) {
|
||||
handleTextMessage(session, message, isLast);
|
||||
}
|
||||
});
|
||||
session.addMessageHandler(new MessageHandler.Partial<ByteBuffer>() {
|
||||
@Override
|
||||
public void onMessage(ByteBuffer message, boolean isLast) {
|
||||
handleBinaryMessage(session, message, isLast);
|
||||
}
|
||||
});
|
||||
session.addMessageHandler((MessageHandler.Partial<String>)
|
||||
(message, isLast) -> handleTextMessage(session, message, isLast));
|
||||
session.addMessageHandler((MessageHandler.Partial<ByteBuffer>)
|
||||
(message, isLast) -> handleBinaryMessage(session, message, isLast));
|
||||
}
|
||||
else {
|
||||
session.addMessageHandler(new MessageHandler.Whole<String>() {
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
handleTextMessage(session, message, true);
|
||||
}
|
||||
});
|
||||
session.addMessageHandler(new MessageHandler.Whole<ByteBuffer>() {
|
||||
@Override
|
||||
public void onMessage(ByteBuffer message) {
|
||||
handleBinaryMessage(session, message, true);
|
||||
}
|
||||
});
|
||||
session.addMessageHandler((MessageHandler.Whole<String>)
|
||||
message -> handleTextMessage(session, message, true));
|
||||
session.addMessageHandler((MessageHandler.Whole<ByteBuffer>)
|
||||
message -> handleBinaryMessage(session, message, true));
|
||||
}
|
||||
|
||||
session.addMessageHandler(new MessageHandler.Whole<javax.websocket.PongMessage>() {
|
||||
@Override
|
||||
public void onMessage(javax.websocket.PongMessage message) {
|
||||
handlePongMessage(session, message.getApplicationData());
|
||||
}
|
||||
});
|
||||
session.addMessageHandler((MessageHandler.Whole<javax.websocket.PongMessage>)
|
||||
message -> handlePongMessage(session, message.getApplicationData()));
|
||||
|
||||
try {
|
||||
this.handler.afterConnectionEstablished(this.wsSession);
|
||||
|
|
|
|||
|
|
@ -422,21 +422,18 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
|
|||
public void onWriteInactivity(final Runnable runnable, final long duration) {
|
||||
Assert.state(getTaskScheduler() != null, "No TaskScheduler configured");
|
||||
this.lastWriteTime = System.currentTimeMillis();
|
||||
this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (System.currentTimeMillis() - lastWriteTime > duration) {
|
||||
try {
|
||||
runnable.run();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("WriteInactivityTask failure", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, duration / 2));
|
||||
this.inactivityTasks.add(getTaskScheduler().scheduleWithFixedDelay(() -> {
|
||||
if (System.currentTimeMillis() - lastWriteTime > duration) {
|
||||
try {
|
||||
runnable.run();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("WriteInactivityTask failure", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, duration / 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -30,9 +30,6 @@ import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
|||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.server.HandshakeRFC6455;
|
||||
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
|
||||
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
|
||||
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.core.NamedThreadLocal;
|
||||
|
|
@ -120,16 +117,13 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Serv
|
|||
if (this.factory == null) {
|
||||
this.factory = new WebSocketServerFactory(servletContext, this.policy);
|
||||
}
|
||||
this.factory.setCreator(new WebSocketCreator() {
|
||||
@Override
|
||||
public Object createWebSocket(ServletUpgradeRequest request, ServletUpgradeResponse response) {
|
||||
WebSocketHandlerContainer container = containerHolder.get();
|
||||
Assert.state(container != null, "Expected WebSocketHandlerContainer");
|
||||
response.setAcceptedSubProtocol(container.getSelectedProtocol());
|
||||
response.setExtensions(container.getExtensionConfigs());
|
||||
return container.getHandler();
|
||||
}
|
||||
});
|
||||
this.factory.setCreator((request, response) -> {
|
||||
WebSocketHandlerContainer container = containerHolder.get();
|
||||
Assert.state(container != null, "Expected WebSocketHandlerContainer");
|
||||
response.setAcceptedSubProtocol(container.getSelectedProtocol());
|
||||
response.setExtensions(container.getExtensionConfigs());
|
||||
return container.getHandler();
|
||||
});
|
||||
this.factory.start();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import javax.servlet.ServletRequest;
|
|||
import javax.servlet.ServletRequestWrapper;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.websocket.CloseReason;
|
||||
|
||||
import org.glassfish.tyrus.core.TyrusUpgradeResponse;
|
||||
import org.glassfish.tyrus.core.Utils;
|
||||
|
|
@ -56,11 +55,7 @@ public class WebLogicRequestUpgradeStrategy extends AbstractTyrusRequestUpgradeS
|
|||
|
||||
private static final WebLogicServletWriterHelper servletWriterHelper = new WebLogicServletWriterHelper();
|
||||
|
||||
private static final Connection.CloseListener noOpCloseListener = new Connection.CloseListener() {
|
||||
@Override
|
||||
public void close(CloseReason reason) {
|
||||
}
|
||||
};
|
||||
private static final Connection.CloseListener noOpCloseListener = reason -> { };
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Reference in New Issue