From 81b884ac555806ae2f0a75773accfd8fe27ecbe1 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Fri, 2 Dec 2022 14:52:26 +0100 Subject: Revert "Let list handling catch up with Java 17" --- .../main/java/com/yahoo/tensor/MixedTensor.java | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'vespajlib/src/main/java/com/yahoo') diff --git a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java index 2027dcfb60f..fed9f7017ed 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java @@ -2,6 +2,7 @@ package com.yahoo.tensor; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import java.util.ArrayList; @@ -10,6 +11,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; /** * A mixed tensor type. This is class is currently suitable for serialization @@ -28,14 +30,14 @@ public class MixedTensor implements Tensor { private final TensorType type; /** The list of cells in the tensor */ - private final List cells; + private final ImmutableList cells; /** An index structure over the cell list */ private final Index index; - private MixedTensor(TensorType type, List cells, Index index) { + private MixedTensor(TensorType type, ImmutableList cells, Index index) { this.type = type; - this.cells = List.copyOf(cells); + this.cells = ImmutableList.copyOf(cells); this.index = index; } @@ -89,7 +91,7 @@ public class MixedTensor implements Tensor { @Override public Iterator valueIterator() { return new Iterator<>() { - final Iterator cellIterator = cellIterator(); + Iterator cellIterator = cellIterator(); @Override public boolean hasNext() { return cellIterator.hasNext(); @@ -152,14 +154,14 @@ public class MixedTensor implements Tensor { @Override public String toAbbreviatedString(boolean withType, boolean shortForms) { - return toString(withType, shortForms, Math.max(2, 10 / (type().dimensions().stream().filter(TensorType.Dimension::isMapped).count() + 1))); + return toString(withType, shortForms, Math.max(2, 10 / (type().dimensions().stream().filter(d -> d.isMapped()).count() + 1))); } private String toString(boolean withType, boolean shortForms, long maxCells) { if (! shortForms || type.rank() == 0 - || type.rank() > 1 && type.dimensions().stream().filter(TensorType.Dimension::isIndexed).anyMatch(d -> d.size().isEmpty()) - || type.dimensions().stream().filter(TensorType.Dimension::isMapped).count() > 1) + || type.rank() > 1 && type.dimensions().stream().filter(d -> d.isIndexed()).anyMatch(d -> d.size().isEmpty()) + || type.dimensions().stream().filter(d -> d.isMapped()).count() > 1) return Tensor.toStandardString(this, withType, shortForms, maxCells); return (withType ? type + ":" : "") + index.contentToString(this, maxCells); @@ -241,7 +243,7 @@ public class MixedTensor implements Tensor { indexBuilder = new Index.Builder(type); index = indexBuilder.index(); denseSubtype = new TensorType(type.valueType(), - type.dimensions().stream().filter(TensorType.Dimension::isIndexed).toList()); + type.dimensions().stream().filter(d -> d.isIndexed()).collect(Collectors.toList())); } public long denseSubspaceSize() { @@ -288,7 +290,7 @@ public class MixedTensor implements Tensor { @Override public MixedTensor build() { long count = 0; - List builder = new ArrayList<>(); + ImmutableList.Builder builder = new ImmutableList.Builder<>(); for (Map.Entry entry : denseSubspaceMap.entrySet()) { TensorAddress sparsePart = entry.getKey(); @@ -302,7 +304,7 @@ public class MixedTensor implements Tensor { count++; } } - return new MixedTensor(type, builder, indexBuilder.build()); + return new MixedTensor(type, builder.build(), indexBuilder.build()); } } @@ -317,7 +319,7 @@ public class MixedTensor implements Tensor { */ public static class UnboundBuilder extends Builder { - private final Map cells; + private Map cells; private final long[] dimensionBounds; private UnboundBuilder(TensorType type) { @@ -392,8 +394,8 @@ public class MixedTensor implements Tensor { private Index(TensorType type) { this.type = type; - this.mappedDimensions = type.dimensions().stream().filter(d -> !d.isIndexed()).toList(); - this.indexedDimensions = type.dimensions().stream().filter(TensorType.Dimension::isIndexed).toList(); + this.mappedDimensions = type.dimensions().stream().filter(d -> !d.isIndexed()).collect(Collectors.toList()); + this.indexedDimensions = type.dimensions().stream().filter(d -> d.isIndexed()).collect(Collectors.toList()); this.sparseType = createPartialType(type.valueType(), mappedDimensions); this.denseType = createPartialType(type.valueType(), indexedDimensions); } -- cgit v1.2.3