Skip to content

Commit

Permalink
Unify on List.of
Browse files Browse the repository at this point in the history
  • Loading branch information
baldersheim committed Apr 11, 2024
1 parent 6923743 commit 2d6bbe0
Show file tree
Hide file tree
Showing 160 changed files with 368 additions and 507 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.jar.Manifest;
Expand Down Expand Up @@ -37,7 +36,7 @@ public static List<Export> exportedPackagesAggregated(Collection<File> jarFiles)

static List<Export> exportedPackages(File jarFile) {
var manifest = getOsgiManifest(jarFile);
if (manifest == null) return Collections.emptyList();
if (manifest == null) return List.of();
try {
return parseExports(manifest);
} catch (Exception e) {
Expand All @@ -55,7 +54,7 @@ public static List<String> nonPublicApiPackagesAggregated(Collection<File> jarFi

private static List<String> nonPublicApiPackages(File jarFile) {
var manifest = getOsgiManifest(jarFile);
if (manifest == null) return Collections.emptyList();
if (manifest == null) return List.of();
return getMainAttributeValue(manifest, "X-JDisc-Non-PublicApi-Export-Package")
.map(s -> Arrays.asList(s.split(",")))
.orElseGet(ArrayList::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.File;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.jar.JarFile;
Expand All @@ -25,8 +24,8 @@ public static List<ArtifactId> providedArtifactsFromManifest(File jarFile) {
.map(s -> Arrays.stream(s.split(","))
.map(ArtifactId::fromStringValue)
.toList())
.orElse(Collections.emptyList()))
.orElse(Collections.emptyList());
.orElse(List.of()))
.orElse(List.of());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.yahoo.container.plugin.osgi.ImportPackages.Import;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand All @@ -23,8 +22,8 @@
*/
public class ImportPackageTest {
private static final String PACKAGE_NAME = "com.yahoo.exported";
private final Set<String> referencedPackages = Collections.singleton(PACKAGE_NAME);
private final Map<String, Export> exports = exportByPackageName(new Export(List.of(PACKAGE_NAME), Collections.emptyList()));
private final Set<String> referencedPackages = Set.of(PACKAGE_NAME);
private final Map<String, Export> exports = exportByPackageName(new Export(List.of(PACKAGE_NAME), List.of()));
private final Map<String, Export> exportsWithVersion = exportByPackageName(
new Export(List.of(PACKAGE_NAME), List.of(new Parameter("version", "1.3"))));

Expand Down
3 changes: 1 addition & 2 deletions client/src/main/java/ai/vespa/client/dsl/Sources.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -19,7 +18,7 @@ public class Sources {
}

Sources(Select select, String searchDefinition) {
this(select, Collections.singletonList(searchDefinition));
this(select, List.of(searchDefinition));
}

Sources(Select select, String searchDefinition, String... others) {
Expand Down
12 changes: 6 additions & 6 deletions client/src/test/java/ai/vespa/client/dsl/QTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -498,24 +498,24 @@ void fuzzy_with_annotation() {

@Test
void use_contains_instead_of_contains_equiv_when_input_size_is_1() {
String q = Q.p("f1").containsEquiv(Collections.singletonList("p1"))
String q = Q.p("f1").containsEquiv(List.of("p1"))
.build();

assertEquals(q, "yql=select * from sources * where f1 contains \"p1\"");
}

@Test
void contains_phrase_near_onear_equiv_empty_list_should_throw_illegal_argument_exception() {
assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsPhrase(Collections.emptyList())
assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsPhrase(List.of())
.build());

assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsNear(Collections.emptyList())
assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsNear(List.of())
.build());

assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsOnear(Collections.emptyList())
assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsOnear(List.of())
.build());

assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsEquiv(Collections.emptyList())
assertThrows(IllegalArgumentException.class, () -> Q.p("f1").containsEquiv(List.of())
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public final boolean concerns(Environment environment) {
public abstract boolean concerns(Environment environment, Optional<RegionName> region);

/** Returns the zones deployed to in this step. */
public List<DeclaredZone> zones() { return Collections.emptyList(); }
public List<DeclaredZone> zones() { return List.of(); }

/** The delay introduced by this step (beyond the time it takes to execute the step). */
public Duration delay() { return Duration.ZERO; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static java.util.Collections.emptyList;

/**
* Configuration of notifications for deployment jobs.
*
Expand Down Expand Up @@ -59,7 +58,7 @@ public static Notifications of(Map<When, List<String>> emailAddressesByWhen, Map
/** Returns all email addresses to notify for the given condition. */
public Set<String> emailAddressesFor(When when) {
ImmutableSet.Builder<String> addresses = ImmutableSet.builder();
addresses.addAll(emailAddresses.getOrDefault(when, emptyList()));
addresses.addAll(emailAddresses.getOrDefault(when, List.of()));
for (When include : when.includes)
addresses.addAll(emailAddressesFor(include));
return addresses.build();
Expand All @@ -68,7 +67,7 @@ public Set<String> emailAddressesFor(When when) {
/** Returns all roles for which email notification is to be sent for the given condition. */
public Set<Role> emailRolesFor(When when) {
ImmutableSet.Builder<Role> roles = ImmutableSet.builder();
roles.addAll(emailRoles.getOrDefault(when, emptyList()));
roles.addAll(emailRoles.getOrDefault(when, List.of()));
for (When include : when.includes)
roles.addAll(emailRolesFor(include));
return roles.build();
Expand All @@ -81,17 +80,17 @@ public enum Role {
author;

public static String toValue(Role role) {
switch (role) {
case author: return "author";
default: throw new IllegalArgumentException("Unexpected constant '" + role.name() + "'.");
if (Objects.requireNonNull(role) == Role.author) {
return "author";
}
throw new IllegalArgumentException("Unexpected constant '" + role.name() + "'.");
}

public static Role fromValue(String value) {
switch (value) {
case "author": return author;
default: throw new IllegalArgumentException("Unknown value '" + value + "'.");
if (value.equals("author")) {
return author;
}
throw new IllegalArgumentException("Unknown value '" + value + "'.");
}

}
Expand All @@ -112,11 +111,11 @@ public enum When {
}

public static String toValue(When when) {
switch (when) {
case failing: return "failing";
case failingCommit: return "failing-commit";
default: throw new IllegalArgumentException("Unexpected constant '" + when.name() + "'.");
}
return switch (when) {
case failing -> "failing";
case failingCommit -> "failing-commit";
default -> throw new IllegalArgumentException("Unexpected constant '" + when.name() + "'.");
};
}

public static When fromValue(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -1152,7 +1151,7 @@ public void noEndpoints() {
<instance id='default'/>
</deployment>
""");
assertEquals(Collections.emptyList(), spec.requireInstance("default").endpoints());
assertEquals(List.of(), spec.requireInstance("default").endpoints());
assertEquals(ZoneEndpoint.defaultEndpoint, spec.zoneEndpoint(InstanceName.defaultName(),
defaultId(),
ClusterSpec.Id.from("cluster")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -599,7 +598,7 @@ public void customTesterFlavor() {
@Test
public void emptyEndpoints() {
var spec = DeploymentSpec.fromXml("<deployment><endpoints/></deployment>");
assertEquals(Collections.emptyList(), spec.requireInstance("default").endpoints());
assertEquals(List.of(), spec.requireInstance("default").endpoints());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.yahoo.component.Vtag;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down Expand Up @@ -45,10 +45,10 @@ void testSingleConditionFilter() {

@Test
void testMultiConditionFilter() {
HostFilter typeAndId = HostFilter.from(Collections.emptyList(),
Collections.emptyList(),
Collections.singletonList(ClusterSpec.Type.content),
Collections.singletonList(ClusterSpec.Id.from("type1")));
HostFilter typeAndId = HostFilter.from(List.of(),
List.of(),
List.of(ClusterSpec.Type.content),
List.of(ClusterSpec.Id.from("type1")));

assertFalse(typeAndId.matches("anyhost", "flavor", membership("content/anyType/0/0/stateful")));
assertFalse(typeAndId.matches("anyhost", "flavor", membership("container/type1/0/0")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.yahoo.vespa.config.RawConfig;
import com.yahoo.vespa.config.protocol.JRTServerConfigRequest;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
Expand Down Expand Up @@ -56,7 +55,7 @@ public String getActiveSourceConnection() {

@Override
public List<String> getSourceConnections() {
return Collections.singletonList("N/A");
return List.of("N/A");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.yahoo.vespa.config.protocol.Trace;
import com.yahoo.vespa.config.util.ConfigUtils;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand All @@ -30,7 +29,7 @@
public class ConfigTester {

private static final long defaultTimeout = 10000;
private static final List<String> defContent = Collections.singletonList("bar string");
private static final List<String> defContent = List.of("bar string");

static RawConfig fooConfig;
static RawConfig barConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.yahoo.vespa.config.RawConfig;
import com.yahoo.vespa.config.protocol.JRTServerConfigRequest;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -51,7 +50,7 @@ public String getActiveSourceConnection() {

@Override
public List<String> getSourceConnections() {
return Collections.singletonList("N/A");
return List.of("N/A");
}

@Override
Expand Down
3 changes: 1 addition & 2 deletions config/src/main/java/com/yahoo/vespa/config/RawConfig.java
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.yahoo.vespa.config.protocol.VespaVersion;
import com.yahoo.vespa.config.util.ConfigUtils;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -40,7 +39,7 @@ public class RawConfig extends ConfigInstance {
* @param defMd5 The md5 sum of the .def-file.
*/
public RawConfig(ConfigKey<?> key, String defMd5) {
this(key, defMd5, null, PayloadChecksums.empty(), 0L, false, 0, Collections.emptyList(), Optional.empty());
this(key, defMd5, null, PayloadChecksums.empty(), 0L, false, 0, List.of(), Optional.empty());
}

public RawConfig(ConfigKey<?> key, String defMd5, Payload payload, PayloadChecksums payloadChecksums, long generation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.yahoo.vespa.config.TimingValues;
import org.junit.Test;

import java.util.Collections;
import java.util.List;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -78,7 +77,7 @@ public void testSubscribeInterface() {
@Test
public void testSubscribeWithException() {
TestConfigSubscriber sub = new TestConfigSubscriber();
ConfigSourceSet configSourceSet = new ConfigSourceSet(Collections.singletonList("tcp/localhost:99999"));
ConfigSourceSet configSourceSet = new ConfigSourceSet(List.of("tcp/localhost:99999"));
try {
sub.subscribe(SimpletypesConfig.class, "configid", configSourceSet, new TimingValues().setSubscribeTimeout(100));
fail();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import com.yahoo.vespa.config.server.http.v2.request.TenantRequest;
import com.yahoo.vespa.config.util.ConfigUtils;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;

Expand Down Expand Up @@ -190,7 +190,7 @@ public ConfigKey<?> getConfigKey() {

@Override
public DefContent getDefContent() {
return DefContent.fromList(Collections.emptyList());
return DefContent.fromList(List.of());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.nio.file.Paths;
import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.BooleanSupplier;
Expand Down Expand Up @@ -311,7 +310,7 @@ private List<Host> createHosts(String vespaVersion) {
}

private Host createHost(String hostname, String version) {
return new Host(hostname, Collections.emptyList(), Optional.empty(), Optional.of(com.yahoo.component.Version.fromString(version)));
return new Host(hostname, List.of(), Optional.empty(), Optional.of(com.yahoo.component.Version.fromString(version)));
}

private VipStatus createVipStatus(StateMonitor stateMonitor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -73,7 +73,7 @@ public void test_lb_config_simple() {
public void test_unknown_config_definition() {
PayloadChecksums payloadChecksums = PayloadChecksums.empty();
Request request = createWithParams(new ConfigKey<>("foo", "id", "bar", null),
DefContent.fromList(Collections.emptyList()), "fromHost",
DefContent.fromList(List.of()), "fromHost",
payloadChecksums, 1, 1, Trace.createDummy(),
CompressionType.UNCOMPRESSED, Optional.empty())
.getRequest();
Expand Down
Loading

0 comments on commit 2d6bbe0

Please sign in to comment.