diff options
author | Bjørn Christian Seime <bjorn.christian@seime.no> | 2022-12-02 14:52:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-02 14:52:26 +0100 |
commit | 81b884ac555806ae2f0a75773accfd8fe27ecbe1 (patch) | |
tree | 0f92b9ef73a90854cacc96796562d3f21ff1cff6 /vespajlib/src | |
parent | c956ac4cb73b329243072aabe35f0da508c02d0f (diff) |
Revert "Let list handling catch up with Java 17"
Diffstat (limited to 'vespajlib/src')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/tensor/MixedTensor.java | 28 |
1 files changed, 15 insertions, 13 deletions
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<Cell> cells; + private final ImmutableList<Cell> cells; /** An index structure over the cell list */ private final Index index; - private MixedTensor(TensorType type, List<Cell> cells, Index index) { + private MixedTensor(TensorType type, ImmutableList<Cell> 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<Double> valueIterator() { return new Iterator<>() { - final Iterator<Cell> cellIterator = cellIterator(); + Iterator<Cell> 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<Cell> builder = new ArrayList<>(); + ImmutableList.Builder<Cell> builder = new ImmutableList.Builder<>(); for (Map.Entry<TensorAddress, double[]> 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<TensorAddress, Double> cells; + private Map<TensorAddress, Double> 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); } |