Skip to content
Permalink
Browse files
8266155: Convert java.base to use Stream.toList()
Reviewed-by: bpb, naoto, iris, chegar
  • Loading branch information
Ian Graves authored and pavelrappo committed Apr 30, 2021
1 parent c36c63a commit dd05158b24e8b399052a170ea9fe9ee6f65c0432
@@ -3824,7 +3824,7 @@ public String stripIndent() {
}
char lastChar = charAt(length - 1);
boolean optOut = lastChar == '\n' || lastChar == '\r';
List<String> lines = lines().collect(Collectors.toList());
List<String> lines = lines().toList();
final int outdent = optOut ? 0 : outdent(lines);
return lines.stream()
.map(line -> {
@@ -59,7 +59,6 @@
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.lang.invoke.LambdaForm.BasicType.V_TYPE;
@@ -6649,8 +6648,7 @@ public static MethodHandle loop(MethodHandle[]... clauses) {
iterationVariableTypes.add(in == null ? st.type().returnType() : in.type().returnType());
}
}
final List<Class<?>> commonPrefix = iterationVariableTypes.stream().filter(t -> t != void.class).
collect(Collectors.toList());
final List<Class<?>> commonPrefix = iterationVariableTypes.stream().filter(t -> t != void.class).toList();

// Step 1B: determine loop parameters (A...).
final List<Class<?>> commonSuffix = buildCommonSuffix(init, step, pred, fini, commonPrefix.size());
@@ -6779,11 +6777,11 @@ private static void loopChecks2(List<MethodHandle> step, List<MethodHandle> pred
int pc = h.type().parameterCount();
int tpsize = targetParams.size();
return pc < tpsize ? dropArguments0(h, pc, targetParams.subList(pc, tpsize)) : h;
}).collect(Collectors.toList());
}).toList();
}

private static List<MethodHandle> fixArities(List<MethodHandle> hs) {
return hs.stream().map(MethodHandle::asFixedArity).collect(Collectors.toList());
return hs.stream().map(MethodHandle::asFixedArity).toList();
}

/**
@@ -62,7 +62,6 @@
import java.util.jar.JarEntry;
import java.util.spi.ResourceBundleControlProvider;
import java.util.spi.ResourceBundleProvider;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jdk.internal.loader.BootLoader;
@@ -1514,13 +1513,10 @@ private static Control getDefaultControl(Module targetModule, String baseName) {

private static class ResourceBundleControlProviderHolder {
private static final PrivilegedAction<List<ResourceBundleControlProvider>> pa =
() -> {
return Collections.unmodifiableList(
ServiceLoader.load(ResourceBundleControlProvider.class,
ClassLoader.getSystemClassLoader()).stream()
.map(ServiceLoader.Provider::get)
.collect(Collectors.toList()));
};
() -> ServiceLoader.load(ResourceBundleControlProvider.class,
ClassLoader.getSystemClassLoader()).stream()
.map(ServiceLoader.Provider::get)
.toList();

private static final List<ResourceBundleControlProvider> CONTROL_PROVIDERS =
AccessController.doPrivileged(pa);
@@ -41,7 +41,6 @@
import java.util.StringJoiner;
import java.util.WeakHashMap;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import static java.util.Collections.*;

import jdk.internal.access.JavaLangAccess;
@@ -293,7 +292,7 @@ private void log(Class<?> caller, String what, Supplier<String> msgSupplier) {
List<StackWalker.StackFrame> stack = StackWalkerHolder.INSTANCE.walk(s ->
s.dropWhile(this::isJavaBase)
.limit(32)
.collect(Collectors.toList())
.toList()
);

// record usage if this is the first (or not recently recorded)
@@ -50,7 +50,6 @@
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jdk.internal.loader.Resource;
@@ -84,7 +83,7 @@ public ModulePatcher(Map<String, List<String>> input) {
String mn = e.getKey();
List<Path> paths = e.getValue().stream()
.map(Paths::get)
.collect(Collectors.toList());
.toList();
map.put(mn, paths);
}
this.map = map;
@@ -45,7 +45,6 @@
import java.util.function.Supplier;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.ZipFile;

@@ -274,7 +273,7 @@ private JarEntry getEntry(String name) {
// take snapshot to avoid async close
List<String> names = jf.versionedStream()
.map(JarEntry::getName)
.collect(Collectors.toList());
.toList();
return names.stream();
}

@@ -340,7 +339,7 @@ static JmodFile newJmodFile(Path path) {
List<String> names = jf.stream()
.filter(e -> e.section() == JmodFile.Section.CLASSES)
.map(JmodFile.Entry::name)
.collect(Collectors.toList());
.toList();
return names.stream();
}

@@ -39,7 +39,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

public class IPAddressUtil {
private static final int INADDR4SZ = 4;
@@ -359,7 +358,7 @@ private static InetAddress findScopedAddress(InetAddress address) {
.filter(a -> (a instanceof Inet6Address)
&& address.equals(a)
&& ((Inet6Address) a).getScopeId() != 0)
.collect(Collectors.toList());
.toList();
List<InetAddress> result;
try {
result = AccessController.doPrivileged(pa);
@@ -36,7 +36,6 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
* Implementation for BCP47 Locale matching
@@ -184,7 +183,7 @@
Collection<String> tags) {
Set<String> distinctTags = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
return tags.stream().filter(x -> distinctTags.add(x))
.collect(Collectors.toList());
.toList();
}

/**

0 comments on commit dd05158

Please sign in to comment.