Skip to content

Commit

Permalink
Merge pull request #25096 from vespa-engine/revert-25091-revert-25088…
Browse files Browse the repository at this point in the history
…-balder/immutablelist-2-list

Revert "Revert "Let list handling catch up with Java 17""
  • Loading branch information
Harald Musum authored Dec 2, 2022
2 parents 7f870bf + fcf664e commit afcf1bb
Show file tree
Hide file tree
Showing 51 changed files with 262 additions and 415 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import java.net.InetAddress;
import java.security.PublicKey;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -119,10 +119,7 @@ private VespaUniqueInstanceId getVespaUniqueInstanceId(InstanceConfirmation inst
// Find a list of SAN DNS
List<String> sanDNS = Optional.ofNullable(instanceConfirmation.attributes.get(SAN_DNS_ATTRNAME))
.map(s -> s.split(","))
.map(Arrays::asList)
.map(List::stream)
.orElse(Stream.empty())
.collect(Collectors.toList());
.map(Arrays::asList).stream().flatMap(Collection::stream).toList();

return sanDNS.stream()
.filter(dns -> dns.contains(INSTANCE_ID_DELIMITER))
Expand Down Expand Up @@ -152,15 +149,13 @@ private boolean validateAttributes(InstanceConfirmation confirmation, VespaUniqu
// Find list of ipaddresses
List<InetAddress> ips = Optional.ofNullable(confirmation.attributes.get(SAN_IPS_ATTRNAME))
.map(s -> s.split(","))
.map(Arrays::asList)
.map(List::stream)
.orElse(Stream.empty())
.map(Arrays::asList).stream().flatMap(Collection::stream)
.map(InetAddresses::forString)
.collect(Collectors.toList());
.toList();

List<InetAddress> nodeIpAddresses = node.ipConfig().primary().stream()
.map(InetAddresses::forString)
.collect(Collectors.toList());
.toList();

// Validate that ipaddresses in request are valid for node

Expand All @@ -187,7 +182,7 @@ private boolean isSameIdentityAsInServicesXml(ApplicationId applicationId, Strin

Optional<ApplicationInfo> applicationInfo = superModelProvider.getSuperModel().getApplicationInfo(applicationId);

if (!applicationInfo.isPresent()) {
if (applicationInfo.isEmpty()) {
log.info(String.format("Could not find application info for %s, existing applications: %s",
applicationId.serializedForm(),
superModelProvider.getSuperModel().getAllApplicationInfos()));
Expand All @@ -207,7 +202,7 @@ private boolean isSameIdentityAsInServicesXml(ApplicationId applicationId, Strin
.filter(serviceInfo -> serviceInfo.getProperty(SERVICE_PROPERTIES_SERVICE_KEY).isPresent())
.findFirst();

if (!matchingServiceInfo.isPresent()) {
if (matchingServiceInfo.isEmpty()) {
log.info(String.format("Application %s has not specified domain/service", applicationId.serializedForm()));
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.athenz.instanceproviderservice;

import com.google.common.collect.ImmutableList;
import com.yahoo.component.Version;
import com.yahoo.config.model.api.ApplicationInfo;
import com.yahoo.config.model.api.HostInfo;
Expand Down Expand Up @@ -145,7 +144,7 @@ void accepts_valid_refresh_requests() {
nodeList = allocateNode(nodeList, node, applicationId);
when(nodes.list()).thenReturn(NodeList.copyOf(nodeList));
String nodeIp = node.ipConfig().primary().stream().findAny().orElseThrow(() -> new RuntimeException("No ipaddress for mocked node"));
InstanceConfirmation instanceConfirmation = createRefreshInstanceConfirmation(applicationId, domain, service, ImmutableList.of(nodeIp));
InstanceConfirmation instanceConfirmation = createRefreshInstanceConfirmation(applicationId, domain, service, List.of(nodeIp));

assertTrue(instanceValidator.isValidRefresh(instanceConfirmation));
}
Expand Down Expand Up @@ -179,7 +178,7 @@ void rejects_refresh_when_node_is_not_allocated() {
List<Node> nodeList = createNodes(10);

when(nodes.list()).thenReturn(NodeList.copyOf(nodeList));
InstanceConfirmation instanceConfirmation = createRefreshInstanceConfirmation(applicationId, domain, service, ImmutableList.of("::11"));
InstanceConfirmation instanceConfirmation = createRefreshInstanceConfirmation(applicationId, domain, service, List.of("::11"));

assertFalse(instanceValidator.isValidRefresh(instanceConfirmation));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.classanalysis;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Sets;
import com.yahoo.container.plugin.util.Maps;

Expand All @@ -21,7 +20,6 @@ public class PackageTally {
private final Map<String, Optional<ExportPackageAnnotation>> definedPackagesMap;
private final Set<String> referencedPackagesUnfiltered;

@VisibleForTesting
PackageTally(Map<String, Optional<ExportPackageAnnotation>> definedPackagesMap, Set<String> referencedPackagesUnfiltered) {
this.definedPackagesMap = definedPackagesMap;
this.referencedPackagesUnfiltered = referencedPackagesUnfiltered;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.plugin.classanalysis;

import com.google.common.collect.ImmutableList;
import com.yahoo.container.plugin.classanalysis.sampleclasses.Base;
import com.yahoo.container.plugin.classanalysis.sampleclasses.ClassAnnotation;
import com.yahoo.container.plugin.classanalysis.sampleclasses.InvisibleAnnotation;
Expand All @@ -25,6 +24,7 @@
import java.awt.image.Kernel;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import static com.yahoo.container.plugin.classanalysis.TestUtilities.analyzeClass;
import static com.yahoo.container.plugin.classanalysis.TestUtilities.classFile;
Expand Down Expand Up @@ -176,17 +176,17 @@ void attributes_are_included() {
@Test
void switch_statements_are_analyzed() {
var referencedClasses = analyzeClass(SwitchStatement.class).getReferencedClasses();
assertTrue(referencedClasses.contains(name(ImmutableList.class)));
assertTrue(referencedClasses.contains(name(List.class)));
assertTrue(referencedClasses.contains(name(IllegalArgumentException.class)));
}

@Test
void records_are_analyzed() {
var referencedClasses = analyzeClass(RecordWithOverride.class).getReferencedClasses();
assertTrue(referencedClasses.containsAll(List.of(
name(java.util.List.class),
name(List.class),
name(Byte.class),
name(ImmutableList.class),
name(String.class),
name(IllegalArgumentException.class)
)));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.yahoo.container.plugin.classanalysis.sampleclasses;

import com.google.common.collect.ImmutableList;

import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -13,7 +12,7 @@
public record RecordWithOverride(List<Byte> list) {

public RecordWithOverride {
if (list instanceof ImmutableList<Byte> l) {
if (list instanceof ArrayList<Byte> l) {
throw new IllegalArgumentException(l.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.yahoo.container.plugin.classanalysis.sampleclasses;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
* Input for class analysis test verifying Java 14 switch statement.
Expand All @@ -15,8 +14,8 @@ public class SwitchStatement {
void switchStatement() throws Exception{
String foo = "";
Collection<?> c = switch (foo) {
case "list" -> ImmutableList.of();
case "set" -> ImmutableSet.of();
case "list" -> List.of();
case "set" -> Set.of();
default -> throw new IllegalArgumentException();
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.admin;

import com.google.common.collect.ImmutableList;
import com.yahoo.config.model.ApplicationConfigProducerRoot;
import com.yahoo.config.model.ConfigModel;
import com.yahoo.config.model.ConfigModelContext;
Expand Down Expand Up @@ -65,8 +64,8 @@ private void verifyClusterControllersOnlyDefinedForContent(ConfigModelRepo confi
public static class BuilderV2 extends ConfigModelBuilder<AdminModel> {

public static final List<ConfigModelId> configModelIds =
ImmutableList.of(ConfigModelId.fromNameAndVersion("admin", "2.0"),
ConfigModelId.fromNameAndVersion("admin", "1.0"));
List.of(ConfigModelId.fromNameAndVersion("admin", "2.0"),
ConfigModelId.fromNameAndVersion("admin", "1.0"));

public BuilderV2() {
super(AdminModel.class);
Expand Down Expand Up @@ -98,8 +97,8 @@ public void doBuild(AdminModel model, Element adminElement, ConfigModelContext m
public static class BuilderV4 extends ConfigModelBuilder<AdminModel> {

public static final List<ConfigModelId> configModelIds =
ImmutableList.of(ConfigModelId.fromNameAndVersion("admin", "3.0"),
ConfigModelId.fromNameAndVersion("admin", "4.0"));
List.of(ConfigModelId.fromNameAndVersion("admin", "3.0"),
ConfigModelId.fromNameAndVersion("admin", "4.0"));

public BuilderV4() {
super(AdminModel.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.model.provision;

import com.google.common.collect.ImmutableList;
import com.yahoo.component.Version;
import com.yahoo.config.provision.Flavor;

Expand All @@ -16,12 +15,12 @@
public class Host {

private final String hostname;
private final ImmutableList<String> aliases;
private final List<String> aliases;
private final Optional<Flavor> flavor;
private final Optional<Version> version;

public Host(String hostname) {
this(hostname, ImmutableList.of(), Optional.empty());
this(hostname, List.of(), Optional.empty());
}

public Host(String hostname, List<String> hostAliases) {
Expand All @@ -34,7 +33,7 @@ public Host(String hostname, List<String> hostAliases, Optional<Flavor> flavor)

public Host(String hostname, List<String> hostAliases, Optional<Flavor> flavor, Optional<Version> version) {
this.hostname = hostname;
this.aliases = ImmutableList.copyOf(hostAliases);
this.aliases = List.copyOf(hostAliases);
this.flavor = flavor;
this.version = version;
}
Expand All @@ -52,7 +51,7 @@ public Host(String hostname, List<String> hostAliases, Optional<Flavor> flavor,
@Override
public String toString() {
return hostname + (aliases.size() > 0 ? " (aliases: " + aliases + ")" : "" ) +
(flavor.isPresent() ? " (flavor: " + flavor.get() + ")" : "");
(flavor.map(value -> " (flavor: " + value + ")").orElse(""));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package com.yahoo.schema.derived;

import ai.vespa.rankingexpression.importer.configmodelview.ImportedMlModels;
import com.google.common.collect.ImmutableList;
import com.yahoo.collections.Pair;
import com.yahoo.compress.Compressor;
import com.yahoo.config.model.api.ModelContext;
Expand Down Expand Up @@ -86,9 +85,9 @@ private Compressor.Compression compress(List<Pair<String, String>> properties) {

private List<Pair<String, String>> decompress(Compressor.Compression compression) {
String propertiesString = new String(compressor.decompress(compression), StandardCharsets.UTF_8);
if (propertiesString.isEmpty()) return ImmutableList.of();
if (propertiesString.isEmpty()) return List.of();

ImmutableList.Builder<Pair<String, String>> properties = new ImmutableList.Builder<>();
List<Pair<String, String>> properties = new ArrayList<>();
for (int pos = 0; pos < propertiesString.length();) {
int keyEndPos = propertiesString.indexOf(keyEndMarker, pos);
String key = propertiesString.substring(pos, keyEndPos);
Expand All @@ -98,7 +97,7 @@ private List<Pair<String, String>> decompress(Compressor.Compression compression
pos = valueEndPos + valueEndMarker.length();
properties.add(new Pair<>(key, value));
}
return properties.build();
return List.copyOf(properties);
}

public String getName() { return name; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.expressiontransforms;

import com.google.common.collect.ImmutableList;
import com.yahoo.searchlib.rankingexpression.RankingExpression;
import com.yahoo.searchlib.rankingexpression.transform.ConstantDereferencer;
import com.yahoo.searchlib.rankingexpression.transform.ExpressionTransformer;
Expand All @@ -24,19 +23,19 @@ public class ExpressionTransforms {

public ExpressionTransforms() {
transforms =
ImmutableList.of(new TensorFlowFeatureConverter(),
new OnnxFeatureConverter(),
new OnnxModelTransformer(),
new XgboostFeatureConverter(),
new LightGBMFeatureConverter(),
new TokenTransformer(),
new ConstantDereferencer(),
new ConstantTensorTransformer(),
new FunctionInliner(),
new FunctionShadower(),
new TensorMaxMinTransformer(),
new Simplifier(),
new BooleanExpressionTransformer());
List.of(new TensorFlowFeatureConverter(),
new OnnxFeatureConverter(),
new OnnxModelTransformer(),
new XgboostFeatureConverter(),
new LightGBMFeatureConverter(),
new TokenTransformer(),
new ConstantDereferencer(),
new ConstantTensorTransformer(),
new FunctionInliner(),
new FunctionShadower(),
new TensorMaxMinTransformer(),
new Simplifier(),
new BooleanExpressionTransformer());
}

public RankingExpression transform(RankingExpression expression, RankProfileTransformContext context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.schema.processing;

import com.google.common.collect.ImmutableSet;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.schema.RankProfile;
import com.yahoo.schema.RankProfileRegistry;
import com.yahoo.schema.Schema;
import com.yahoo.searchlib.rankingexpression.parser.RankingExpressionParserConstants;
import com.yahoo.vespa.model.container.search.QueryProfiles;

import java.util.Arrays;
import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Collectors;

/**
* Issues a warning if some function has a reserved name. This is not necessarily
Expand All @@ -20,7 +21,7 @@
*/
public class ReservedFunctionNames extends Processor {

private static Set<String> reservedNames = getReservedNames();
private static final Set<String> reservedNames = getReservedNames();

public ReservedFunctionNames(Schema schema, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
super(schema, deployLogger, rankProfileRegistry, queryProfiles);
Expand All @@ -44,13 +45,9 @@ public void process(boolean validate, boolean documentsOnly) {
}
}

private static ImmutableSet<String> getReservedNames() {
ImmutableSet.Builder<String> names = ImmutableSet.builder();
for (String token : RankingExpressionParserConstants.tokenImage) {
String tokenWithoutQuotes = token.substring(1, token.length()-1);
names.add(tokenWithoutQuotes);
}
return names.build();
private static Set<String> getReservedNames() {
return Arrays.stream(RankingExpressionParserConstants.tokenImage)
.map(token -> token.substring(1, token.length()-1)).collect(Collectors.toUnmodifiableSet());
}

}
Loading

0 comments on commit afcf1bb

Please sign in to comment.