Skip to content

Commit

Permalink
Replace all usages of Arrays.asList with List.of where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
baldersheim committed Apr 12, 2024
1 parent 7e7ebf7 commit 76a89b6
Show file tree
Hide file tree
Showing 310 changed files with 1,042 additions and 1,224 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collection;
import java.util.Deque;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarEntry;
Expand All @@ -24,7 +24,7 @@ public static ClassFileTree fromJar(JarFile jarFile) {
while (jarEntries.hasMoreElements()) {
JarEntry entry = jarEntries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
Deque<String> parts = new ArrayDeque<>(Arrays.asList(entry.getName().split("/")));
Deque<String> parts = new ArrayDeque<>(List.of(entry.getName().split("/")));
String className = parts.removeLast();
Package pkg = rootPackages
.computeIfAbsent(parts.removeFirst(), name -> new Package(null, name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

import com.yahoo.abicheck.collector.Util;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
import org.objectweb.asm.Opcodes;

import java.util.List;

public class AccessConversionTest {

@Test
public void testClassFlags() {
// ACC_SUPER should be ignored
assertEquals(
Arrays.asList("public", "abstract"),
List.of("public", "abstract"),
Util.convertAccess(
Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER | Opcodes.ACC_ABSTRACT,
Util.classFlags));
Expand All @@ -25,7 +26,7 @@ public void testClassFlags() {
public void testMethodFlags() {
// ACC_DEPRECATED should be ignored
assertEquals(
Arrays.asList("protected", "varargs"),
List.of("protected", "varargs"),
Util.convertAccess(
Opcodes.ACC_PROTECTED | Opcodes.ACC_VARARGS | Opcodes.ACC_DEPRECATED,
Util.methodFlags));
Expand All @@ -34,7 +35,7 @@ public void testMethodFlags() {
@Test
public void testFieldFlags() {
assertEquals(
Arrays.asList("private", "volatile"),
List.of("private", "volatile"),
Util.convertAccess(
Opcodes.ACC_PRIVATE | Opcodes.ACC_VOLATILE,
Util.fieldFlags));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import com.yahoo.abicheck.classtree.ClassFileTree;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import org.junit.jupiter.api.Test;
Expand All @@ -27,7 +27,7 @@ public void testJarParsing() throws IOException {
JarEntry dirJarEntry = new JarEntry("com/yahoo/");
InputStream jarEntryStream = mock(InputStream.class);
when(jarFile.entries())
.thenReturn(Collections.enumeration(Arrays.asList(dirJarEntry, classJarEntry)));
.thenReturn(Collections.enumeration(List.of(dirJarEntry, classJarEntry)));
when(jarFile.getInputStream(classJarEntry)).thenReturn(jarEntryStream);

try (ClassFileTree cft = ClassFileTree.fromJar(jarFile)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.yahoo.abicheck.classtree.ClassFileTree;
import com.yahoo.abicheck.signature.JavaClassSignature;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -32,7 +31,7 @@ private static ClassFileTree.Package buildClassFileTree() throws IOException {
ClassFileTree.ClassFile subPkgClass = mock(ClassFileTree.ClassFile.class);

when(rootPkg.getSubPackages()).thenReturn(Set.of(subPkg));
when(rootPkg.getClassFiles()).thenReturn(Arrays.asList(rootPkgClass, rootPkgInfoClass));
when(rootPkg.getClassFiles()).thenReturn(List.of(rootPkgClass, rootPkgInfoClass));
when(subPkg.getClassFiles()).thenReturn(Set.of(subPkgClass));

when(rootPkgInfoClass.getName()).thenReturn("package-info.class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -56,7 +55,7 @@ private static List<String> nonPublicApiPackages(File jarFile) {
var manifest = getOsgiManifest(jarFile);
if (manifest == null) return List.of();
return getMainAttributeValue(manifest, "X-JDisc-Non-PublicApi-Export-Package")
.map(s -> Arrays.asList(s.split(",")))
.map(s -> List.of(s.split(",")))
.orElseGet(ArrayList::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;

Expand Down Expand Up @@ -55,9 +55,9 @@ public void visitAttribute(Attribute attribute) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
Analyze.getClassName(Type.getReturnType(desc)).ifPresent(imports::add);
Arrays.asList(Type.getArgumentTypes(desc)).forEach(argType -> Analyze.getClassName(argType).ifPresent(imports::add));
List.of(Type.getArgumentTypes(desc)).forEach(argType -> Analyze.getClassName(argType).ifPresent(imports::add));
if (exceptions != null) {
Arrays.asList(exceptions).forEach(ex -> Analyze.internalNameToClassName(ex).ifPresent(imports::add));
List.of(exceptions).forEach(ex -> Analyze.internalNameToClassName(ex).ifPresent(imports::add));
}

AnalyzeSignatureVisitor.analyzeMethod(signature, this);
Expand All @@ -83,7 +83,7 @@ public void visit(int version, int access, String name, String signature, String
}

addImportWithInternalName(superName);
Arrays.asList(interfaces).forEach(this::addImportWithInternalName);
List.of(interfaces).forEach(this::addImportWithInternalName);

AnalyzeSignatureVisitor.analyzeClass(signature, this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
Expand Down Expand Up @@ -70,7 +70,7 @@ public void visitMultiANewArrayInsn(String desc, int dims) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
addImportWithInternalName(owner);
Arrays.asList(Type.getArgumentTypes(desc)).forEach(this::addImport);
List.of(Type.getArgumentTypes(desc)).forEach(this::addImport);
addImport(Type.getReturnType(desc));
}

Expand Down Expand Up @@ -112,7 +112,7 @@ public void visitInvokeDynamicInsn(String name, String desc, Handle bootstrapMet
addImport((Type) arg);
} else if (arg instanceof Handle) {
addImportWithInternalName(((Handle) arg).getOwner());
Arrays.asList(Type.getArgumentTypes(desc)).forEach(this::addImport);
List.of(Type.getArgumentTypes(desc)).forEach(this::addImport);
} else if ( ! (arg instanceof Number) && ! (arg instanceof String)) {
throw new AssertionError("Unexpected type " + arg.getClass() + " with value '" + arg + "'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -145,7 +145,7 @@ static String releaseVersion(String mavenVersion) {
if (parts.length <= 3) {
return mavenVersion;
} else {
return stringJoin(Arrays.asList(parts).subList(0, 3), ".");
return stringJoin(List.of(parts).subList(0, 3), ".");
}
}
}
Expand Down
15 changes: 7 additions & 8 deletions client/src/test/java/ai/vespa/client/dsl/QTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -224,9 +223,9 @@ void wand_with_and_without_annotation() {
String q = Q.select("*")
.from("sd1")
.where(Q.wand("f1", stringIntMap("a", 1, "b", 2, "c", 3)))
.and(Q.wand("f2", Arrays.asList(Arrays.asList(1, 1), Arrays.asList(2, 2))))
.and(Q.wand("f2", List.of(List.of(1, 1), List.of(2, 2))))
.and(
Q.wand("f3", Arrays.asList(Arrays.asList(1, 1), Arrays.asList(2, 2)))
Q.wand("f3", List.of(List.of(1, 1), List.of(2, 2)))
.annotate(A.a("scoreThreshold", 0.13))
)
.build();
Expand Down Expand Up @@ -421,31 +420,31 @@ void contains_phrase_near_onear_equiv() {
{
String q1 = Q.p("f1").containsPhrase("p1", "p2", "p3")
.build();
String q2 = Q.p("f1").containsPhrase(Arrays.asList("p1", "p2", "p3"))
String q2 = Q.p("f1").containsPhrase(List.of("p1", "p2", "p3"))
.build();
assertEquals(q1, "yql=select * from sources * where f1 contains phrase(\"p1\", \"p2\", \"p3\")");
assertEquals(q2, "yql=select * from sources * where f1 contains phrase(\"p1\", \"p2\", \"p3\")");
}
{
String q1 = Q.p("f1").containsNear("p1", "p2", "p3")
.build();
String q2 = Q.p("f1").containsNear(Arrays.asList("p1", "p2", "p3"))
String q2 = Q.p("f1").containsNear(List.of("p1", "p2", "p3"))
.build();
assertEquals(q1, "yql=select * from sources * where f1 contains near(\"p1\", \"p2\", \"p3\")");
assertEquals(q2, "yql=select * from sources * where f1 contains near(\"p1\", \"p2\", \"p3\")");
}
{
String q1 = Q.p("f1").containsOnear("p1", "p2", "p3")
.build();
String q2 = Q.p("f1").containsOnear(Arrays.asList("p1", "p2", "p3"))
String q2 = Q.p("f1").containsOnear(List.of("p1", "p2", "p3"))
.build();
assertEquals(q1, "yql=select * from sources * where f1 contains onear(\"p1\", \"p2\", \"p3\")");
assertEquals(q2, "yql=select * from sources * where f1 contains onear(\"p1\", \"p2\", \"p3\")");
}
{
String q1 = Q.p("f1").containsEquiv("p1", "p2", "p3")
.build();
String q2 = Q.p("f1").containsEquiv(Arrays.asList("p1", "p2", "p3"))
String q2 = Q.p("f1").containsEquiv(List.of("p1", "p2", "p3"))
.build();
assertEquals(q1, "yql=select * from sources * where f1 contains equiv(\"p1\", \"p2\", \"p3\")");
assertEquals(q2, "yql=select * from sources * where f1 contains equiv(\"p1\", \"p2\", \"p3\")");
Expand Down Expand Up @@ -586,7 +585,7 @@ void set_group_syntax_string_directly() {

@Test
void arbitrary_annotations() {
Annotation a = A.a("a1", "v1", "a2", 2, "a3", stringObjMap("k", "v", "k2", 1), "a4", 4D, "a5", Arrays.asList(1, 2, 3));
Annotation a = A.a("a1", "v1", "a2", 2, "a3", stringObjMap("k", "v", "k2", 1), "a4", 4D, "a5", List.of(1, 2, 3));
assertEquals(a.toString(), "{\"a1\":\"v1\",\"a2\":2,\"a3\":{\"k\":\"v\",\"k2\":1},\"a4\":4.0,\"a5\":[1,2,3]}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import com.yahoo.vdslib.state.ClusterState;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -137,7 +137,7 @@ public Builder bucketSpaces(Set<String> bucketSpaces) {
}

public Builder bucketSpaces(String... bucketSpaces) {
return bucketSpaces(new TreeSet<>(Arrays.asList(bucketSpaces)));
return bucketSpaces(new TreeSet<>(List.of(bucketSpaces)));
}

public Builder explicitDerivedStates(Map<String, AnnotatedClusterState> derivedStates) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -221,7 +220,7 @@ protected List<DummyVdsNode> setUpVdsNodes(Timer timer, boolean startDisconnecte
}

static Set<Integer> asIntSet(Integer... idx) {
return new HashSet<>(Arrays.asList(idx));
return new HashSet<>(List.of(idx));
}

static Set<ConfiguredNode> asConfiguredNodes(Set<Integer> indices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import com.yahoo.vdslib.state.ClusterState;
import org.junit.jupiter.api.Test;


import java.util.Arrays;
import java.util.List;

import static com.yahoo.vespa.clustercontroller.core.NodeStateReason.MAY_HAVE_MERGES_PENDING;
import static com.yahoo.vespa.clustercontroller.core.NodeStateReason.NODE_TOO_UNSTABLE;
Expand Down Expand Up @@ -110,8 +112,8 @@ void node_state_reasons_are_used_as_baseline_in_default_bucket_space_state() {
@Test
void node_with_pending_merges_only_set_to_maintenance_if_eligible() {
Fixture f = new Fixture();
Arrays.asList(1, 2, 3).forEach(idx -> when(f.mockPendingChecker.mayHaveMergesPending(globalSpace(), idx)).thenReturn(true));
Arrays.asList(1, 2, 4).forEach(idx -> when(f.mockTransitionConstraint.maintenanceTransitionAllowed(idx)).thenReturn(false));
List.of(1, 2, 3).forEach(idx -> when(f.mockPendingChecker.mayHaveMergesPending(globalSpace(), idx)).thenReturn(true));
List.of(1, 2, 4).forEach(idx -> when(f.mockTransitionConstraint.maintenanceTransitionAllowed(idx)).thenReturn(false));
AnnotatedClusterState derived = f.deriver.derivedFrom(stateFromString("distributor:5 storage:5"), defaultSpace());
assertThat(derived, equalTo(AnnotatedClusterStateBuilder.ofState("distributor:5 storage:5 .3.s:m")
.reason(MAY_HAVE_MERGES_PENDING, 3).build()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static List<File> getBundleFiles(File bundleDir) {
if (!bundleDir.isDirectory()) {
return new ArrayList<>();
}
return Arrays.asList(bundleDir.listFiles((dir, name) -> name.endsWith(".jar")));
return List.of(bundleDir.listFiles((dir, name) -> name.endsWith(".jar")));
}

public List<DefEntry> getDefEntries() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import java.nio.file.Files;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -435,11 +434,11 @@ static List<File> getSearchDefinitionFiles(File appDir) {

File sdDir = applicationFile(appDir, SEARCH_DEFINITIONS_DIR.getRelative());
if (sdDir.isDirectory())
schemaFiles.addAll(Arrays.asList(sdDir.listFiles((dir, name) -> validSchemaFilename(name))));
schemaFiles.addAll(List.of(sdDir.listFiles((dir, name) -> validSchemaFilename(name))));

sdDir = applicationFile(appDir, SCHEMAS_DIR.getRelative());
if (sdDir.isDirectory())
schemaFiles.addAll(Arrays.asList(sdDir.listFiles((dir, name) -> validSchemaFilename(name))));
schemaFiles.addAll(List.of(sdDir.listFiles((dir, name) -> validSchemaFilename(name))));

return schemaFiles;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.yahoo.foo.StructtypesConfig.Simple.Gender.Enum.FEMALE;
Expand Down Expand Up @@ -176,7 +176,7 @@ static FunctionTestConfig.Builder createVariableAccessBuilder() {
doublearr(123.0).
stringarr("bar").
enumarr(Enumarr.VALUES).
refarr(Arrays.asList(":parent:", ":parent", "parent:")). // test collection based setter
refarr(List.of(":parent:", ":parent", "parent:")). // test collection based setter
fileArr("bin").
intMap("one", 1).
intMap("two", 2).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import static com.yahoo.test.FunctionTestConfig.BasicStruct;
Expand Down Expand Up @@ -136,7 +136,7 @@ private static FunctionTestConfig.Builder newBuilder() {
doublearr(123.0).
stringarr("bar").
enumarr(Enumarr.VALUES).
refarr(Arrays.asList(":parent:", ":parent", "parent:")). // test collection based setter
refarr(List.of(":parent:", ":parent", "parent:")). // test collection based setter
fileArr("bin").
urlArr(new UrlReference("http://docs.vespa.ai")).
modelArr(ModelReference.unresolved(Optional.empty(),
Expand Down
Loading

0 comments on commit 76a89b6

Please sign in to comment.