diff options
47 files changed, 188 insertions, 531 deletions
diff --git a/component/src/main/java/com/yahoo/component/provider/ComponentRegistry.java b/component/src/main/java/com/yahoo/component/provider/ComponentRegistry.java index 1dddcbcc461..a64d6eb1090 100644 --- a/component/src/main/java/com/yahoo/component/provider/ComponentRegistry.java +++ b/component/src/main/java/com/yahoo/component/provider/ComponentRegistry.java @@ -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.component.provider; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.yahoo.component.ComponentId; import com.yahoo.component.ComponentSpecification; @@ -56,17 +55,9 @@ public class ComponentRegistry<COMPONENT> { if (frozen) throw new IllegalStateException("Cannot modify a frozen component registry"); Map<String, Map<Version, COMPONENT>> componentVersionsByName = - componentsByNameByNamespace.get(id.getNamespace()); - if (componentVersionsByName == null) { - componentVersionsByName = new LinkedHashMap<>(); - componentsByNameByNamespace.put(id.getNamespace(), componentVersionsByName); - } + componentsByNameByNamespace.computeIfAbsent(id.getNamespace(), k -> new LinkedHashMap<>()); - Map<Version, COMPONENT> componentVersions = componentVersionsByName.get(id.getName()); - if (componentVersions == null) { - componentVersions = new LinkedHashMap<>(); - componentVersionsByName.put(id.getName(), componentVersions); - } + Map<Version, COMPONENT> componentVersions = componentVersionsByName.computeIfAbsent(id.getName(), k -> new LinkedHashMap<>()); componentVersions.put(id.getVersion(), component); componentsById.put(id, component); @@ -162,7 +153,7 @@ public class ComponentRegistry<COMPONENT> { * Returns an unmodifiable snapshot of all components present in this registry. */ public List<COMPONENT> allComponents() { - return ImmutableList.copyOf(componentsById.values()); + return List.copyOf(componentsById.values()); } /** diff --git a/config-model-api/src/main/java/com/yahoo/config/application/api/Notifications.java b/config-model-api/src/main/java/com/yahoo/config/application/api/Notifications.java index e95527d646a..7955a11ce45 100644 --- a/config-model-api/src/main/java/com/yahoo/config/application/api/Notifications.java +++ b/config-model-api/src/main/java/com/yahoo/config/application/api/Notifications.java @@ -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.application.api; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -50,10 +49,10 @@ public class Notifications { return none; ImmutableMap.Builder<When, List<String>> emailAddresses = ImmutableMap.builder(); - emailAddressesByWhen.forEach((when, addresses) -> emailAddresses.put(when, ImmutableList.copyOf(addresses))); + emailAddressesByWhen.forEach((when, addresses) -> emailAddresses.put(when, List.copyOf(addresses))); ImmutableMap.Builder<When, List<Role>> emailRoles = ImmutableMap.builder(); - emailRolesByWhen.forEach((when, roles) -> emailRoles.put(when, ImmutableList.copyOf(roles))); + emailRolesByWhen.forEach((when, roles) -> emailRoles.put(when, List.copyOf(roles))); return new Notifications(emailAddresses.build(), emailRoles.build()); } @@ -122,11 +121,11 @@ public class Notifications { } public static When fromValue(String value) { - switch (value) { - case "failing": return failing; - case "failing-commit": return failingCommit; - default: throw new IllegalArgumentException("Unknown value '" + value + "'."); - } + return switch (value) { + case "failing" -> failing; + case "failing-commit" -> failingCommit; + default -> throw new IllegalArgumentException("Unknown value '" + value + "'."); + }; } } diff --git a/config/pom.xml b/config/pom.xml index 1f90d374d88..28eb45fd406 100755 --- a/config/pom.xml +++ b/config/pom.xml @@ -21,11 +21,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <scope>provided</scope> - </dependency> - <dependency> <groupId>com.yahoo.vespa</groupId> <artifactId>annotations</artifactId> <version>${project.version}</version> diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java b/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java index 9c2d703e1a8..0b8c0c8c48c 100644 --- a/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java +++ b/container-disc/src/main/java/com/yahoo/container/jdisc/ConfiguredApplication.java @@ -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.jdisc; -import com.google.common.util.concurrent.AtomicDouble; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Injector; @@ -58,7 +57,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.Phaser; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; @@ -79,8 +77,8 @@ public final class ConfiguredApplication implements Application { private final String configId; private final OsgiFramework osgiFramework; private final com.yahoo.jdisc.Timer timerSingleton; - private final AtomicBoolean dumpHeapOnShutdownTimeout = new AtomicBoolean(false); - private final AtomicDouble shutdownTimeoutS = new AtomicDouble(50.0); + private volatile boolean dumpHeapOnShutdownTimeout = false; + private volatile double shutdownTimeoutS = 50.0; // Subscriber that is used when this is not a standalone-container. Subscribes // to config to make sure that container will be registered in slobrok (by {@link com.yahoo.jrt.slobrok.api.Register}) // if slobrok config changes (typically slobroks moving to other nodes) @@ -286,8 +284,8 @@ public final class ConfiguredApplication implements Application { } private void reconfigure(QrConfig.Shutdown shutdown) { - dumpHeapOnShutdownTimeout.set(shutdown.dumpHeapOnTimeout()); - shutdownTimeoutS.set(shutdown.timeout()); + dumpHeapOnShutdownTimeout = shutdown.dumpHeapOnTimeout(); + shutdownTimeoutS = shutdown.timeout(); } private void initializeAndActivateContainer(ContainerBuilder builder, Runnable cleanupTask) { @@ -429,7 +427,7 @@ public final class ConfiguredApplication implements Application { @Override public void stop() { log.info("Stop: Initiated"); - shutdownDeadline.schedule((long)(shutdownTimeoutS.get() * 1000), dumpHeapOnShutdownTimeout.get()); + shutdownDeadline.schedule((long)(shutdownTimeoutS * 1000), dumpHeapOnShutdownTimeout); stopServersAndAwaitTermination(); log.info("Stop: Finished"); } @@ -438,7 +436,7 @@ public final class ConfiguredApplication implements Application { log.info("PrepareStop: Initiated"); long timeoutMillis = (long) (request.parameters().get(0).asDouble() * 1000); try (ShutdownDeadline ignored = - new ShutdownDeadline(configId).schedule(timeoutMillis, dumpHeapOnShutdownTimeout.get())) { + new ShutdownDeadline(configId).schedule(timeoutMillis, dumpHeapOnShutdownTimeout)) { stopServersAndAwaitTermination(); log.info("PrepareStop: Finished"); } catch (Exception e) { diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunLog.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunLog.java index bc27d736ad4..f388a148ffb 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunLog.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/RunLog.java @@ -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.controller.deployment; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.yahoo.vespa.hosted.controller.api.integration.LogEntry; @@ -32,7 +31,7 @@ public class RunLog { ImmutableMap.Builder<Step, List<LogEntry>> builder = ImmutableMap.builder(); log.forEach((step, entries) -> { if ( ! entries.isEmpty()) - builder.put(step, ImmutableList.copyOf(entries)); + builder.put(step, List.copyOf(entries)); }); OptionalLong lastId = log.values().stream() .flatMap(List::stream) diff --git a/document/src/main/java/com/yahoo/document/DocumentType.java b/document/src/main/java/com/yahoo/document/DocumentType.java index 0f771e4d55a..bec08837a84 100644 --- a/document/src/main/java/com/yahoo/document/DocumentType.java +++ b/document/src/main/java/com/yahoo/document/DocumentType.java @@ -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.document; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.fieldset.AllFields; @@ -38,9 +37,9 @@ public class DocumentType extends StructuredDataType { public static final int classId = registerClass(Ids.document + 58, DocumentType.class); private StructDataType contentStructType; private List<DocumentType> inherits = new ArrayList<>(1); - private Map<String, Set<Field>> fieldSets = new HashMap<>(); + private final Map<String, Set<Field>> fieldSets = new HashMap<>(); private final Set<String> importedFieldNames; - private Map<String, StructDataType> declaredStructTypes = new HashMap<>(); + private final Map<String, StructDataType> declaredStructTypes = new HashMap<>(); /** * Creates a new document type and registers it with the document type manager. @@ -101,10 +100,9 @@ public class DocumentType extends StructuredDataType { @Override public boolean isValueCompatible(FieldValue value) { - if (!(value instanceof Document)) { + if (!(value instanceof Document doc)) { return false; } - Document doc = (Document) value; if (doc.getDataType().inherits(this)) { //the value is of this type; or the supertype of the value is of this type, etc.... return true; @@ -330,7 +328,7 @@ public class DocumentType extends StructuredDataType { for (DocumentType type : inherits) { names.add(type.getDataTypeName()); } - return ImmutableList.copyOf(names).listIterator(); + return List.copyOf(names).listIterator(); } /** @@ -433,7 +431,7 @@ public class DocumentType extends StructuredDataType { } collection.addAll(contentStructType.getFields()); - return ImmutableList.copyOf(collection); + return List.copyOf(collection); } private Set<Field> getAllUniqueFields() { @@ -486,8 +484,7 @@ public class DocumentType extends StructuredDataType { } public boolean equals(Object o) { - if (!(o instanceof DocumentType)) return false; - DocumentType other = (DocumentType) o; + if (!(o instanceof DocumentType other)) return false; // Ignore whether one of them have added inheritance to super Document.0 type if (super.equals(o) && contentStructType.equals(other.contentStructType)) { if ((inherits.size() > 1 || other.inherits.size() > 1) || diff --git a/document/src/main/java/com/yahoo/document/StructDataType.java b/document/src/main/java/com/yahoo/document/StructDataType.java index 34967cf6f51..2af34711851 100644 --- a/document/src/main/java/com/yahoo/document/StructDataType.java +++ b/document/src/main/java/com/yahoo/document/StructDataType.java @@ -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.document; -import com.google.common.collect.ImmutableList; import com.yahoo.document.datatypes.FieldValue; import com.yahoo.document.datatypes.Struct; import com.yahoo.vespa.objects.Ids; @@ -9,6 +8,7 @@ import com.yahoo.vespa.objects.Ids; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.List; /** * @author Einar M R Rosenvinge @@ -98,7 +98,7 @@ public class StructDataType extends BaseStructDataType { Collection<Field> fieldsBuilder = new ArrayList<>(); fieldsBuilder.addAll(super.getFields()); fieldsBuilder.addAll(superType.getFields()); - return ImmutableList.copyOf(fieldsBuilder); + return List.copyOf(fieldsBuilder); } public Collection<Field> getFieldsThisTypeOnly() { @@ -117,10 +117,9 @@ public class StructDataType extends BaseStructDataType { @Override public boolean isValueCompatible(FieldValue value) { - if (!(value instanceof Struct)) { + if (!(value instanceof Struct structValue)) { return false; } - Struct structValue = (Struct) value; if (structValue.getDataType().inherits(this)) { //the value is of this type; or the supertype of the value is of this type, etc.... return true; @@ -142,9 +141,9 @@ public class StructDataType extends BaseStructDataType { public Collection<StructDataType> getInheritedTypes() { if (superType == null) { - return ImmutableList.of(); + return List.of(); } - return ImmutableList.of(superType); + return List.of(superType); } public boolean inherits(StructDataType type) { @@ -156,10 +155,9 @@ public class StructDataType extends BaseStructDataType { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof StructDataType)) return false; + if (!(o instanceof StructDataType that)) return false; if (!super.equals(o)) return false; - StructDataType that = (StructDataType) o; if (superType != null ? !superType.equals(that.superType) : that.superType != null) return false; return true; } diff --git a/document/src/main/java/com/yahoo/document/annotation/AnnotationType.java b/document/src/main/java/com/yahoo/document/annotation/AnnotationType.java index 4acc9c00384..88e6bd7822a 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationType.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationType.java @@ -1,12 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.annotation; -import com.google.common.collect.ImmutableList; import com.yahoo.collections.MD5; import com.yahoo.document.DataType; import java.util.Collection; -import java.util.Collections; +import java.util.List; /** * An AnnotationType describes a certain type of annotations; they are @@ -124,9 +123,9 @@ public class AnnotationType implements Comparable<AnnotationType> { public Collection<AnnotationType> getInheritedTypes() { if (superType == null) { - return ImmutableList.of(); + return List.of(); } - return ImmutableList.of(superType); + return List.of(superType); } public boolean inherits(AnnotationType type) { @@ -138,9 +137,7 @@ public class AnnotationType implements Comparable<AnnotationType> { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof AnnotationType)) return false; - - AnnotationType that = (AnnotationType) o; + if (!(o instanceof AnnotationType that)) return false; return name.equals(that.name); } diff --git a/document/src/main/java/com/yahoo/document/annotation/SpanTree.java b/document/src/main/java/com/yahoo/document/annotation/SpanTree.java index b03f587d839..d63616130e2 100644 --- a/document/src/main/java/com/yahoo/document/annotation/SpanTree.java +++ b/document/src/main/java/com/yahoo/document/annotation/SpanTree.java @@ -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.document.annotation; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMultiset; import com.yahoo.document.CollectionDataType; import com.yahoo.document.Field; @@ -63,7 +62,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl setRoot(new SpanList()); } - @SuppressWarnings("unchecked") public SpanTree(SpanTree otherToCopy) { name = otherToCopy.name; setRoot(copySpan(otherToCopy.root)); @@ -250,7 +248,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl * total number of Annotations, and m is the number of SpanNodes that had been removed from the tree. * The lower bound is Omega(n), if no SpanNodes had been removed from the tree. */ - @SuppressWarnings("unchecked") public void cleanup() { Map<Annotation, Annotation> removedAnnotations = removeAnnotationsThatPointToInvalidSpanNodes(); @@ -269,9 +266,8 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl } FieldValue value = a.getFieldValue(); - if (value instanceof AnnotationReference) { + if (value instanceof AnnotationReference ref) { //the annotation "a" has a reference - AnnotationReference ref = (AnnotationReference) value; if (removedAnnotations.get(ref.getReference()) != null) { //this reference refers to a dead annotation ref.setReference(null); @@ -367,7 +363,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl return false; } - @SuppressWarnings("unchecked") private Map<Annotation, Annotation> removeAnnotationsThatPointToInvalidSpanNodes() { Map<Annotation, Annotation> removedAnnotations = new IdentityHashMap<Annotation, Annotation>(); @@ -412,7 +407,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl annotations.annotate(annotation); } - @SuppressWarnings("unchecked") private Collection<Annotation> getAnnotations() { return annotations.annotations(); } @@ -548,7 +542,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl * Returns an Iterator over all annotations in this tree. Note that the iteration order is non-deterministic. * @return an Iterator over all annotations in this tree. */ - @SuppressWarnings("unchecked") public Iterator<Annotation> iterator() { return annotations.annotations().iterator(); } @@ -559,7 +552,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl * @param node the node to return annotations for. * @return an Iterator over all annotations that annotate the given node. */ - @SuppressWarnings("unchecked") public Iterator<Annotation> iterator(SpanNode node) { return annotations.iterator(node); } @@ -570,7 +562,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl * @param node the node to recursively return annotations for. * @return a recursive Iterator over all annotations that annotate the given node and its subnodes. */ - @SuppressWarnings("unchecked") public Iterator<Annotation> iteratorRecursive(SpanNode node) { return annotations.iteratorRecursive(node); } @@ -642,10 +633,10 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl public Collection<IndexKey> getCurrentIndexes() { if (annotations instanceof AnnotationType2AnnotationContainer) - return ImmutableList.of(IndexKey.ANNOTATION_TYPE); + return List.of(IndexKey.ANNOTATION_TYPE); if (annotations instanceof SpanNode2AnnotationContainer) - return ImmutableList.of(IndexKey.SPAN_NODE); - return ImmutableList.of(); + return List.of(IndexKey.SPAN_NODE); + return List.of(); } @Override @@ -656,9 +647,8 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof SpanTree)) return false; + if (!(o instanceof SpanTree tree)) return false; - SpanTree tree = (SpanTree) o; if (!annotationsEquals(tree)) return false; if (!name.equals(tree.name)) return false; if (!root.equals(tree.root)) return false; @@ -666,7 +656,6 @@ public class SpanTree implements Iterable<Annotation>, SpanNodeParent, Comparabl return true; } - @SuppressWarnings("unchecked") private boolean annotationsEquals(SpanTree tree) { List<Annotation> annotationCollection = new LinkedList<Annotation>(getAnnotations()); List<Annotation> otherAnnotations = new LinkedList<Annotation>(tree.getAnnotations()); diff --git a/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java index 51b068b4712..6133c9ca0ad 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java @@ -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.document.datatypes; -import com.google.common.collect.ImmutableList; import com.yahoo.collections.CollectionComparator; import com.yahoo.document.DataType; import com.yahoo.document.Field; @@ -16,6 +15,7 @@ import com.yahoo.vespa.objects.Ids; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; @@ -142,9 +142,9 @@ public class StringFieldValue extends FieldValue { */ public Collection<SpanTree> getSpanTrees() { if (spanTrees == null) { - return ImmutableList.of(); + return List.of(); } - return ImmutableList.copyOf(spanTrees.values()); + return List.copyOf(spanTrees.values()); } /** Returns the map of spantrees. Might be null. */ @@ -236,9 +236,8 @@ public class StringFieldValue extends FieldValue { @Override public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof StringFieldValue)) return false; + if (!(o instanceof StringFieldValue that)) return false; if (!super.equals(o)) return false; - StringFieldValue that = (StringFieldValue) o; if (!Objects.equals(spanTrees, that.spanTrees)) return false; if (!Objects.equals(value, that.value)) return false; return true; diff --git a/document/src/main/java/com/yahoo/document/json/TokenBuffer.java b/document/src/main/java/com/yahoo/document/json/TokenBuffer.java index e6d2021f90b..58ceeec4f4c 100644 --- a/document/src/main/java/com/yahoo/document/json/TokenBuffer.java +++ b/document/src/main/java/com/yahoo/document/json/TokenBuffer.java @@ -89,10 +89,6 @@ public class TokenBuffer { bufferJsonStruct(first, tokens, JsonToken.START_OBJECT); } - public void bufferArray(JsonToken first, JsonParser tokens) { - bufferJsonStruct(first, tokens, JsonToken.START_ARRAY); - } - private void bufferJsonStruct(JsonToken first, JsonParser tokens, JsonToken firstToken) { int localNesting = 0; JsonToken t = first; @@ -150,42 +146,6 @@ public class TokenBuffer { return nesting; } - public String dumpContents() { - StringBuilder b = new StringBuilder(); - b.append("[nesting: ").append(nesting()).append("\n"); - for (Token t : buffer) { - b.append("(").append(t.token).append(", \"").append(t.name).append("\", \"").append(t.text).append("\")\n"); - } - b.append("]\n"); - return b.toString(); - } - - public void fastForwardToEndObject() { - JsonToken t = currentToken(); - while (t != JsonToken.END_OBJECT) { - t = next(); - } - } - - public TokenBuffer prefetchCurrentElement() { - Deque<Token> copy = new ArrayDeque<>(); - - if (currentToken().isScalarValue()) { - copy.add(buffer.peekFirst()); - } else { - int localNesting = nesting(); - int nestingBarrier = localNesting; - for (Token t : buffer) { - copy.add(t); - localNesting += nestingOffset(t.token); - if (localNesting < nestingBarrier) { - break; - } - } - } - return new TokenBuffer(copy); - } - public Token prefetchScalar(String name) { int localNesting = nesting(); int nestingBarrier = localNesting; diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BundleInstallationException.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BundleInstallationException.java index 6b3f4d6e7d7..ab75b499e20 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/BundleInstallationException.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/BundleInstallationException.java @@ -1,13 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jdisc.application; -import com.google.common.collect.ImmutableList; import org.osgi.framework.Bundle; import org.osgi.framework.BundleException; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; /** @@ -25,7 +22,7 @@ public final class BundleInstallationException extends BundleException { public BundleInstallationException(Collection<Bundle> installedBundles, Throwable cause) { super(cause.getMessage(), cause); - this.installedBundles = ImmutableList.copyOf(installedBundles); + this.installedBundles = List.copyOf(installedBundles); } public List<Bundle> installedBundles() { diff --git a/jdisc_core/src/main/java/com/yahoo/jdisc/application/ServerRepository.java b/jdisc_core/src/main/java/com/yahoo/jdisc/application/ServerRepository.java index 39e7eb29c0f..b6121337e3d 100644 --- a/jdisc_core/src/main/java/com/yahoo/jdisc/application/ServerRepository.java +++ b/jdisc_core/src/main/java/com/yahoo/jdisc/application/ServerRepository.java @@ -1,12 +1,14 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jdisc.application; -import com.google.common.collect.ImmutableList; import com.yahoo.jdisc.Container; import com.yahoo.jdisc.service.ServerProvider; import org.osgi.framework.Bundle; -import java.util.*; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; import java.util.logging.Logger; /** @@ -25,7 +27,7 @@ public class ServerRepository implements Iterable<ServerProvider> { this.guice = guice; } - public Iterable<ServerProvider> activate() { return ImmutableList.copyOf(servers); } + public Iterable<ServerProvider> activate() { return List.copyOf(servers); } public List<ServerProvider> installAll(Bundle bundle, Iterable<String> serverNames) throws ClassNotFoundException { List<ServerProvider> lst = new LinkedList<>(); @@ -65,7 +67,7 @@ public class ServerRepository implements Iterable<ServerProvider> { } public Collection<ServerProvider> collection() { - return Collections.unmodifiableCollection(servers); + return List.copyOf(servers); } @Override diff --git a/metrics-proxy/pom.xml b/metrics-proxy/pom.xml index c3866d3e592..ee1439fb5f6 100644 --- a/metrics-proxy/pom.xml +++ b/metrics-proxy/pom.xml @@ -31,16 +31,6 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>com.google.inject</groupId> - <artifactId>guice</artifactId> - <scope>provided</scope> - </dependency> - <dependency> <groupId>com.yahoo.vespa</groupId> <artifactId>annotations</artifactId> <version>${project.version}</version> diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/service/VespaServices.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/service/VespaServices.java index 4318a689ba8..5b9e1e67657 100644 --- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/service/VespaServices.java +++ b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/service/VespaServices.java @@ -4,11 +4,9 @@ package ai.vespa.metricsproxy.service; import ai.vespa.metricsproxy.core.MonitoringConfig; import ai.vespa.metricsproxy.metric.model.DimensionId; import ai.vespa.metricsproxy.service.VespaServicesConfig.Service; -import com.google.common.annotations.VisibleForTesting; import com.yahoo.component.annotation.Inject; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.logging.Logger; @@ -39,7 +37,6 @@ public class VespaServices { updateServices(services); } - @VisibleForTesting public VespaServices(List<VespaService> services) { this.services = services; sentinel = null; @@ -74,7 +71,7 @@ public class VespaServices { * @return A list of VespaService objects */ public List<VespaService> getVespaServices() { - return Collections.unmodifiableList(services); + return List.copyOf(services); } /** diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/core/MetricsManagerTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/core/MetricsManagerTest.java index 9e5a24ccd3c..70f126a8514 100644 --- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/core/MetricsManagerTest.java +++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/core/MetricsManagerTest.java @@ -18,12 +18,10 @@ import ai.vespa.metricsproxy.service.DownService; import ai.vespa.metricsproxy.service.DummyService; import ai.vespa.metricsproxy.service.VespaService; import ai.vespa.metricsproxy.service.VespaServices; -import com.google.common.collect.ImmutableList; import org.junit.Before; import org.junit.Test; import java.time.Instant; -import java.util.Collections; import java.util.List; import java.util.Map; @@ -48,7 +46,7 @@ public class MetricsManagerTest { private static final String SERVICE_0_ID = "dummy/id/0"; private static final String SERVICE_1_ID = "dummy/id/1"; - private static final List<VespaService> testServices = ImmutableList.of( + private static final List<VespaService> testServices = List.of( new DummyService(0, SERVICE_0_ID), new DummyService(1, SERVICE_1_ID)); @@ -64,7 +62,7 @@ public class MetricsManagerTest { public void service_that_is_down_has_a_separate_metrics_packet() { // Reset to use only the service that is down var downService = new DownService(HealthMetric.getDown("No response")); - List<VespaService> testServices = Collections.singletonList(downService); + List<VespaService> testServices = List.of(downService); MetricsManager metricsManager = TestUtil.createMetricsManager(new VespaServices(testServices), getMetricsConsumers(),getApplicationDimensions(), getNodeDimensions()); @@ -140,9 +138,9 @@ public class MetricsManagerTest { // TODO: test that non-whitelisted metrics are filtered out, but this is currently not the case, see ExternalMetrics.setExtraMetrics @Test public void extra_metrics_packets_containing_whitelisted_metrics_are_added() { - metricsManager.setExtraMetrics(ImmutableList.of( + metricsManager.setExtraMetrics(List.of( new MetricsPacket.Builder(toServiceId("foo")) - .putMetrics(ImmutableList.of(new Metric(WHITELISTED_METRIC_ID, 0))))); + .putMetrics(List.of(new Metric(WHITELISTED_METRIC_ID, 0))))); List<MetricsPacket> packets = metricsManager.getMetrics(testServices, Instant.EPOCH); assertEquals(3, packets.size()); @@ -150,9 +148,9 @@ public class MetricsManagerTest { @Test public void extra_metrics_packets_without_whitelisted_metrics_are_not_added() { - metricsManager.setExtraMetrics(ImmutableList.of( + metricsManager.setExtraMetrics(List.of( new MetricsPacket.Builder(toServiceId("foo")) - .putMetrics(ImmutableList.of(new Metric(toMetricId("not-whitelisted"), 0))))); + .putMetrics(List.of(new Metric(toMetricId("not-whitelisted"), 0))))); List<MetricsPacket> packets = metricsManager.getMetrics(testServices, Instant.EPOCH); assertEquals(2, packets.size()); @@ -161,9 +159,9 @@ public class MetricsManagerTest { @Test public void application_from_extra_metrics_packets_is_used_as_service_in_result_packets() { final ServiceId serviceId = toServiceId("custom-service"); - metricsManager.setExtraMetrics(ImmutableList.of( + metricsManager.setExtraMetrics(List.of( new MetricsPacket.Builder(serviceId) - .putMetrics(ImmutableList.of(new Metric(WHITELISTED_METRIC_ID, 0))))); + .putMetrics(List.of(new Metric(WHITELISTED_METRIC_ID, 0))))); List<MetricsPacket> packets = metricsManager.getMetrics(testServices, Instant.EPOCH); MetricsPacket extraPacket = null; @@ -175,9 +173,9 @@ public class MetricsManagerTest { @Test public void extra_dimensions_are_added_to_metrics_packets_that_do_not_have_those_dimensions() { - metricsManager.setExtraMetrics(ImmutableList.of( + metricsManager.setExtraMetrics(List.of( new MetricsPacket.Builder(toServiceId("foo")) - .putMetrics(ImmutableList.of(new Metric(WHITELISTED_METRIC_ID, 0))) + .putMetrics(List.of(new Metric(WHITELISTED_METRIC_ID, 0))) .putDimension(ROLE_DIMENSION, "role from extraMetrics"))); List<MetricsPacket> packets = metricsManager.getMetrics(testServices, Instant.EPOCH); @@ -188,9 +186,9 @@ public class MetricsManagerTest { @Test public void extra_dimensions_do_not_overwrite_existing_dimension_values() { - metricsManager.setExtraMetrics(ImmutableList.of( + metricsManager.setExtraMetrics(List.of( new MetricsPacket.Builder(toServiceId("foo")) - .putMetrics(ImmutableList.of(new Metric(WHITELISTED_METRIC_ID, 0))) + .putMetrics(List.of(new Metric(WHITELISTED_METRIC_ID, 0))) .putDimension(METRIC_TYPE_DIMENSION_ID, "from extraMetrics"))); List<MetricsPacket> packets = metricsManager.getMetrics(testServices, Instant.EPOCH); diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/HttpHandlerTestBase.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/HttpHandlerTestBase.java index dd19970efa7..4f9634a061a 100644 --- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/HttpHandlerTestBase.java +++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/http/HttpHandlerTestBase.java @@ -17,7 +17,6 @@ import ai.vespa.metricsproxy.service.DownService; import ai.vespa.metricsproxy.service.DummyService; import ai.vespa.metricsproxy.service.VespaService; import ai.vespa.metricsproxy.service.VespaServices; -import com.google.common.collect.ImmutableList; import com.yahoo.container.jdisc.RequestHandlerTestDriver; import java.time.Instant; @@ -33,10 +32,9 @@ import static ai.vespa.metricsproxy.service.DummyService.METRIC_1; * * @author gjoranv */ -@SuppressWarnings("UnstableApiUsage") public class HttpHandlerTestBase { - protected static final List<VespaService> testServices = ImmutableList.of( + protected static final List<VespaService> testServices = List.of( new DummyService(0, ""), new DummyService(1, ""), new DownService(HealthMetric.getDown("No response"))); @@ -55,10 +53,10 @@ public class HttpHandlerTestBase { protected static MetricsManager getMetricsManager() { MetricsManager metricsManager = TestUtil.createMetricsManager(vespaServices, getMetricsConsumers(), getApplicationDimensions(), getNodeDimensions()); - metricsManager.setExtraMetrics(ImmutableList.of( + metricsManager.setExtraMetrics(List.of( new MetricsPacket.Builder(VESPA_NODE_SERVICE_ID) .timestamp(Instant.now().getEpochSecond()) - .putMetrics(ImmutableList.of(new Metric(MetricId.toMetricId(CPU_METRIC), 12.345))))); + .putMetrics(List.of(new Metric(MetricId.toMetricId(CPU_METRIC), 12.345))))); return metricsManager; } diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/ExternalMetricsTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/ExternalMetricsTest.java index 581367878ca..4e79c11678c 100644 --- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/ExternalMetricsTest.java +++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/ExternalMetricsTest.java @@ -6,7 +6,6 @@ import ai.vespa.metricsproxy.core.MetricsConsumers; import ai.vespa.metricsproxy.metric.model.ConsumerId; import ai.vespa.metricsproxy.metric.model.MetricsPacket; import ai.vespa.metricsproxy.metric.model.ServiceId; -import com.google.common.collect.ImmutableList; import org.junit.Test; import java.util.List; @@ -29,7 +28,7 @@ public class ExternalMetricsTest { MetricsConsumers noConsumers = new MetricsConsumers(new ConsumersConfig.Builder().build()); ExternalMetrics externalMetrics = new ExternalMetrics(noConsumers); - externalMetrics.setExtraMetrics(ImmutableList.of( + externalMetrics.setExtraMetrics(List.of( new MetricsPacket.Builder(toServiceId("foo")))); List<MetricsPacket.Builder> packets = externalMetrics.getMetrics(); @@ -42,7 +41,7 @@ public class ExternalMetricsTest { MetricsConsumers noConsumers = new MetricsConsumers(new ConsumersConfig.Builder().build()); ExternalMetrics externalMetrics = new ExternalMetrics(noConsumers); - externalMetrics.setExtraMetrics(ImmutableList.of( + externalMetrics.setExtraMetrics(List.of( new MetricsPacket.Builder(SERVICE_ID))); List<MetricsPacket.Builder> packets = externalMetrics.getMetrics(); @@ -59,7 +58,7 @@ public class ExternalMetricsTest { MetricsConsumers consumers = new MetricsConsumers(consumersConfig); ExternalMetrics externalMetrics = new ExternalMetrics(consumers); - externalMetrics.setExtraMetrics(ImmutableList.of( + externalMetrics.setExtraMetrics(List.of( new MetricsPacket.Builder(toServiceId("foo")))); List<MetricsPacket.Builder> packets = externalMetrics.getMetrics(); diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/model/MetricsPacketTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/model/MetricsPacketTest.java index 4dcdb45feee..57029ff4aff 100644 --- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/model/MetricsPacketTest.java +++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/metric/model/MetricsPacketTest.java @@ -2,18 +2,15 @@ package ai.vespa.metricsproxy.metric.model; import ai.vespa.metricsproxy.metric.Metric; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; import org.junit.Test; import java.util.List; import java.util.Map; +import java.util.Set; import static ai.vespa.metricsproxy.metric.model.ConsumerId.toConsumerId; import static ai.vespa.metricsproxy.metric.model.MetricId.toMetricId; import static ai.vespa.metricsproxy.metric.model.ServiceId.toServiceId; -import static java.util.Collections.singleton; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -45,8 +42,8 @@ public class MetricsPacketTest { MetricsPacket packet = new MetricsPacket.Builder(toServiceId("foo")) .statusCode(0) .statusMessage("") - .addConsumers(singleton(DUPLICATE_CONSUMER)) - .addConsumers(singleton(DUPLICATE_CONSUMER)) + .addConsumers(Set.of(DUPLICATE_CONSUMER)) + .addConsumers(Set.of(DUPLICATE_CONSUMER)) .build(); assertEquals(1, packet.consumers().size()); } @@ -57,17 +54,17 @@ public class MetricsPacketTest { var builder = new MetricsPacket.Builder(toServiceId("foo")) .statusCode(0) .statusMessage("") - .addConsumers(singleton(consumer)); + .addConsumers(Set.of(consumer)); assertTrue(builder.hasConsumer(consumer)); } @Test public void builder_can_retain_subset_of_metrics() { MetricsPacket packet = new MetricsPacket.Builder(toServiceId("foo")) - .putMetrics(ImmutableList.of( + .putMetrics(List.of( new Metric(toMetricId("remove"), 1), new Metric(toMetricId("keep"), 2))) - .retainMetrics(ImmutableSet.of(toMetricId("keep"), toMetricId("non-existent"))) + .retainMetrics(Set.of(toMetricId("keep"), toMetricId("non-existent"))) .build(); assertFalse("should not contain 'remove'", packet.metrics().containsKey(toMetricId("remove"))); @@ -86,14 +83,14 @@ public class MetricsPacketTest { MetricId THREE_ID = toMetricId(THREE); MetricId NON_EXISTENT_ID = toMetricId(NON_EXISTENT); - Map<MetricId, List<MetricId>> outputNamesById = ImmutableMap.of( - ONE_ID, ImmutableList.of(ONE_ID), - TWO_ID, ImmutableList.of(TWO_ID, toMetricId("dos")), - THREE_ID, ImmutableList.of(toMetricId("3")), - NON_EXISTENT_ID, ImmutableList.of(NON_EXISTENT_ID)); + Map<MetricId, List<MetricId>> outputNamesById = Map.of( + ONE_ID, List.of(ONE_ID), + TWO_ID, List.of(TWO_ID, toMetricId("dos")), + THREE_ID, List.of(toMetricId("3")), + NON_EXISTENT_ID, List.of(NON_EXISTENT_ID)); MetricsPacket packet = new MetricsPacket.Builder(toServiceId("foo")) - .putMetrics(ImmutableList.of( + .putMetrics(List.of( new Metric(ONE_ID, 1), new Metric(TWO_ID, 2), new Metric(THREE_ID, 3))) diff --git a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServicesTest.java b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServicesTest.java index dda8af8559b..f7bfdb0e76f 100644 --- a/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServicesTest.java +++ b/metrics-proxy/src/test/java/ai/vespa/metricsproxy/service/VespaServicesTest.java @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.metricsproxy.service; -import com.google.common.collect.ImmutableList; import org.junit.Test; import java.util.List; @@ -18,7 +17,7 @@ public class VespaServicesTest { @Test public void services_can_be_retrieved_from_monitoring_name() { - List<VespaService> dummyServices = ImmutableList.of( + List<VespaService> dummyServices = List.of( new DummyService(0, "dummy/id/0"), new DummyService(1, "dummy/id/1")); VespaServices services = new VespaServices(dummyServices); @@ -28,7 +27,7 @@ public class VespaServicesTest { @Test public void all_services_can_be_retrieved_by_using_special_name() { - List<VespaService> dummyServices = ImmutableList.of( + List<VespaService> dummyServices = List.of( new DummyService(0, "dummy/id/0")); VespaServices services = new VespaServices(dummyServices); diff --git a/model-evaluation/src/main/java/ai/vespa/models/evaluation/Model.java b/model-evaluation/src/main/java/ai/vespa/models/evaluation/Model.java index 65515deee51..1ecec4108a3 100644 --- a/model-evaluation/src/main/java/ai/vespa/models/evaluation/Model.java +++ b/model-evaluation/src/main/java/ai/vespa/models/evaluation/Model.java @@ -2,13 +2,10 @@ package ai.vespa.models.evaluation; import com.yahoo.api.annotations.Beta; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.yahoo.searchlib.rankingexpression.ExpressionFunction; import com.yahoo.searchlib.rankingexpression.evaluation.ContextIndex; -import com.yahoo.searchlib.rankingexpression.evaluation.DoubleValue; import com.yahoo.searchlib.rankingexpression.evaluation.ExpressionOptimizer; -import com.yahoo.searchlib.rankingexpression.evaluation.Value; import com.yahoo.tensor.TensorType; import java.util.Arrays; @@ -32,10 +29,10 @@ public class Model { private final String name; /** Free functions */ - private final ImmutableList<ExpressionFunction> functions; + private final List<ExpressionFunction> functions; /** The subset of the free functions which are public (additional non-public methods are generated during import) */ - private final ImmutableList<ExpressionFunction> publicFunctions; + private final List<ExpressionFunction> publicFunctions; /** Instances of each usage of the above function, where variables (if any) are replaced by their bindings */ private final ImmutableMap<FunctionReference, ExpressionFunction> referencedFunctions; @@ -67,7 +64,7 @@ public class Model { try { LazyArrayContext context = new LazyArrayContext(function.getValue(), referencedFunctions, constants, onnxModels, this); contextBuilder.put(function.getValue().getName(), context); - if ( ! function.getValue().returnType().isPresent()) { + if (function.getValue().returnType().isEmpty()) { functions.put(function.getKey(), function.getValue().withReturnType(TensorType.empty)); } @@ -96,10 +93,9 @@ public class Model { } } this.contextPrototypes = contextBuilder.build(); - this.functions = ImmutableList.copyOf(functions.values()); - this.publicFunctions = ImmutableList.copyOf(functions.values().stream() - .filter(f -> ! f.getName().startsWith(INTERMEDIATE_OPERATION_FUNCTION_PREFIX)) - .collect(Collectors.toList())); + this.functions = List.copyOf(functions.values()); + this.publicFunctions = functions.values().stream() + .filter(f -> !f.getName().startsWith(INTERMEDIATE_OPERATION_FUNCTION_PREFIX)).toList(); // Optimize functions ImmutableMap.Builder<FunctionReference, ExpressionFunction> functionsBuilder = new ImmutableMap.Builder<>(); @@ -129,20 +125,11 @@ public class Model { } /** Returns the given function, or throws a IllegalArgumentException if it does not exist */ - ExpressionFunction requireFunction(String name) { - ExpressionFunction function = function(name); - if (function == null) - throw new IllegalArgumentException("No function named '" + name + "' in " + this + ". Available functions: " + - functions.stream().map(f -> f.getName()).collect(Collectors.joining(", "))); - return function; - } - - /** Returns the given function, or throws a IllegalArgumentException if it does not exist */ private LazyArrayContext requireContextPrototype(String name) { LazyArrayContext context = contextPrototypes.get(name); if (context == null) // Implies function is not present throw new IllegalArgumentException("No function named '" + name + "' in " + this + ". Available functions: " + - functions.stream().map(f -> f.getName()).collect(Collectors.joining(", "))); + functions.stream().map(ExpressionFunction::getName).collect(Collectors.joining(", "))); return context; } @@ -234,7 +221,7 @@ public class Model { private void throwUndeterminedFunction(String message) { throw new IllegalArgumentException(message + ". Available functions: " + - functions.stream().map(f -> f.getName()).collect(Collectors.joining(", "))); + functions.stream().map(ExpressionFunction::getName).collect(Collectors.joining(", "))); } @Override diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java index 1e745b61eaa..5fe9eef7e73 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/persistence/CuratorDatabase.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.hosted.provision.persistence; import com.google.common.cache.AbstractCache; -import com.google.common.collect.ImmutableList; import com.yahoo.config.provision.HostName; import com.yahoo.path.Path; import com.yahoo.transaction.NestedTransaction; @@ -155,7 +154,7 @@ public class CuratorDatabase { @Override public List<String> getChildren(Path path) { - return get(children, path, () -> ImmutableList.copyOf(curator.getChildren(path))); + return get(children, path, () -> List.copyOf(curator.getChildren(path))); } @Override diff --git a/vespajlib/src/main/java/com/yahoo/collections/ListMap.java b/vespajlib/src/main/java/com/yahoo/collections/ListMap.java index b73f50fe00f..d802012e71a 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/ListMap.java +++ b/vespajlib/src/main/java/com/yahoo/collections/ListMap.java @@ -1,9 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; @@ -48,21 +45,13 @@ public class ListMap<K, V> { /** Puts an element into this. Multiple elements at the same position are added to the list at this key */ public void put(K key, V value) { - List<V> list = map.get(key); - if (list == null) { - list = new ArrayList<>(); - map.put(key, list); - } + List<V> list = map.computeIfAbsent(key, k -> new ArrayList<>()); list.add(value); } /** Put a key without adding a new value, such that there is an empty list of values if no values are already added */ public void put(K key) { - List<V> list = map.get(key); - if (list == null) { - list = new ArrayList<>(); - map.put(key, list); - } + map.computeIfAbsent(key, k -> new ArrayList<>()); } /** Put this map in the state where it has just the given value of the given key */ @@ -110,7 +99,7 @@ public class ListMap<K, V> { */ public List<V> get(K key) { List<V> list = map.get(key); - if (list == null) return ImmutableList.of();; + if (list == null) return List.of();; return list; } @@ -137,8 +126,8 @@ public class ListMap<K, V> { frozen = true; for (Map.Entry<K,List<V>> entry : map.entrySet()) - entry.setValue(ImmutableList.copyOf(entry.getValue())); - this.map = ImmutableMap.copyOf(this.map); + entry.setValue(List.copyOf(entry.getValue())); + this.map = Map.copyOf(this.map); } /** Returns whether this allows changes */ diff --git a/vespajlib/src/main/java/com/yahoo/errorhandling/Results.java b/vespajlib/src/main/java/com/yahoo/errorhandling/Results.java index 89dd44cb9fc..917b7251c15 100644 --- a/vespajlib/src/main/java/com/yahoo/errorhandling/Results.java +++ b/vespajlib/src/main/java/com/yahoo/errorhandling/Results.java @@ -1,11 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.errorhandling; -import com.google.common.collect.ImmutableList; - import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; /** @@ -17,8 +14,8 @@ public class Results<DATA, ERROR> { private final List<ERROR> errors; public Results(List<DATA> data, List<ERROR> errors) { - this.data = ImmutableList.copyOf(data); - this.errors = ImmutableList.copyOf(errors); + this.data = List.copyOf(data); + this.errors = List.copyOf(errors); } public boolean hasErrors() { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java index 50809ab3ff6..996d85b3199 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/IndexedTensor.java @@ -1,19 +1,16 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.NoSuchElementException; import java.util.Optional; import java.util.Set; -import java.util.function.DoubleBinaryOperator; /** * An indexed (dense) tensor. @@ -202,7 +199,7 @@ public abstract class IndexedTensor implements Tensor { @Override public Map<TensorAddress, Double> cells() { if (dimensionSizes.dimensions() == 0) - return Collections.singletonMap(TensorAddress.of(), get(0)); + return Map.of(TensorAddress.of(), get(0)); ImmutableMap.Builder<TensorAddress, Double> builder = new ImmutableMap.Builder<>(); Indexes indexes = Indexes.of(dimensionSizes, dimensionSizes, size()); @@ -574,7 +571,7 @@ public abstract class IndexedTensor implements Tensor { throw new IllegalArgumentException("Wrong number of indexes (" + indexes.length + ") for " + type); if (indexes.length == 0) { - firstDimension = Collections.singletonList(value); + firstDimension = List.of(value); return this; } @@ -767,7 +764,7 @@ public abstract class IndexedTensor implements Tensor { private final static class LazyCell extends Tensor.Cell { private double value; - private Indexes indexes; + private final Indexes indexes; private LazyCell(Indexes indexes, Double value) { super(null, value); @@ -919,10 +916,9 @@ public abstract class IndexedTensor implements Tensor { /** Returns an immutable list containing a copy of the indexes in this */ public List<Long> toList() { - ImmutableList.Builder<Long> builder = new ImmutableList.Builder<>(); - for (long index : indexes) - builder.add(index); - return builder.build(); + ArrayList<Long> list = new ArrayList<>(indexes.length); + for(long index : indexes) { list.add(index); } + return List.copyOf(list); } @Override diff --git a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java index e7690876434..fed9f7017ed 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java @@ -11,7 +11,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.function.DoubleBinaryOperator; import java.util.stream.Collectors; /** diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmax.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmax.java index d2762ad762d..2ee3d7dab60 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmax.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmax.java @@ -1,10 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor.functions; -import com.google.common.collect.ImmutableList; import com.yahoo.tensor.evaluation.Name; -import java.util.Collections; import java.util.List; import java.util.Objects; @@ -17,21 +15,21 @@ public class Argmax<NAMETYPE extends Name> extends CompositeTensorFunction<NAMET private final List<String> dimensions; public Argmax(TensorFunction<NAMETYPE> argument) { - this(argument, Collections.emptyList()); + this(argument, List.of()); } public Argmax(TensorFunction<NAMETYPE> argument, String dimension) { - this(argument, Collections.singletonList(dimension)); + this(argument, List.of(dimension)); } public Argmax(TensorFunction<NAMETYPE> argument, List<String> dimensions) { Objects.requireNonNull(dimensions, "The dimensions cannot be null"); this.argument = argument; - this.dimensions = ImmutableList.copyOf(dimensions); + this.dimensions = List.copyOf(dimensions); } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.singletonList(argument); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmin.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmin.java index baedf41bcb8..a1e30c419e3 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmin.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Argmin.java @@ -1,10 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor.functions; -import com.google.common.collect.ImmutableList; import com.yahoo.tensor.evaluation.Name; -import java.util.Collections; import java.util.List; import java.util.Objects; @@ -17,21 +15,21 @@ public class Argmin<NAMETYPE extends Name> extends CompositeTensorFunction<NAMET private final List<String> dimensions; public Argmin(TensorFunction<NAMETYPE> argument) { - this(argument, Collections.emptyList()); + this(argument, List.of()); } public Argmin(TensorFunction<NAMETYPE> argument, String dimension) { - this(argument, Collections.singletonList(dimension)); + this(argument, List.of(dimension)); } public Argmin(TensorFunction<NAMETYPE> argument, List<String> dimensions) { Objects.requireNonNull(dimensions, "The dimensions cannot be null"); this.argument = argument; - this.dimensions = ImmutableList.copyOf(dimensions); + this.dimensions = List.copyOf(dimensions); } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.singletonList(argument); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java index abf0d89c2b7..2a93acc19e6 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Concat.java @@ -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.tensor.functions; -import com.google.common.collect.ImmutableList; import com.yahoo.tensor.DimensionSizes; import com.yahoo.tensor.IndexedTensor; import com.yahoo.tensor.Tensor; @@ -46,7 +45,7 @@ public class Concat<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return ImmutableList.of(argumentA, argumentB); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argumentA, argumentB); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { @@ -362,20 +361,11 @@ public class Concat<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET int b = 0; for (var how : plan.combineHow) { switch (how) { - case left: - labels[out++] = leftOnly.label(a++); - break; - case right: - labels[out++] = rightOnly.label(b++); - break; - case both: - labels[out++] = match.label(m++); - break; - case concat: - labels[out++] = String.valueOf(concatDimIdx); - break; - default: - throw new IllegalArgumentException("cannot handle: "+how); + case left -> labels[out++] = leftOnly.label(a++); + case right -> labels[out++] = rightOnly.label(b++); + case both -> labels[out++] = match.label(m++); + case concat -> labels[out++] = String.valueOf(concatDimIdx); + default -> throw new IllegalArgumentException("cannot handle: " + how); } } return TensorAddress.of(labels); @@ -419,17 +409,10 @@ public class Concat<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET int separateIdx = 0; for (int i = 0; i < how.handleDims.size(); i++) { switch (how.handleDims.get(i)) { - case common: - commonLabels[commonIdx++] = addr.label(i); - break; - case separate: - separateLabels[separateIdx++] = addr.label(i); - break; - case concat: - ccDimIndex = addr.numericLabel(i); - break; - default: - throw new IllegalArgumentException("cannot handle: "+how.handleDims.get(i)); + case common -> commonLabels[commonIdx++] = addr.label(i); + case separate -> separateLabels[separateIdx++] = addr.label(i); + case concat -> ccDimIndex = addr.numericLabel(i); + default -> throw new IllegalArgumentException("cannot handle: " + how.handleDims.get(i)); } } TensorAddress commonAddr = TensorAddress.of(commonLabels); diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/DynamicTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/DynamicTensor.java index c402a1bde5b..558b01baa02 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/DynamicTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/DynamicTensor.java @@ -10,7 +10,6 @@ import com.yahoo.tensor.evaluation.EvaluationContext; import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -32,7 +31,7 @@ public abstract class DynamicTensor<NAMETYPE extends Name> extends PrimitiveTens public TensorType type(TypeContext<NAMETYPE> context) { return type; } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.emptyList(); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java index 1009177761b..61060b700a3 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Join.java @@ -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.tensor.functions; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; import com.yahoo.tensor.DimensionSizes; import com.yahoo.tensor.IndexedTensor; @@ -15,7 +14,6 @@ import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -60,7 +58,7 @@ public class Join<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYP public DoubleBinaryOperator combinator() { return combinator; } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return ImmutableList.of(argumentA, argumentB); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argumentA, argumentB); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { @@ -345,7 +343,7 @@ public class Join<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYP for (Iterator<Tensor.Cell> cellIterator = b.cellIterator(); cellIterator.hasNext(); ) { Tensor.Cell bCell = cellIterator.next(); TensorAddress partialCommonAddress = partialCommonAddress(bCell, bIndexesInCommon); - for (Tensor.Cell aCell : aCellsByCommonAddress.getOrDefault(partialCommonAddress, Collections.emptyList())) { + for (Tensor.Cell aCell : aCellsByCommonAddress.getOrDefault(partialCommonAddress, List.of())) { TensorAddress combinedAddress = joinAddresses(aCell.getKey(), aIndexesInJoined, bCell.getKey(), bIndexesInJoined, joinedType); if (combinedAddress == null) continue; // not combinable diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Matmul.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Matmul.java index 3239ab1a70c..a06053c88a4 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Matmul.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Matmul.java @@ -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.tensor.functions; -import com.google.common.collect.ImmutableList; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.Name; @@ -27,7 +26,7 @@ public class Matmul<NAMETYPE extends Name> extends CompositeTensorFunction<NAMET } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return ImmutableList.of(argument1, argument2); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument1, argument2); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Merge.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Merge.java index 2b9dc709e0e..86d3ca50bd7 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Merge.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Merge.java @@ -1,11 +1,7 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor.functions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Sets; -import com.yahoo.tensor.DimensionSizes; import com.yahoo.tensor.IndexedTensor; -import com.yahoo.tensor.PartialAddress; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; @@ -14,15 +10,10 @@ import com.yahoo.tensor.evaluation.EvaluationContext; import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Optional; -import java.util.Set; import java.util.function.DoubleBinaryOperator; /** @@ -55,7 +46,7 @@ public class Merge<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETY public DoubleBinaryOperator merger() { return merger; } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return ImmutableList.of(argumentA, argumentB); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argumentA, argumentB); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Reduce.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Reduce.java index 96465de6c0f..83d5187f116 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Reduce.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Reduce.java @@ -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.tensor.functions; -import com.google.common.collect.ImmutableList; import com.yahoo.tensor.IndexedTensor; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; @@ -37,12 +36,12 @@ public class Reduce<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET /** Creates a reduce function reducing all dimensions */ public Reduce(TensorFunction<NAMETYPE> argument, Aggregator aggregator) { - this(argument, aggregator, Collections.emptyList()); + this(argument, aggregator, List.of()); } /** Creates a reduce function reducing a single dimension */ public Reduce(TensorFunction<NAMETYPE> argument, Aggregator aggregator, String dimension) { - this(argument, aggregator, Collections.singletonList(dimension)); + this(argument, aggregator, List.of(dimension)); } /** @@ -57,7 +56,7 @@ public class Reduce<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET public Reduce(TensorFunction<NAMETYPE> argument, Aggregator aggregator, List<String> dimensions) { this.argument = Objects.requireNonNull(argument, "The argument tensor cannot be null"); this.aggregator = Objects.requireNonNull(aggregator, "The aggregator cannot be null"); - this.dimensions = ImmutableList.copyOf(dimensions); + this.dimensions = List.copyOf(dimensions); } public static TensorType outputType(TensorType inputType, List<String> reduceDimensions) { @@ -71,7 +70,7 @@ public class Reduce<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET List<String> dimensions() { return dimensions; } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.singletonList(argument); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { @@ -174,16 +173,16 @@ public class Reduce<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET static abstract class ValueAggregator { static ValueAggregator ofType(Aggregator aggregator) { - switch (aggregator) { - case avg : return new AvgAggregator(); - case count : return new CountAggregator(); - case max : return new MaxAggregator(); - case median : return new MedianAggregator(); - case min : return new MinAggregator(); - case prod : return new ProdAggregator(); - case sum : return new SumAggregator(); - default: throw new UnsupportedOperationException("Aggregator " + aggregator + " is not implemented"); - } + return switch (aggregator) { + case avg -> new AvgAggregator(); + case count -> new CountAggregator(); + case max -> new MaxAggregator(); + case median -> new MedianAggregator(); + case min -> new MinAggregator(); + case prod -> new ProdAggregator(); + case sum -> new SumAggregator(); + default -> throw new UnsupportedOperationException("Aggregator " + aggregator + " is not implemented"); + }; } diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/ReduceJoin.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/ReduceJoin.java index ccb437ef5a7..1048e5ab10e 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/ReduceJoin.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/ReduceJoin.java @@ -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.tensor.functions; -import com.google.common.collect.ImmutableList; import com.yahoo.tensor.DimensionSizes; import com.yahoo.tensor.IndexedTensor; import com.yahoo.tensor.Tensor; @@ -47,12 +46,12 @@ public class ReduceJoin<NAMETYPE extends Name> extends CompositeTensorFunction<N this.argumentB = argumentB; this.combinator = combinator; this.aggregator = aggregator; - this.dimensions = ImmutableList.copyOf(dimensions); + this.dimensions = List.copyOf(dimensions); } @Override public List<TensorFunction<NAMETYPE>> arguments() { - return ImmutableList.of(argumentA, argumentB); + return List.of(argumentA, argumentB); } @Override diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java index 023e91e424f..8d58cee5e1e 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Rename.java @@ -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.tensor.functions; -import com.google.common.collect.ImmutableList; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorAddress; import com.yahoo.tensor.TensorType; @@ -10,7 +9,6 @@ import com.yahoo.tensor.evaluation.EvaluationContext; import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -30,7 +28,7 @@ public class Rename<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET private final Map<String, String> fromToMap; public Rename(TensorFunction<NAMETYPE> argument, String fromDimension, String toDimension) { - this(argument, ImmutableList.of(fromDimension), ImmutableList.of(toDimension)); + this(argument, List.of(fromDimension), List.of(toDimension)); } public Rename(TensorFunction<NAMETYPE> argument, List<String> fromDimensions, List<String> toDimensions) { @@ -43,8 +41,8 @@ public class Rename<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET throw new IllegalArgumentException("Rename from and to dimensions must be equal, was " + fromDimensions.size() + " and " + toDimensions.size()); this.argument = argument; - this.fromDimensions = ImmutableList.copyOf(fromDimensions); - this.toDimensions = ImmutableList.copyOf(toDimensions); + this.fromDimensions = List.copyOf(fromDimensions); + this.toDimensions = List.copyOf(toDimensions); this.fromToMap = fromToMap(fromDimensions, toDimensions); } @@ -59,7 +57,7 @@ public class Rename<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMET } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.singletonList(argument); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunctions.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunctions.java index 2639e153923..1057ffa9552 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunctions.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/ScalarFunctions.java @@ -1,8 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor.functions; -import com.google.common.collect.ImmutableList; - import java.util.Comparator; import java.util.List; import java.util.Objects; @@ -510,9 +508,9 @@ public class ScalarFunctions { // Variable-length operators ----------------------------------------------------------------------------- public static class EqualElements implements Function<List<Long>, Double> { - private final ImmutableList<String> argumentNames; + private final List<String> argumentNames; private EqualElements(List<String> argumentNames) { - this.argumentNames = ImmutableList.copyOf(argumentNames); + this.argumentNames = List.copyOf(argumentNames); } @Override @@ -553,9 +551,9 @@ public class ScalarFunctions { } public static class SumElements implements Function<List<Long>, Double> { - private final ImmutableList<String> argumentNames; + private final List<String> argumentNames; private SumElements(List<String> argumentNames) { - this.argumentNames = ImmutableList.copyOf(argumentNames); + this.argumentNames = List.copyOf(argumentNames); } @Override diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java index df8cd6d39cd..0853e1becf6 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java @@ -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.tensor.functions; -import com.google.common.collect.ImmutableList; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.Name; @@ -23,7 +22,7 @@ public class Softmax<NAMETYPE extends Name> extends CompositeTensorFunction<NAME } public static TensorType outputType(TensorType inputType, String dimension) { - return Reduce.outputType(inputType, ImmutableList.of(dimension)); + return Reduce.outputType(inputType, List.of(dimension)); } @Override diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/XwPlusB.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/XwPlusB.java index bd4fc7b8336..499cd31d700 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/XwPlusB.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/XwPlusB.java @@ -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.tensor.functions; -import com.google.common.collect.ImmutableList; import com.yahoo.tensor.evaluation.Name; import java.util.List; @@ -23,7 +22,7 @@ public class XwPlusB<NAMETYPE extends Name> extends CompositeTensorFunction<NAME } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return ImmutableList.of(x, w, b); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(x, w, b); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java b/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java index fb90fabb964..a177b07256b 100644 --- a/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java +++ b/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java @@ -1,11 +1,9 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.text; -import com.google.common.collect.ImmutableSet; - import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.io.ByteArrayOutputStream; import java.util.Set; @@ -212,12 +210,12 @@ public class StringUtilities { /** Splits a string on both space and comma */ public static Set<String> split(String s) { - if (s == null || s.isEmpty()) return Collections.emptySet(); - ImmutableSet.Builder<String> b = new ImmutableSet.Builder<>(); + if (s == null || s.isEmpty()) return Set.of(); + Set<String> b = new HashSet<>(); for (String item : s.split("[\\s,]")) if ( ! item.isEmpty()) b.add(item); - return b.build(); + return Set.copyOf(b); } } diff --git a/vespajlib/src/test/java/com/yahoo/stream/CustomCollectorsTest.java b/vespajlib/src/test/java/com/yahoo/stream/CustomCollectorsTest.java index a5b2accec48..b8a13525159 100644 --- a/vespajlib/src/test/java/com/yahoo/stream/CustomCollectorsTest.java +++ b/vespajlib/src/test/java/com/yahoo/stream/CustomCollectorsTest.java @@ -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.stream; -import com.google.common.collect.Lists; import com.yahoo.stream.CustomCollectors.DuplicateKeyException; import org.junit.Test; @@ -42,7 +41,7 @@ public class CustomCollectorsTest { @Test public void custom_map_collector_throws_exception_upon_duplicate_keys() { - List<String> duplicates = Lists.newArrayList("same", "same"); + List<String> duplicates = List.of("same", "same"); try { duplicates.stream().collect(toCustomMap(Function.identity(), Function.identity(), HashMap::new)); @@ -53,7 +52,7 @@ public class CustomCollectorsTest { } private static List<String> numberList() { - return Lists.newArrayList("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); + return List.of("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); } private static class CustomHashMap<K,V> extends HashMap<K,V> { diff --git a/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorTestCase.java index ba814f7ad54..09b989e4380 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/MappedTensorTestCase.java @@ -1,9 +1,10 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor; -import com.google.common.collect.Sets; import org.junit.Test; +import java.util.Set; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -34,7 +35,7 @@ public class MappedTensorTestCase { Tensor tensor = Tensor.Builder.of(type). cell().label("x", "0").value(1). cell().label("x", "1").value(2).build(); - assertEquals(Sets.newHashSet("x"), tensor.type().dimensionNames()); + assertEquals(Set.of("x"), tensor.type().dimensionNames()); assertEquals("tensor(x{}):{0:1.0, 1:2.0}", tensor.toString()); } @@ -44,7 +45,7 @@ public class MappedTensorTestCase { Tensor tensor = Tensor.Builder.of(type). cell().label("x", "0").label("y", "0").value(1). cell().label("x", "1").label("y", "0").value(2).build(); - assertEquals(Sets.newHashSet("x", "y"), tensor.type().dimensionNames()); + assertEquals(Set.of("x", "y"), tensor.type().dimensionNames()); assertEquals("tensor(x{},y{}):{{x:0,y:0}:1.0, {x:1,y:0}:2.0}", tensor.toString()); } diff --git a/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java index a26e56c4468..0b5b761224b 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/MixedTensorTestCase.java @@ -2,9 +2,10 @@ package com.yahoo.tensor; -import com.google.common.collect.Sets; import org.junit.Test; +import java.util.Set; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -40,7 +41,7 @@ public class MixedTensorTestCase { cell().label("y", 1).value(2). // {y:2} should be 0.0 and non NaN since we specify indexed size build(); - assertEquals(Sets.newHashSet("y"), tensor.type().dimensionNames()); + assertEquals(Set.of("y"), tensor.type().dimensionNames()); assertEquals("tensor(y[3]):[1.0, 2.0, 0.0]", tensor.toString()); } @@ -56,7 +57,7 @@ public class MixedTensorTestCase { cell().label("x", 1).label("y", 1).value(5). cell().label("x", 1).label("y", 2).value(6). build(); - assertEquals(Sets.newHashSet("x", "y"), tensor.type().dimensionNames()); + assertEquals(Set.of("x", "y"), tensor.type().dimensionNames()); assertEquals("tensor(x[2],y[3]):[[1.0, 2.0, 0.0], [4.0, 5.0, 6.0]]", tensor.toString()); } @@ -68,7 +69,7 @@ public class MixedTensorTestCase { cell().label("x", "0").value(1). cell().label("x", "1").value(2). build(); - assertEquals(Sets.newHashSet("x"), tensor.type().dimensionNames()); + assertEquals(Set.of("x"), tensor.type().dimensionNames()); assertEquals("tensor(x{}):{0:1.0, 1:2.0}", tensor.toString()); } @@ -83,7 +84,7 @@ public class MixedTensorTestCase { cell().label("x", "1").label("y", "1").value(5). cell().label("x", "1").label("y", "2").value(6). build(); - assertEquals(Sets.newHashSet("x", "y"), tensor.type().dimensionNames()); + assertEquals(Set.of("x", "y"), tensor.type().dimensionNames()); assertEquals("tensor(x{},y{}):{{x:0,y:0}:1.0, {x:0,y:1}:2.0, {x:1,y:0}:4.0, {x:1,y:1}:5.0, {x:1,y:2}:6.0}", tensor.toString()); } @@ -99,7 +100,7 @@ public class MixedTensorTestCase { cell().label("x", "2").label("y", 1).value(5). cell().label("x", "2").label("y", 2).value(6). build(); - assertEquals(Sets.newHashSet("x", "y"), tensor.type().dimensionNames()); + assertEquals(Set.of("x", "y"), tensor.type().dimensionNames()); assertEquals("tensor(x{},y[3]):{1:[1.0, 2.0, 0.0], 2:[4.0, 5.0, 6.0]}", tensor.toString()); } @@ -121,7 +122,7 @@ public class MixedTensorTestCase { cell().label("x", "x2").label("y", 2).label("z","z1").value(15). cell().label("x", "x2").label("y", 2).label("z","z2").value(16). build(); - assertEquals(Sets.newHashSet("x", "y", "z"), tensor.type().dimensionNames()); + assertEquals(Set.of("x", "y", "z"), tensor.type().dimensionNames()); assertEquals("tensor(x{},y[3],z{}):{{x:x1,y:0,z:z1}:1.0, {x:x1,y:0,z:z2}:2.0, {x:x1,y:1,z:z1}:3.0, " + "{x:x1,y:1,z:z2}:4.0, {x:x1,y:2,z:z1}:5.0, {x:x1,y:2,z:z2}:6.0, {x:x2,y:0,z:z1}:11.0, " + "{x:x2,y:0,z:z2}:12.0, {x:x2,y:1,z:z1}:13.0, {x:x2,y:1,z:z2}:14.0, {x:x2,y:2,z:z1}:15.0, {x:x2,y:2,z:z2}:16.0}", @@ -149,7 +150,7 @@ public class MixedTensorTestCase { cell().label("i", "b").label("k","d").label("j",1).label("l",0).value(15). cell().label("i", "b").label("k","d").label("j",1).label("l",1).value(16). build(); - assertEquals(Sets.newHashSet("i", "j", "k", "l"), tensor.type().dimensionNames()); + assertEquals(Set.of("i", "j", "k", "l"), tensor.type().dimensionNames()); assertEquals("tensor(i{},j[2],k{},l[2]):{{i:a,j:0,k:c,l:0}:1.0, {i:a,j:0,k:c,l:1}:2.0, " + "{i:a,j:0,k:d,l:0}:5.0, {i:a,j:0,k:d,l:1}:6.0, {i:a,j:1,k:c,l:0}:3.0, {i:a,j:1,k:c,l:1}:4.0, " + "{i:a,j:1,k:d,l:0}:7.0, {i:a,j:1,k:d,l:1}:8.0, {i:b,j:0,k:c,l:0}:9.0, {i:b,j:0,k:c,l:1}:10.0, " + diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java index 428c8a83b47..5e392a74bf3 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java @@ -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.tensor; -import com.google.common.collect.ImmutableList; import com.yahoo.tensor.evaluation.MapEvaluationContext; import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.VariableTensor; @@ -154,7 +153,7 @@ public class TensorTestCase { Tensor xy = Tensor.from("{{x:0,y:1}:11, {x:1,y:1}:13}"); double nest1 = y.multiply(x.multiply(xy).sum("x")).sum("y").asDouble(); double nest2 = x.multiply(xy).sum("x").multiply(y).sum("y").asDouble(); - double flat = y.multiply(x).multiply(xy).sum(ImmutableList.of("x","y")).asDouble(); + double flat = y.multiply(x).multiply(xy).sum(List.of("x","y")).asDouble(); assertEquals(nest1, flat, 0.000000001); assertEquals(nest2, flat, 0.000000001); } @@ -176,8 +175,8 @@ public class TensorTestCase { assertEquals(Tensor.from("{ {x:1,y:1}:0, {x:2,y:1}:1 }"), tensor1.larger(tensor2)); assertEquals(Tensor.from("{ {y:1}:50.0 }"), tensor1.matmul(tensor2, "x")); assertEquals(Tensor.from("{ {z:1}:3, {z:2}:7 }"), tensor1.rename("x", "z")); - assertEquals(Tensor.from("{ {y:1,x:1}:8, {x:1,y:2}:12 }"), tensor1.add(tensor2).rename(ImmutableList.of("x", "y"), - ImmutableList.of("y", "x"))); + assertEquals(Tensor.from("{ {y:1,x:1}:8, {x:1,y:2}:12 }"), tensor1.add(tensor2).rename(List.of("x", "y"), + List.of("y", "x"))); assertEquals(Tensor.from("{ {x:0,y:0}:0, {x:0,y:1}:0, {x:1,y:0}:0, {x:1,y:1}:1, {x:2,y:0}:0, {x:2,y:1}:2, }"), Tensor.generate(new TensorType.Builder().indexed("x", 3).indexed("y", 2).build(), (List<Long> indexes) -> (double)indexes.get(0)*indexes.get(1))); diff --git a/vespajlib/src/test/java/com/yahoo/tensor/functions/MatmulTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/functions/MatmulTestCase.java index fb4cb659624..1ac796ae9c5 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/functions/MatmulTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/functions/MatmulTestCase.java @@ -1,11 +1,12 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.tensor.functions; -import com.google.common.collect.ImmutableList; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; import org.junit.Test; +import java.util.List; + import static org.junit.Assert.assertEquals; /** @@ -41,7 +42,7 @@ public class MatmulTestCase { rb.cell(154,1, 1); Tensor r = rb.build(); - Tensor result = a.matmul(b.rename(ImmutableList.of("d0","d1"), ImmutableList.of("d1","d2")), "d1") + Tensor result = a.matmul(b.rename(List.of("d0","d1"), List.of("d1","d2")), "d1") .rename("d2","d1"); assertEquals(r, result); } @@ -90,7 +91,7 @@ public class MatmulTestCase { rb.cell(730,1, 1, 1); Tensor r = rb.build(); - Tensor result = a.matmul(b.rename(ImmutableList.of("d1","d2"), ImmutableList.of("d2","d3")), "d2") + Tensor result = a.matmul(b.rename(List.of("d1","d2"), List.of("d2","d3")), "d2") .rename("d3","d2"); assertEquals(r, result); } diff --git a/vespajlib/src/test/java/com/yahoo/text/Benchmark.java b/vespajlib/src/test/java/com/yahoo/text/Benchmark.java deleted file mode 100644 index 292503f462a..00000000000 --- a/vespajlib/src/test/java/com/yahoo/text/Benchmark.java +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.text; - -// import com.google.common.base.Preconditions; -// import com.google.inject.Provider; - -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.Callable; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; - -/** - * @author Simon Thoresen Hult - */ -class Benchmark { - - public static interface Task { - public long run(CyclicBarrier barrier, int numIterations) throws Exception; - } - - - public static class TaskProvider { - final Class<? extends Task> taskClass; - public Task get() { - try { - return taskClass.getDeclaredConstructor().newInstance(); - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - throw new RuntimeException(e); - } - } - public TaskProvider(final Class<? extends Task> taskClass) { - this.taskClass = taskClass; - } - } - - private final TaskProvider taskProvider; - private final int numIterationsPerThread; - private final int numThreads; - - private Benchmark(Builder builder) { - Objects.requireNonNull(builder.taskProvider, "taskProvider"); -/* - Preconditions.checkArgument(builder.numIterationsPerThread > 0, "numIterationsPerThread; %s", - builder.numIterationsPerThread); - Preconditions.checkArgument(builder.numThreads > 0, "numThreads; %s", - builder.numThreads); -*/ - taskProvider = builder.taskProvider; - numIterationsPerThread = builder.numIterationsPerThread; - numThreads = builder.numThreads; - } - - public long run() throws Exception { - final CyclicBarrier barrier = new CyclicBarrier(numThreads); - List<Callable<Long>> clients = new ArrayList<>(numThreads); - for (int i = 0; i < numThreads; ++i) { - final Task task = taskProvider.get(); - clients.add(new Callable<Long>() { - - @Override - public Long call() throws Exception { - return task.run(barrier, numIterationsPerThread); - } - }); - } - long maxNanosPerClient = 0; - for (Future<Long> result : Executors.newFixedThreadPool(numThreads).invokeAll(clients)) { - maxNanosPerClient = Math.max(maxNanosPerClient, result.get()); - } - return TimeUnit.SECONDS.toNanos(1) * numThreads * numIterationsPerThread / maxNanosPerClient; - } - - public static class Builder { - - private TaskProvider taskProvider; - private int numIterationsPerThread = 1000; - private int numThreads = 1; - - public Builder setNumThreads(int numThreads) { - this.numThreads = numThreads; - return this; - } - - public Builder setNumIterationsPerThread(int numIterationsPerThread) { - this.numIterationsPerThread = numIterationsPerThread; - return this; - } - - public Builder setTaskClass(final Class<? extends Task> taskClass) { - return setTaskProvider(new TaskProvider(taskClass)); - } - - public Builder setTaskProvider(TaskProvider taskProvider) { - this.taskProvider = taskProvider; - return this; - } - - public Benchmark build() { - return new Benchmark(this); - } - } - -} diff --git a/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java b/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java index 926d19f433f..098eaddacac 100644 --- a/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java +++ b/vespajlib/src/test/java/com/yahoo/text/Utf8TestCase.java @@ -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.text; -import com.google.common.collect.ImmutableMap; import org.junit.Ignore; import org.junit.Test; @@ -11,9 +10,9 @@ import java.nio.ByteBuffer; import java.nio.charset.CharsetEncoder; import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.Map; import java.util.function.Function; -import static com.yahoo.text.Lowercase.toLowerCase; import static com.yahoo.text.Utf8.calculateBytePositions; import static com.yahoo.text.Utf8.calculateStringPositions; import static org.hamcrest.CoreMatchers.equalTo; @@ -21,7 +20,6 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; /** * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> @@ -34,62 +32,6 @@ public class Utf8TestCase { 0x34, 0x355, 0x2567, 0xfff, 0xe987, 0x100abc }; - public void dumpSome() throws java.io.IOException { - int i = 32; - int j = 3; - int cnt = 0; - while (i < 0x110000) { - if (i < 0xD800 || i >= 0xE000) ++cnt; - i += j; - ++j; - } - System.out.println("allocate "+cnt+" array entries"); - int codes[] = new int[cnt]; - i = 32; - j = 3; - cnt = 0; - while (i < 0x110000) { - if (i < 0xD800 || i >= 0xE000) codes[cnt++] = i; - i += j; - ++j; - } - assertEquals(cnt, codes.length); - System.out.println("fill "+cnt+" array entries"); - String str = new String(codes, 0, cnt); - byte[] arr = Utf8.toBytes(str); - java.io.FileOutputStream fos = new java.io.FileOutputStream("random-long-utf8.dat"); - fos.write(arr); - fos.close(); - } - - public void dumpMore() throws java.io.IOException { - java.text.Normalizer.Form form = java.text.Normalizer.Form.NFKC; - - java.io.FileOutputStream fos = new java.io.FileOutputStream("lowercase-table.dat"); - for (int i = 0; i < 0x110000; i++) { - StringBuilder b = new StringBuilder(); - b.appendCodePoint(i); - String n1 = b.toString(); - String n2 = java.text.Normalizer.normalize(b, form); - if (n1.equals(n2)) { - String l = toLowerCase(n1); - int chars = l.length(); - int codes = l.codePointCount(0, chars); - if (codes != 1) { - System.out.println("codepoint "+i+" transformed into "+codes+" codepoints: "+n1+" -> "+l); - } else { - int lc = l.codePointAt(0); - if (lc != i) { - String o = "lowercase( "+i+" )= "+lc+"\n"; - byte[] arr = Utf8.toBytes(o); - fos.write(arr); - } - } - } - } - fos.close(); - } - @Test public void testSimple() { String s1 = "test"; @@ -322,7 +264,7 @@ public class Utf8TestCase { for (char c=0; c < i; c++) { sb.append(c); } - assertTrue(Arrays.equals(Utf8.toBytesStd(sb.toString()), Utf8.toBytes(sb.toString()))); + assertArrayEquals(Utf8.toBytesStd(sb.toString()), Utf8.toBytes(sb.toString())); } } @@ -340,7 +282,7 @@ public class Utf8TestCase { byte [] a = Utf8.toBytes(String.valueOf(l)); byte [] b = Utf8.toAsciiBytes(l); if (!Arrays.equals(a, b)) { - assertTrue(Arrays.equals(a, b)); + assertArrayEquals(a, b); } } @@ -348,8 +290,8 @@ public class Utf8TestCase { public void testBoolean() { assertEquals("true", String.valueOf(true)); assertEquals("false", String.valueOf(false)); - assertTrue(Arrays.equals(Utf8.toAsciiBytes(true), new Utf8String(String.valueOf(true)).getBytes())); - assertTrue(Arrays.equals(Utf8.toAsciiBytes(false), new Utf8String(String.valueOf(false)).getBytes())); + assertArrayEquals(Utf8.toAsciiBytes(true), new Utf8String(String.valueOf(true)).getBytes()); + assertArrayEquals(Utf8.toAsciiBytes(false), new Utf8String(String.valueOf(false)).getBytes()); } @Test public void testInt() @@ -358,7 +300,7 @@ public class Utf8TestCase { byte [] a = Utf8.toBytes(String.valueOf(l)); byte [] b = Utf8.toAsciiBytes(l); if (!Arrays.equals(a, b)) { - assertTrue(Arrays.equals(a, b)); + assertArrayEquals(a, b); } } } @@ -369,7 +311,7 @@ public class Utf8TestCase { byte [] a = Utf8.toBytes(String.valueOf(l)); byte [] b = Utf8.toAsciiBytes(l); if (!Arrays.equals(a, b)) { - assertTrue(Arrays.equals(a, b)); + assertArrayEquals(a, b); } } } @@ -561,7 +503,7 @@ public class Utf8TestCase { byte[] unicode = "This is just sort of random mix. \u5370\u57df\u60c5\u5831\u53EF\u4EE5\u6709x\u00e9\u00e8".getBytes(StandardCharsets.UTF_8); int iterations = 100_000; // Use 100_000+ for benchmarking - ImmutableMap.of("ascii", ascii, "unicode", unicode).forEach((type, b) -> { + Map.of("ascii", ascii, "unicode", unicode).forEach((type, b) -> { long time1 = benchmark(() -> decode(Utf8::toString, b, iterations)); System.out.printf("Utf8::toString of %s string took %d ms\n", type, time1); long time2 = benchmark(() -> decode((b1) -> new String(b1, StandardCharsets.UTF_8), b, iterations)); @@ -578,7 +520,7 @@ public class Utf8TestCase { String unicode = "This is just sort of random mix. \u5370\u57df\u60c5\u5831\u53EF\u4EE5\u6709x\u00e9\u00e8"; int iterations = 1_000_000; // Use 1_000_000+ for benchmarking - ImmutableMap.of("ascii", ascii, "unicode", unicode).forEach((type, s) -> { + Map.of("ascii", ascii, "unicode", unicode).forEach((type, s) -> { long time1 = benchmark(() -> encode(Utf8::toBytes, s, iterations)); System.out.printf("Utf8::toBytes of %s string took %d ms\n", type, time1); long time2 = benchmark(() -> encode((s1) -> s1.getBytes(StandardCharsets.UTF_8), s, iterations)); |