diff options
author | Jon Bratseth <bratseth@oath.com> | 2019-01-28 09:39:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-28 09:39:31 +0100 |
commit | fd3df489a188490774ab5550f23f74e007af1b57 (patch) | |
tree | d8a8eea392dfe29ca8646f16c887ab5efdaa60dd | |
parent | 4fba0da4b970af2c31ed543c378e9641dd1b6106 (diff) | |
parent | f91b6093c9b018a49a36f4d34ac0b2acbe1b31d8 (diff) |
Merge pull request #8250 from vespa-engine/bratseth/rendering-cleanup-1
Remove dead code
4 files changed, 15 insertions, 214 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/JSONField.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/JSONField.java deleted file mode 100644 index bf9cc02b766..00000000000 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/JSONField.java +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.fastsearch; - -import java.nio.ByteBuffer; - -import com.yahoo.io.SlowInflate; -import com.yahoo.prelude.hitfield.JSONString; -import com.yahoo.text.Utf8; -import com.yahoo.data.access.*; -import com.yahoo.data.access.simple.Value; - -/** - * A hit field containing JSON structured data - * - * @author Steinar Knutsen - */ -public class JSONField extends DocsumField { - - public JSONField(String name) { - super(name); - } - - @Override - public String toString() { - return "field " + getName() + " type JSONString"; - } - - private static class CompatibilityConverter { - Value.ArrayValue target = new Value.ArrayValue(); - - Inspector stringify(Inspector value) { - if (value.type() == Type.STRING) return value; - if (value.type() == Type.LONG) { - String str = String.valueOf(value.asLong()); - return new Value.StringValue(str); - } - if (value.type() == Type.DOUBLE) { - String str = String.valueOf(value.asDouble()); - return new Value.StringValue(str); - } - String str = value.toString(); - return new Value.StringValue(str); - } - } - - private static class ArrConv extends CompatibilityConverter implements ArrayTraverser { - @Override - public void entry(int idx, Inspector value) { - target.add(stringify(value)); - } - } - - private static class WsConv1 extends CompatibilityConverter - implements ArrayTraverser - { - @Override - public void entry(int idx, Inspector value) { - Value.ArrayValue obj = new Value.ArrayValue(); - obj.add(stringify(value.entry(0))); - obj.add(value.entry(1)); - target.add(obj); - } - } - - private static class WsConv2 extends CompatibilityConverter - implements ArrayTraverser - { - @Override - public void entry(int idx, Inspector value) { - Value.ArrayValue obj = new Value.ArrayValue(); - obj.add(stringify(value.field("item"))); - obj.add(value.field("weight")); - target.add(obj); - } - } - - static Inspector convertTop(Inspector value) { - if (value.type() == Type.ARRAY && value.entryCount() > 0) { - Inspector first = value.entry(0); - if (first.type() == Type.ARRAY && first.entryCount() == 2) { - // old style weighted set - WsConv1 conv = new WsConv1(); - value.traverse(conv); - return conv.target; - } - if (first.type() == Type.OBJECT && - first.fieldCount() == 2 && - first.field("item").valid() && - first.field("weight").valid()) - { - // new style weighted set - WsConv2 conv = new WsConv2(); - value.traverse(conv); - return conv.target; - } - if (first.type() == Type.LONG) { - ArrConv conv = new ArrConv(); - value.traverse(conv); - return conv.target; - } - if (first.type() == Type.DOUBLE) { - ArrConv conv = new ArrConv(); - value.traverse(conv); - return conv.target; - } - } - return value; - } - - @Override - public Object convert(Inspector value) { - if (value.valid()) { - return new JSONString(convertTop(value)); - } else { - return new JSONString(""); - } - } - -} diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/StructDataField.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/StructDataField.java index 18986667a6c..8d8be0d3df0 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/StructDataField.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/StructDataField.java @@ -9,7 +9,7 @@ import com.yahoo.prelude.hitfield.JSONString; /** * A hit field containing JSON structured data */ -public class StructDataField extends JSONField { +public class StructDataField extends DocsumField { public StructDataField(String name) { super(name); @@ -22,10 +22,17 @@ public class StructDataField extends JSONField { @Override public Object convert(Inspector value) { - if (value.type() == Type.STRING) { - return super.convert(value); - } + if (value.type() == Type.STRING) + return convertString(value); return new StructuredData(value); } + private Object convertString(Inspector value) { + if (value.valid()) { + return new JSONString(value); + } else { + return new JSONString(""); + } + } + } diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/JsonFieldTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/JsonFieldTestCase.java deleted file mode 100644 index 01d658e9c88..00000000000 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/JsonFieldTestCase.java +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.prelude.fastsearch; - -import static org.junit.Assert.*; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.yahoo.data.access.*; -import com.yahoo.data.access.simple.*; - -public class JsonFieldTestCase { - - @Test - public final void requireThatWeightedSetsItemsAreConvertedToStrings() { - Value.ArrayValue topArr = new Value.ArrayValue(); - topArr.add(new Value.ArrayValue() - .add(new Value.DoubleValue(17.5)) - .add(new Value.LongValue(10))); - topArr.add(new Value.ArrayValue() - .add(new Value.DoubleValue(0.25)) - .add(new Value.DoubleValue(20))); - - Inspector c = JSONField.convertTop(topArr); - - assertEquals(Type.STRING, c.entry(0).entry(0).type()); - assertEquals(Type.LONG, c.entry(0).entry(1).type()); - assertEquals(Type.STRING, c.entry(1).entry(0).type()); - assertEquals(Type.DOUBLE, c.entry(1).entry(1).type()); - - assertEquals("17.5", c.entry(0).entry(0).asString()); - assertEquals(10, c.entry(0).entry(1).asLong()); - assertEquals("0.25", c.entry(1).entry(0).asString()); - assertEquals(20.0, c.entry(1).entry(1).asDouble(), 0.01); - } - - @Test - public final void requireThatNewWeightedSetsAreConvertedToOldFormat() { - Value.ArrayValue topArr = new Value.ArrayValue(); - topArr.add(new Value.ObjectValue() - .put("item", new Value.DoubleValue(17.5)) - .put("weight", new Value.LongValue(10))); - topArr.add(new Value.ObjectValue() - .put("item", new Value.DoubleValue(0.25)) - .put("weight", new Value.DoubleValue(20))); - topArr.add(new Value.ObjectValue() - .put("item", new Value.StringValue("foob")) - .put("weight", new Value.DoubleValue(30))); - - Inspector c = JSONField.convertTop(topArr); - - assertEquals(Type.STRING, c.entry(0).entry(0).type()); - assertEquals(Type.LONG, c.entry(0).entry(1).type()); - assertEquals(Type.STRING, c.entry(1).entry(0).type()); - assertEquals(Type.DOUBLE, c.entry(1).entry(1).type()); - assertEquals(Type.STRING, c.entry(2).entry(0).type()); - assertEquals(Type.DOUBLE, c.entry(2).entry(1).type()); - - assertEquals("17.5", c.entry(0).entry(0).asString()); - assertEquals(10, c.entry(0).entry(1).asLong()); - assertEquals("0.25", c.entry(1).entry(0).asString()); - assertEquals(20.0, c.entry(1).entry(1).asDouble(), 0.01); - assertEquals("foob", c.entry(2).entry(0).asString()); - assertEquals(30.0, c.entry(2).entry(1).asDouble(), 0.01); - } - - @Test - public final void requireThatArrayValuesAreConvertedToStrings() { - Value.ArrayValue topArr = new Value.ArrayValue(); - topArr.add(new Value.DoubleValue(17.5)); - topArr.add(new Value.DoubleValue(0.25)); - topArr.add(new Value.LongValue(10)); - topArr.add(new Value.DoubleValue(20)); - - Inspector c = JSONField.convertTop(topArr); - - assertEquals(Type.STRING, c.entry(0).type()); - assertEquals(Type.STRING, c.entry(1).type()); - assertEquals(Type.STRING, c.entry(2).type()); - assertEquals(Type.STRING, c.entry(3).type()); - - assertEquals("17.5", c.entry(0).asString()); - assertEquals("0.25", c.entry(1).asString()); - assertEquals("10", c.entry(2).asString()); - assertEquals("20.0", c.entry(3).asString()); - } - -} diff --git a/vespajlib/src/main/java/com/yahoo/data/access/Inspectable.java b/vespajlib/src/main/java/com/yahoo/data/access/Inspectable.java index f982d887f44..69151048e78 100644 --- a/vespajlib/src/main/java/com/yahoo/data/access/Inspectable.java +++ b/vespajlib/src/main/java/com/yahoo/data/access/Inspectable.java @@ -7,6 +7,8 @@ package com.yahoo.data.access; * impractical to implement the Inspector interface directly. **/ public interface Inspectable { - /** get an Inspector exposing this object's structured data. */ - public Inspector inspect(); + + /** Returns an Inspector exposing this object's structured data. */ + Inspector inspect(); + } |