diff options
author | Olli Virtanen <olli.virtanen@oath.com> | 2019-03-13 10:53:48 +0100 |
---|---|---|
committer | Olli Virtanen <olli.virtanen@oath.com> | 2019-03-13 10:53:48 +0100 |
commit | cd43364b451b40936fd2e21cb868820438536d78 (patch) | |
tree | eb8e3b0db1c771dfc171a5aa7ca2e15d80fbe8e7 /searchlib | |
parent | d442809e57f4477ca57d107252d6b908f2e07d8a (diff) |
Relocate MapConverter
Diffstat (limited to 'searchlib')
-rw-r--r-- | searchlib/src/main/java/com/yahoo/searchlib/protobuf/MapConverter.java | 73 | ||||
-rw-r--r-- | searchlib/src/main/java/com/yahoo/searchlib/protobuf/package-info.java | 5 |
2 files changed, 0 insertions, 78 deletions
diff --git a/searchlib/src/main/java/com/yahoo/searchlib/protobuf/MapConverter.java b/searchlib/src/main/java/com/yahoo/searchlib/protobuf/MapConverter.java deleted file mode 100644 index 4de8e3b5bb0..00000000000 --- a/searchlib/src/main/java/com/yahoo/searchlib/protobuf/MapConverter.java +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.searchlib.protobuf; - -import ai.vespa.searchlib.searchprotocol.protobuf.Search.StringProperty; -import ai.vespa.searchlib.searchprotocol.protobuf.Search.TensorProperty; -import com.google.protobuf.ByteString; -import com.yahoo.tensor.Tensor; -import com.yahoo.tensor.serialization.TypedBinaryFormat; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -/** - * @author ollivir - */ -public class MapConverter { - @FunctionalInterface - public interface PropertyInserter<T> { - void add(T prop); - } - - public static void convertMapTensors(Map<String, Object> map, PropertyInserter<TensorProperty.Builder> inserter) { - for (var entry : map.entrySet()) { - var value = entry.getValue(); - if (value instanceof Tensor) { - byte[] tensor = TypedBinaryFormat.encode((Tensor) value); - inserter.add(TensorProperty.newBuilder().setName(entry.getKey()).setValue(ByteString.copyFrom(tensor))); - } - } - } - - public static void convertMapStrings(Map<String, Object> map, PropertyInserter<StringProperty.Builder> inserter) { - for (var entry : map.entrySet()) { - var value = entry.getValue(); - if (!(value instanceof Tensor)) { - inserter.add(StringProperty.newBuilder().setName(entry.getKey()).addValues(value.toString())); - } - } - } - - public static void convertStringMultiMap(Map<String, List<String>> map, PropertyInserter<StringProperty.Builder> inserter) { - for (var entry : map.entrySet()) { - var values = entry.getValue(); - if (values != null) { - inserter.add(StringProperty.newBuilder().setName(entry.getKey()).addAllValues(values)); - } - } - } - - public static void convertMultiMap(Map<String, List<Object>> map, PropertyInserter<StringProperty.Builder> stringInserter, - PropertyInserter<TensorProperty.Builder> tensorInserter) { - for (var entry : map.entrySet()) { - if (entry.getValue() != null) { - var key = entry.getKey(); - var stringValues = new LinkedList<String>(); - for (var value : entry.getValue()) { - if (value != null) { - if (value instanceof Tensor) { - byte[] tensor = TypedBinaryFormat.encode((Tensor) value); - tensorInserter.add(TensorProperty.newBuilder().setName(key).setValue(ByteString.copyFrom(tensor))); - } else { - stringValues.add(value.toString()); - } - } - } - if (!stringValues.isEmpty()) { - stringInserter.add(StringProperty.newBuilder().setName(key).addAllValues(stringValues)); - } - } - } - } -} diff --git a/searchlib/src/main/java/com/yahoo/searchlib/protobuf/package-info.java b/searchlib/src/main/java/com/yahoo/searchlib/protobuf/package-info.java deleted file mode 100644 index bb7aeca35b9..00000000000 --- a/searchlib/src/main/java/com/yahoo/searchlib/protobuf/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -@ExportPackage -package com.yahoo.searchlib.protobuf; - -import com.yahoo.osgi.annotation.ExportPackage; |