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
@@ -57,9 +57,7 @@ import org.springframework.boot.cli.compiler.RepositoryConfigurationFactory;
|
||||
import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration;
|
||||
import org.springframework.boot.loader.tools.JarWriter;
|
||||
import org.springframework.boot.loader.tools.Layout;
|
||||
import org.springframework.boot.loader.tools.Libraries;
|
||||
import org.springframework.boot.loader.tools.Library;
|
||||
import org.springframework.boot.loader.tools.LibraryCallback;
|
||||
import org.springframework.boot.loader.tools.LibraryScope;
|
||||
import org.springframework.boot.loader.tools.Repackager;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -198,13 +196,9 @@ abstract class ArchiveCommand extends OptionParsingCommand {
|
||||
libraries.addAll(createLibraries(dependencies));
|
||||
Repackager repackager = new Repackager(file);
|
||||
repackager.setMainClass(PackagedSpringApplicationLauncher.class.getName());
|
||||
repackager.repackage(new Libraries() {
|
||||
|
||||
@Override
|
||||
public void doWithLibraries(LibraryCallback callback) throws IOException {
|
||||
for (Library library : libraries) {
|
||||
callback.library(library);
|
||||
}
|
||||
repackager.repackage((callback) -> {
|
||||
for (Library library : libraries) {
|
||||
callback.library(library);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -94,11 +94,7 @@ class ServiceCapabilitiesReportGenerator {
|
||||
|
||||
private List<Dependency> getSortedDependencies(InitializrServiceMetadata metadata) {
|
||||
ArrayList<Dependency> dependencies = new ArrayList<>(metadata.getDependencies());
|
||||
dependencies.sort(new Comparator<Dependency>() {
|
||||
@Override public int compare(Dependency o1, Dependency o2) {
|
||||
return o1.getId().compareTo(o2.getId());
|
||||
}
|
||||
});
|
||||
dependencies.sort(Comparator.comparing(Dependency::getId));
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
@@ -107,15 +103,7 @@ class ServiceCapabilitiesReportGenerator {
|
||||
report.append("Available project types:" + NEW_LINE);
|
||||
report.append("------------------------" + NEW_LINE);
|
||||
SortedSet<Entry<String, ProjectType>> entries = new TreeSet<>(
|
||||
new Comparator<Entry<String, ProjectType>>() {
|
||||
|
||||
@Override
|
||||
public int compare(Entry<String, ProjectType> o1,
|
||||
Entry<String, ProjectType> o2) {
|
||||
return o1.getKey().compareTo(o2.getKey());
|
||||
}
|
||||
|
||||
});
|
||||
Comparator.comparing(Entry::getKey));
|
||||
entries.addAll(metadata.getProjectTypes().entrySet());
|
||||
for (Entry<String, ProjectType> entry : entries) {
|
||||
ProjectType type = entry.getValue();
|
||||
|
||||
@@ -130,17 +130,10 @@ public class OptionHandler {
|
||||
|
||||
@Override
|
||||
public String format(Map<String, ? extends OptionDescriptor> options) {
|
||||
Comparator<OptionDescriptor> comparator = new Comparator<OptionDescriptor>() {
|
||||
@Override
|
||||
public int compare(OptionDescriptor first, OptionDescriptor second) {
|
||||
return first.options().iterator().next()
|
||||
.compareTo(second.options().iterator().next());
|
||||
}
|
||||
};
|
||||
|
||||
Comparator<OptionDescriptor> comparator = (first, second) -> first.options()
|
||||
.iterator().next().compareTo(second.options().iterator().next());
|
||||
Set<OptionDescriptor> sorted = new TreeSet<>(comparator);
|
||||
sorted.addAll(options.values());
|
||||
|
||||
for (OptionDescriptor descriptor : sorted) {
|
||||
if (!descriptor.representsNonOptions()) {
|
||||
this.help.add(new OptionHelpAdapter(descriptor));
|
||||
|
||||
@@ -119,12 +119,7 @@ public class Shell {
|
||||
}
|
||||
|
||||
private void attachSignalHandler() {
|
||||
SignalUtils.attachSignalHandler(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handleSigInt();
|
||||
}
|
||||
});
|
||||
SignalUtils.attachSignalHandler(this::handleSigInt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -122,23 +122,23 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader {
|
||||
|
||||
@Override
|
||||
public ClassCollector createCollector(CompilationUnit unit, SourceUnit su) {
|
||||
InnerLoader loader = AccessController
|
||||
.doPrivileged(new PrivilegedAction<InnerLoader>() {
|
||||
@Override
|
||||
public InnerLoader run() {
|
||||
return new InnerLoader(ExtendedGroovyClassLoader.this) {
|
||||
// Don't return URLs from the inner loader so that Tomcat only
|
||||
// searches the parent. Fixes 'TLD skipped' issues
|
||||
@Override
|
||||
public URL[] getURLs() {
|
||||
return NO_URLS;
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
InnerLoader loader = AccessController.doPrivileged(getInnerLoader());
|
||||
return new ExtendedClassCollector(loader, unit, su);
|
||||
}
|
||||
|
||||
private PrivilegedAction<InnerLoader> getInnerLoader() {
|
||||
return () -> new InnerLoader(ExtendedGroovyClassLoader.this) {
|
||||
|
||||
// Don't return URLs from the inner loader so that Tomcat only
|
||||
// searches the parent. Fixes 'TLD skipped' issues
|
||||
@Override
|
||||
public URL[] getURLs() {
|
||||
return NO_URLS;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public CompilerConfiguration getConfiguration() {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
@@ -100,19 +100,11 @@ public class AetherGrapeEngine implements GrapeEngine {
|
||||
|| Boolean.getBoolean("groovy.grape.report.downloads")) {
|
||||
return new DetailedProgressReporter(session, System.out);
|
||||
}
|
||||
else if ("none".equals(progressReporter)) {
|
||||
return new ProgressReporter() {
|
||||
|
||||
@Override
|
||||
public void finished() {
|
||||
|
||||
}
|
||||
|
||||
if ("none".equals(progressReporter)) {
|
||||
return () -> {
|
||||
};
|
||||
}
|
||||
else {
|
||||
return new SummaryProgressReporter(session, System.out);
|
||||
}
|
||||
return new SummaryProgressReporter(session, System.out);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user