diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-09-13 10:51:55 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2018-09-13 10:51:55 +0200 |
commit | e6c49f90583b8e13bf900be110d4aa4cb99a26cf (patch) | |
tree | 79bf053442cae3b032178db3c9c07cad11ef2eef /document | |
parent | fb0aa3e2df91dec55dcdcee6dfcfabf88fdedf5d (diff) |
Add deprecation comments and some renaming.
Diffstat (limited to 'document')
6 files changed, 60 insertions, 35 deletions
diff --git a/document/src/main/java/com/yahoo/document/DocumentUpdate.java b/document/src/main/java/com/yahoo/document/DocumentUpdate.java index 4f8e3ef3b82..bbd5cfe75fe 100644 --- a/document/src/main/java/com/yahoo/document/DocumentUpdate.java +++ b/document/src/main/java/com/yahoo/document/DocumentUpdate.java @@ -40,6 +40,8 @@ import java.util.Optional; * @see com.yahoo.document.update.FieldUpdate * @see com.yahoo.document.update.ValueUpdate */ +//TODO Vespa 7 Remove all deprecated methods + public class DocumentUpdate extends DocumentOperation implements Iterable<FieldPathUpdate> { //see src/vespa/document/util/identifiableid.h @@ -169,6 +171,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * Get an unmodifiable list of all field updates that this document update specifies. * * @return a list of all FieldUpdates in this DocumentUpdate + * @deprecated Use fieldUpdates() instead. */ @Deprecated public List<FieldUpdate> getFieldUpdates() { @@ -178,9 +181,9 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP /** * Get an unmodifiable collection of all field updates that this document update specifies. * - * @return a list of all FieldUpdates in this DocumentUpdate + * @return a collection of all FieldUpdates in this DocumentUpdate */ - public Collection<FieldUpdate> getFieldUpdatesCollection() { + public Collection<FieldUpdate> fieldUpdates() { return Collections.unmodifiableCollection(id2FieldUpdateMap.values()); } @@ -188,11 +191,22 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * Get an unmodifiable list of all field path updates this document update specifies. * * @return Returns a list of all field path updates in this document update. + * @deprecated Use fieldPathUpdates() instead. */ + @Deprecated public List<FieldPathUpdate> getFieldPathUpdates() { return Collections.unmodifiableList(fieldPathUpdates); } + /** + * Get an unmodifiable collection of all field path updates that this document update specifies. + * + * @return a collection of all FieldPathUpdates in this DocumentUpdate + */ + public Collection<FieldPathUpdate> fieldPathUpdates() { + return Collections.unmodifiableCollection(fieldPathUpdates); + } + /** Returns the type of the document this updates * * @return The documentype of the document @@ -215,6 +229,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * @param index the index of the FieldUpdate to return * @return the FieldUpdate at the specified index * @throws IndexOutOfBoundsException if index is out of range + * @deprecated use getFieldUpdate(Field field) instead. */ @Deprecated public FieldUpdate getFieldUpdate(int index) { @@ -228,6 +243,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * @param upd the FieldUpdate to be stored at the specified position * @return the FieldUpdate previously at the specified position * @throws IndexOutOfBoundsException if index is out of range + * @deprecated Use removeFieldUpdate/addFieldUpdate instead */ @Deprecated public FieldUpdate setFieldUpdate(int index, FieldUpdate upd) { @@ -274,11 +290,14 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * * @param fieldUpdates the new list of updates of this * @throws NullPointerException if the argument passed is null + * @deprecated Iterate and use addFieldUpdate instead */ + @Deprecated public void setFieldUpdates(Collection<FieldUpdate> fieldUpdates) { if (fieldUpdates == null) { throw new NullPointerException("The field updates of a document update can not be null"); } + fieldUpdates.clear(); for (FieldUpdate fieldUpdate : fieldUpdates) { addFieldUpdate(fieldUpdate); } @@ -347,7 +366,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP if (!documentType.equals(update.documentType)) { throw new IllegalArgumentException("Expected " + documentType + ", got " + update.documentType + "."); } - for (FieldUpdate fieldUpd : update.id2FieldUpdateMap.values()) { + for (FieldUpdate fieldUpd : update.fieldUpdates()) { addFieldUpdate(fieldUpd); } for (FieldPathUpdate pathUpd : update.fieldPathUpdates) { @@ -361,6 +380,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * @param index the index of the FieldUpdate to remove * @return the FieldUpdate previously at the specified position * @throws IndexOutOfBoundsException if index is out of range + * @deprecated use removeFieldUpdate(Field field) instead. */ @Deprecated public FieldUpdate removeFieldUpdate(int index) { diff --git a/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java b/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java index 5b1dda0f71c..6adae27cadc 100644 --- a/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java +++ b/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java @@ -47,6 +47,7 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.regex.Matcher; @@ -105,11 +106,11 @@ public class DocumentUpdateJsonSerializer } generator.writeObjectFieldStart("fields"); - for (FieldUpdate up : update.getFieldUpdatesCollection()) { + for (FieldUpdate up : update.fieldUpdates()) { up.serialize(this); } - update.getFieldPathUpdates().stream() + update.fieldPathUpdates().stream() .collect(Collectors.groupingBy(FieldPathUpdate::getFieldPath)) .forEach((fieldPath, fieldPathUpdates) -> wrapIOException(() -> write(fieldPath, fieldPathUpdates, generator))); @@ -120,7 +121,7 @@ public class DocumentUpdateJsonSerializer }); } - private void write(FieldPath fieldPath, List<FieldPathUpdate> fieldPathUpdates, JsonGenerator generator) throws IOException { + private void write(FieldPath fieldPath, Collection<FieldPathUpdate> fieldPathUpdates, JsonGenerator generator) throws IOException { generator.writeObjectFieldStart(fieldPath.toString()); for (FieldPathUpdate update : fieldPathUpdates) { diff --git a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java index b04fece0ef4..cf8161c4306 100644 --- a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java @@ -3,7 +3,6 @@ package com.yahoo.document; import com.yahoo.document.datatypes.*; import com.yahoo.document.fieldpathupdate.FieldPathUpdate; -import com.yahoo.document.select.parser.ParseException; import com.yahoo.document.serialization.*; import com.yahoo.document.update.AssignValueUpdate; import com.yahoo.document.update.FieldUpdate; @@ -259,7 +258,7 @@ public class DocumentUpdateTestCase { update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(1))); update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(2))); - assertEquals(1, update.getFieldUpdatesCollection().size()); + assertEquals(1, update.fieldUpdates().size()); FieldUpdate fieldUpdate = update.getFieldUpdate(field); assertNotNull(fieldUpdate); assertEquals(field, fieldUpdate.getField()); @@ -418,7 +417,7 @@ public class DocumentUpdateTestCase { barUpdate.addFieldUpdate(barField); fooUpdate.addAll(barUpdate); - assertEquals(1, fooUpdate.getFieldUpdatesCollection().size()); + assertEquals(1, fooUpdate.fieldUpdates().size()); FieldUpdate fieldUpdate = fooUpdate.getFieldUpdate(field); assertNotNull(fieldUpdate); assertEquals(field, fieldUpdate.getField()); @@ -463,6 +462,7 @@ public class DocumentUpdateTestCase { } @Test + @SuppressWarnings("deprecation") public void testFieldUpdatesInDocUp() { DocumentType t1 = new DocumentType("doo"); Field f1 = new Field("field1", DataType.STRING); diff --git a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java index b1f114bfbc5..32f63e6c0b3 100644 --- a/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java +++ b/document/src/test/java/com/yahoo/document/json/JsonReaderTestCase.java @@ -292,8 +292,8 @@ public class JsonReaderTestCase { + "\"skuggsjaa\": {" + "\"assign\": { \"sandra\": \"person\"," + " \"cloud\": \"another person\"}}}}"); - assertEquals(1, put.getFieldUpdatesCollection().size()); - FieldUpdate fu = put.getFieldUpdatesCollection().iterator().next(); + assertEquals(1, put.fieldUpdates().size()); + FieldUpdate fu = put.fieldUpdates().iterator().next(); assertEquals(1, fu.getValueUpdates().size()); ValueUpdate vu = fu.getValueUpdate(0); assertTrue(vu instanceof AssignValueUpdate); @@ -315,8 +315,8 @@ public class JsonReaderTestCase { + " \"fields\": { " + "\"skuggsjaa\": {" + "\"assign\": { }}}}"); - assertEquals(1, put.getFieldUpdatesCollection().size()); - FieldUpdate fu = put.getFieldUpdatesCollection().iterator().next(); + assertEquals(1, put.fieldUpdates().size()); + FieldUpdate fu = put.fieldUpdates().iterator().next(); assertEquals(1, fu.getValueUpdates().size()); ValueUpdate vu = fu.getValueUpdate(0); assertTrue(vu instanceof AssignValueUpdate); diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java index 7b855818721..dcdea0975ad 100644 --- a/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java +++ b/document/src/test/java/com/yahoo/vespaxmlparser/UriParserTestCase.java @@ -46,8 +46,8 @@ public class UriParserTestCase { DocumentUpdate upd = nextUpdate(it); assertNotNull(upd); - assertEquals(1, upd.getFieldUpdatesCollection().size()); - FieldUpdate fieldUpd = upd.getFieldUpdatesCollection().iterator().next(); + assertEquals(1, upd.fieldUpdates().size()); + FieldUpdate fieldUpd = upd.fieldUpdates().iterator().next(); assertNotNull(fieldUpd); assertEquals(docType.getField("my_arr"), fieldUpd.getField()); assertEquals(1, fieldUpd.getValueUpdates().size()); diff --git a/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java b/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java index 4c64f7c35cb..1aad59f4c56 100755 --- a/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java +++ b/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java @@ -5,6 +5,7 @@ import com.yahoo.document.*; import com.yahoo.document.datatypes.*; import com.yahoo.document.fieldpathupdate.AddFieldPathUpdate; import com.yahoo.document.fieldpathupdate.AssignFieldPathUpdate; +import com.yahoo.document.fieldpathupdate.FieldPathUpdate; import com.yahoo.document.fieldpathupdate.RemoveFieldPathUpdate; import com.yahoo.document.serialization.DeserializationException; import com.yahoo.document.update.AddValueUpdate; @@ -16,6 +17,7 @@ import org.junit.Before; import org.junit.Test; import java.io.ByteArrayInputStream; +import java.util.Iterator; import java.util.List; import static org.junit.Assert.*; @@ -687,103 +689,105 @@ public class VespaXMLReaderTestCase { DocumentUpdate docUpdate = op.getDocumentUpdate(); - assertEquals(20, docUpdate.getFieldPathUpdates().size()); + assertEquals(20, docUpdate.fieldPathUpdates().size()); + Iterator<FieldPathUpdate> updates = docUpdate.fieldPathUpdates().iterator(); { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(0); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("url", ass.getOriginalFieldPath()); assertEquals(new StringFieldValue("assignUrl"), ass.getNewValue()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(1); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("title", ass.getOriginalFieldPath()); assertEquals(new StringFieldValue("assignTitle"), ass.getNewValue()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(2); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("last_downloaded", ass.getOriginalFieldPath()); assertEquals("1", ass.getExpression()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(3); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("value_long", ass.getOriginalFieldPath()); assertEquals("2", ass.getExpression()); } + updates.next(); // Skip number 5 { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(5); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("stringarr", ass.getOriginalFieldPath()); assertEquals("[assignString1, assignString2]", ass.getNewValue().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(6); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("intarr", ass.getOriginalFieldPath()); assertEquals("[3, 4]", ass.getNewValue().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(7); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("longarr", ass.getOriginalFieldPath()); assertEquals("[5, 6]", ass.getNewValue().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(8); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("bytearr", ass.getOriginalFieldPath()); assertEquals("[7, 8]", ass.getNewValue().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(9); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("floatarr", ass.getOriginalFieldPath()); assertEquals("[9.0, 10.0]", ass.getNewValue().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(10); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("weightedsetint", ass.getOriginalFieldPath()); WeightedSet set = (WeightedSet)ass.getNewValue(); assertEquals(Integer.valueOf(11), set.get(new IntegerFieldValue(11))); assertEquals(Integer.valueOf(12), set.get(new IntegerFieldValue(12))); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(11); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("weightedsetstring", ass.getOriginalFieldPath()); WeightedSet set = (WeightedSet)ass.getNewValue(); assertEquals(Integer.valueOf(13), set.get(new StringFieldValue("assign13"))); assertEquals(Integer.valueOf(14), set.get(new StringFieldValue("assign14"))); } { - AddFieldPathUpdate ass = (AddFieldPathUpdate)docUpdate.getFieldPathUpdates().get(12); + AddFieldPathUpdate ass = (AddFieldPathUpdate)updates.next(); assertEquals("stringarr", ass.getOriginalFieldPath()); assertEquals("[addString1, addString2]", ass.getNewValues().toString()); } { - AddFieldPathUpdate ass = (AddFieldPathUpdate)docUpdate.getFieldPathUpdates().get(13); + AddFieldPathUpdate ass = (AddFieldPathUpdate)updates.next(); assertEquals("longarr", ass.getOriginalFieldPath()); assertEquals("[5]", ass.getNewValues().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(14); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("weightedsetint{13}", ass.getOriginalFieldPath()); assertEquals("13", ass.getExpression()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(15); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("weightedsetint{14}", ass.getOriginalFieldPath()); assertEquals("14", ass.getExpression()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(16); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("weightedsetstring{add13}", ass.getOriginalFieldPath()); assertEquals("1", ass.getExpression()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(17); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); assertEquals("weightedsetstring{assign13}", ass.getOriginalFieldPath()); assertEquals("130", ass.getExpression()); } { - RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)docUpdate.getFieldPathUpdates().get(18); + RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)updates.next(); assertEquals("weightedsetstring{assign14}", ass.getOriginalFieldPath()); } { - RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)docUpdate.getFieldPathUpdates().get(19); + RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)updates.next(); assertEquals("bytearr", ass.getOriginalFieldPath()); } Document doc = new Document(manager.getDocumentType("news"), new DocumentId("doc:test:test:test")); |