Use lambdas when possible
Replace anonymous inner classes with lambda declarations (when possible using method references). See gh-9781
This commit is contained in:
committed by
Phillip Webb
parent
d16af43664
commit
2626a3a795
@@ -136,14 +136,7 @@ public class LocalDevToolsAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public FileSystemWatcherFactory fileSystemWatcherFactory() {
|
||||
return new FileSystemWatcherFactory() {
|
||||
|
||||
@Override
|
||||
public FileSystemWatcher getFileSystemWatcher() {
|
||||
return newFileSystemWatcher();
|
||||
}
|
||||
|
||||
};
|
||||
return this::newFileSystemWatcher;
|
||||
}
|
||||
|
||||
private FileSystemWatcher newFileSystemWatcher() {
|
||||
|
||||
@@ -89,14 +89,7 @@ public class LiveReloadServer {
|
||||
* @param port the listen port
|
||||
*/
|
||||
public LiveReloadServer(int port) {
|
||||
this(port, new ThreadFactory() {
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable runnable) {
|
||||
return new Thread(runnable);
|
||||
}
|
||||
|
||||
});
|
||||
this(port, Thread::new);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,14 +114,7 @@ public class LiveReloadServer {
|
||||
logger.debug("Starting live reload server on port " + this.port);
|
||||
this.serverSocket = new ServerSocket(this.port);
|
||||
int localPort = this.serverSocket.getLocalPort();
|
||||
this.listenThread = this.threadFactory.newThread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
acceptConnections();
|
||||
}
|
||||
|
||||
});
|
||||
this.listenThread = this.threadFactory.newThread(this::acceptConnections);
|
||||
this.listenThread.setDaemon(true);
|
||||
this.listenThread.setName("Live Reload Server");
|
||||
this.listenThread.start();
|
||||
|
||||
@@ -194,14 +194,7 @@ public class RemoteClientConfiguration {
|
||||
|
||||
@Bean
|
||||
public FileSystemWatcherFactory getFileSystemWatcherFactory() {
|
||||
return new FileSystemWatcherFactory() {
|
||||
|
||||
@Override
|
||||
public FileSystemWatcher getFileSystemWatcher() {
|
||||
return newFileSystemWatcher();
|
||||
}
|
||||
|
||||
};
|
||||
return this::newFileSystemWatcher;
|
||||
}
|
||||
|
||||
private FileSystemWatcher newFileSystemWatcher() {
|
||||
|
||||
@@ -30,14 +30,7 @@ public interface AccessManager {
|
||||
/**
|
||||
* {@link AccessManager} that permits all requests.
|
||||
*/
|
||||
AccessManager PERMIT_ALL = new AccessManager() {
|
||||
|
||||
@Override
|
||||
public boolean isAllowed(ServerHttpRequest request) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
AccessManager PERMIT_ALL = (request) -> true;
|
||||
|
||||
/**
|
||||
* Determine if the specific request is allowed to be handled by the
|
||||
|
||||
@@ -28,14 +28,7 @@ public interface FailureHandler {
|
||||
/**
|
||||
* {@link FailureHandler} that always aborts.
|
||||
*/
|
||||
FailureHandler NONE = new FailureHandler() {
|
||||
|
||||
@Override
|
||||
public Outcome handle(Throwable failure) {
|
||||
return Outcome.ABORT;
|
||||
}
|
||||
|
||||
};
|
||||
FailureHandler NONE = (failure) -> Outcome.ABORT;
|
||||
|
||||
/**
|
||||
* Handle a run failure. Implementations may block, for example to wait until specific
|
||||
|
||||
@@ -31,14 +31,7 @@ public interface RestartInitializer {
|
||||
/**
|
||||
* {@link RestartInitializer} that doesn't return any URLs.
|
||||
*/
|
||||
RestartInitializer NONE = new RestartInitializer() {
|
||||
|
||||
@Override
|
||||
public URL[] getInitialUrls(Thread thread) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
RestartInitializer NONE = (thread) -> null;
|
||||
|
||||
/**
|
||||
* Return the initial set of URLs for the {@link Restarter} or {@code null} if no
|
||||
|
||||
@@ -167,15 +167,10 @@ public class Restarter {
|
||||
|
||||
private void immediateRestart() {
|
||||
try {
|
||||
getLeakSafeThread().callAndWait(new Callable<Void>() {
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
start(FailureHandler.NONE);
|
||||
cleanupCaches();
|
||||
return null;
|
||||
}
|
||||
|
||||
getLeakSafeThread().callAndWait(() -> {
|
||||
start(FailureHandler.NONE);
|
||||
cleanupCaches();
|
||||
return null;
|
||||
});
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@@ -251,15 +246,10 @@ public class Restarter {
|
||||
return;
|
||||
}
|
||||
this.logger.debug("Restarting application");
|
||||
getLeakSafeThread().call(new Callable<Void>() {
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
Restarter.this.stop();
|
||||
Restarter.this.start(failureHandler);
|
||||
return null;
|
||||
}
|
||||
|
||||
getLeakSafeThread().call(() -> {
|
||||
Restarter.this.stop();
|
||||
Restarter.this.start(failureHandler);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -641,15 +631,10 @@ public class Restarter {
|
||||
|
||||
@Override
|
||||
public Thread newThread(final Runnable runnable) {
|
||||
return getLeakSafeThread().callAndWait(new Callable<Thread>() {
|
||||
|
||||
@Override
|
||||
public Thread call() throws Exception {
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.setContextClassLoader(Restarter.this.applicationClassLoader);
|
||||
return thread;
|
||||
}
|
||||
|
||||
return getLeakSafeThread().callAndWait(() -> {
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.setContextClassLoader(Restarter.this.applicationClassLoader);
|
||||
return thread;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -31,14 +31,7 @@ public interface ClassLoaderFileRepository {
|
||||
/**
|
||||
* Empty {@link ClassLoaderFileRepository} implementation.
|
||||
*/
|
||||
ClassLoaderFileRepository NONE = new ClassLoaderFileRepository() {
|
||||
|
||||
@Override
|
||||
public ClassLoaderFile getFile(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
ClassLoaderFileRepository NONE = (name) -> null;
|
||||
|
||||
/**
|
||||
* Return a {@link ClassLoaderFile} for the given name or {@code null} if no file is
|
||||
|
||||
@@ -126,12 +126,8 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
|
||||
if (file.getKind() == Kind.DELETED) {
|
||||
return null;
|
||||
}
|
||||
return AccessController.doPrivileged(new PrivilegedAction<URL>() {
|
||||
@Override
|
||||
public URL run() {
|
||||
return createFileUrl(name, file);
|
||||
}
|
||||
});
|
||||
return AccessController
|
||||
.doPrivileged((PrivilegedAction<URL>) () -> createFileUrl(name, file));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -167,12 +163,9 @@ public class RestartClassLoader extends URLClassLoader implements SmartClassLoad
|
||||
if (file.getKind() == Kind.DELETED) {
|
||||
throw new ClassNotFoundException(name);
|
||||
}
|
||||
return AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {
|
||||
@Override
|
||||
public Class<?> run() {
|
||||
byte[] bytes = file.getContents();
|
||||
return defineClass(name, bytes, 0, bytes.length);
|
||||
}
|
||||
return AccessController.doPrivileged((PrivilegedAction<Class<?>>) () -> {
|
||||
byte[] bytes = file.getContents();
|
||||
return defineClass(name, bytes, 0, bytes.length);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user