summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2019-10-08 14:15:51 +0200
committerJon Bratseth <bratseth@verizonmedia.com>2019-10-08 14:15:51 +0200
commit8fb3b2c9d19c29909a84eb9cef883031a6b13000 (patch)
tree14f8b0e357b63c09f0c1f8fce61853430441e2c4 /document
parent4a720e1feb149158f5868b1739bc28821486a6e1 (diff)
Simplify
Diffstat (limited to 'document')
-rw-r--r--document/src/main/java/com/yahoo/document/json/readers/TensorReader.java30
1 files changed, 10 insertions, 20 deletions
diff --git a/document/src/main/java/com/yahoo/document/json/readers/TensorReader.java b/document/src/main/java/com/yahoo/document/json/readers/TensorReader.java
index 90714476ac2..7b5fcfed0db 100644
--- a/document/src/main/java/com/yahoo/document/json/readers/TensorReader.java
+++ b/document/src/main/java/com/yahoo/document/json/readers/TensorReader.java
@@ -3,11 +3,7 @@ package com.yahoo.document.json.readers;
import com.yahoo.document.datatypes.TensorFieldValue;
import com.yahoo.document.json.TokenBuffer;
-import com.yahoo.lang.MutableInteger;
-import com.yahoo.slime.ArrayTraverser;
-import com.yahoo.slime.Type;
import com.yahoo.tensor.IndexedTensor;
-import com.yahoo.tensor.MappedTensor;
import com.yahoo.tensor.MixedTensor;
import com.yahoo.tensor.Tensor;
import com.yahoo.tensor.TensorAddress;
@@ -60,30 +56,24 @@ public class TensorReader {
private static void readTensorCell(TokenBuffer buffer, Tensor.Builder builder) {
expectObjectStart(buffer.currentToken());
+
+ TensorAddress address = null;
+ Double value = null;
int initNesting = buffer.nesting();
- double cellValue = 0.0;
- Tensor.Builder.CellBuilder cellBuilder = builder.cell();
for (buffer.next(); buffer.nesting() >= initNesting; buffer.next()) {
String currentName = buffer.currentName();
if (TensorReader.TENSOR_ADDRESS.equals(currentName)) {
- readTensorAddress(buffer, cellBuilder);
+ address = readAddress(buffer, builder.type());
} else if (TensorReader.TENSOR_VALUE.equals(currentName)) {
- cellValue = readDouble(buffer);
+ value = readDouble(buffer);
}
}
expectObjectEnd(buffer.currentToken());
- cellBuilder.value(cellValue);
- }
-
- private static void readTensorAddress(TokenBuffer buffer, MappedTensor.Builder.CellBuilder cellBuilder) {
- expectObjectStart(buffer.currentToken());
- int initNesting = buffer.nesting();
- for (buffer.next(); buffer.nesting() >= initNesting; buffer.next()) {
- String dimension = buffer.currentName();
- String label = buffer.currentText();
- cellBuilder.label(dimension, label);
- }
- expectObjectEnd(buffer.currentToken());
+ if (address == null)
+ throw new IllegalArgumentException("Expected an object in a tensor 'cells' array to contain an 'address' field");
+ if (value == null)
+ throw new IllegalArgumentException("Expected an object in a tensor 'cells' array to contain a 'value' field");
+ builder.cell(address, value);
}
private static void readTensorValues(TokenBuffer buffer, Tensor.Builder builder) {