summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-11-16 10:58:26 +0100
committerHenning Baldersheim <balder@yahoo-inc.com>2016-11-16 10:58:26 +0100
commit2bcaf96baa296ad84881c79f537b1acb3805b160 (patch)
treeda069c3f1cfda45d6aaa3c6b1952b75b155cff26
parent0cda61be099cc167ca3b896ce201e5e21fd6e152 (diff)
Preserve old behavior where doing a setFieldValue on a string field,
would make an empty spanTreeMap when there where no annotations. However this is different that using the generated setter, which will not touch any annotations. But that is the same issue as always.
-rw-r--r--document/src/main/java/com/yahoo/document/ExtendedStringField.java13
-rw-r--r--documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java7
-rw-r--r--vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java13
3 files changed, 18 insertions, 15 deletions
diff --git a/document/src/main/java/com/yahoo/document/ExtendedStringField.java b/document/src/main/java/com/yahoo/document/ExtendedStringField.java
index 4fb052b9b56..1e84b374372 100644
--- a/document/src/main/java/com/yahoo/document/ExtendedStringField.java
+++ b/document/src/main/java/com/yahoo/document/ExtendedStringField.java
@@ -5,6 +5,8 @@ import com.yahoo.document.annotation.SpanTree;
import com.yahoo.document.datatypes.FieldValue;
import com.yahoo.document.datatypes.StringFieldValue;
import com.yahoo.document.datatypes.StructuredFieldValue;
+
+import java.util.HashMap;
import java.util.Map;
/**
@@ -13,7 +15,7 @@ import java.util.Map;
* @author baldersheim
*/
public class ExtendedStringField extends ExtendedField {
- public static interface ExtractSpanTrees {
+ public interface ExtractSpanTrees {
Map<String, SpanTree> get(StructuredFieldValue doc);
void set(StructuredFieldValue doc, Map<String, SpanTree> trees);
}
@@ -40,7 +42,14 @@ public class ExtendedStringField extends ExtendedField {
FieldValue old = getFieldValue(doc);
StringFieldValue sfv = (StringFieldValue) fv;
super.setFieldValue(doc, sfv);
- extractSpanTrees.set(doc, (sfv == null) ? null : sfv.getSpanTreeMap());
+ Map<String, SpanTree> trees = null;
+ if (sfv != null) {
+ trees = sfv.getSpanTreeMap();
+ if (trees == null) {
+ trees = new HashMap<>();
+ }
+ }
+ extractSpanTrees.set(doc, trees);
return old;
}
diff --git a/documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java b/documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java
index 1f918fb69aa..59e10bbce00 100644
--- a/documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java
+++ b/documentgen-test/src/test/java/com/yahoo/vespa/config/DocumentGenPluginTest.java
@@ -129,6 +129,13 @@ public class DocumentGenPluginTest {
}
@Test
+ public void testSetString() {
+ Book book = new Book(new DocumentId("doc:book:0"));
+ book.setFieldValue("author", "Herman Melville");
+ assertNotEquals(null, book.authorSpanTrees());
+ }
+
+ @Test
public void testremoveFieldValue() {
Book book = getBook();
book.setAuthor(null);
diff --git a/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java b/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java
index 8434f9b635a..a1ba05eacb3 100644
--- a/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java
+++ b/vespa-documentgen-plugin/src/main/java/com/yahoo/vespa/DocumentGenMojo.java
@@ -578,7 +578,6 @@ public class DocumentGenMojo extends AbstractMojo {
exportGetFieldCount(fieldSet, out, ind);
exportGetField(out, ind);
exportGetFieldValue(fieldSet, out, ind);
- exportToNamedMap(out, ind);
exportSetFieldValue(fieldSet, out, ind);
exportRemoveFieldValue(fieldSet, out, ind);
exportIterator(fieldSet, out, ind);
@@ -598,18 +597,6 @@ public class DocumentGenMojo extends AbstractMojo {
out.write(ind(ind)+"}\n\n");
}
- private static void exportToNamedMap(Writer out, int ind) throws IOException {
- // A helper to convert from SpanTree collection to Map. Can be removed if StringFieldValue is fixed to expose the map.
- out.write(
- ind()+"private static java.util.Map<java.lang.String,com.yahoo.document.annotation.SpanTree> toNamedMap(java.util.Collection<com.yahoo.document.annotation.SpanTree> coll) {\n" +
- ind(ind+1)+"if (coll==null) return null;\n" +
- ind(ind+1)+"java.util.Map<java.lang.String,com.yahoo.document.annotation.SpanTree> ret = new java.util.HashMap<java.lang.String,com.yahoo.document.annotation.SpanTree>();\n" +
- ind(ind+1)+"for (com.yahoo.document.annotation.SpanTree st : coll) ret.put(st.getName(), st);\n" +
- ind(ind+1)+"return ret;\n" +
- ind()+"}\n\n"
- );
- }
-
private static void exportHashCode(Collection<Field> fieldSet, Writer out, int ind, String hcBase) throws IOException {
out.write(ind(ind)+"@Override public int hashCode() {\n");
out.write(ind(ind+1)+"int hc = "+hcBase+";\n");