diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-09-13 16:02:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-13 16:02:46 +0200 |
commit | 76f4a719f366a8f804d3748f275b31f2842b3479 (patch) | |
tree | 2ac7f89448abd447814c3968fc7e5f195c79af18 /document | |
parent | 83dac5e4dec3d85084ce3839a74188e9c03d7784 (diff) | |
parent | a66fda29f0e0a10ada10c0857b82f2c1f65f9e4d (diff) |
Merge pull request #6902 from vespa-engine/balder/hashmap-backed-documentupdate
Do not expose fieldupdates as a list. Hide implementation details ins…
Diffstat (limited to 'document')
8 files changed, 148 insertions, 89 deletions
diff --git a/document/src/main/java/com/yahoo/document/DocumentUpdate.java b/document/src/main/java/com/yahoo/document/DocumentUpdate.java index ad93942c1c0..8a743e58490 100644 --- a/document/src/main/java/com/yahoo/document/DocumentUpdate.java +++ b/document/src/main/java/com/yahoo/document/DocumentUpdate.java @@ -13,9 +13,12 @@ import com.yahoo.document.update.ValueUpdate; import com.yahoo.io.GrowableByteBuffer; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Optional; /** @@ -37,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 @@ -44,6 +49,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP private DocumentId docId; private List<FieldUpdate> fieldUpdates; + private final Map<Integer, FieldUpdate> id2FieldUpdateMap; private List<FieldPathUpdate> fieldPathUpdates; private DocumentType documentType; private Optional<Boolean> createIfNonExistent = Optional.empty(); @@ -55,7 +61,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * @param docType the document type that this update is valid for */ public DocumentUpdate(DocumentType docType, DocumentId docId) { - this(docType, docId, new ArrayList<FieldUpdate>()); + this(docType, docId, new HashMap<>()); } /** @@ -65,6 +71,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP docId = null; documentType = null; fieldUpdates = new ArrayList<>(); + id2FieldUpdateMap = new HashMap<>(); fieldPathUpdates = new ArrayList<>(); reader.read(this); } @@ -79,10 +86,11 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP this(docType, new DocumentId(docId)); } - private DocumentUpdate(DocumentType docType, DocumentId docId, List<FieldUpdate> fieldUpdates) { + private DocumentUpdate(DocumentType docType, DocumentId docId, Map<Integer, FieldUpdate> id2fieldUpdateMap) { this.docId = docId; this.documentType = docType; - this.fieldUpdates = fieldUpdates; + this.fieldUpdates = new ArrayList<>(id2fieldUpdateMap.values()); + id2FieldUpdateMap = id2fieldUpdateMap; this.fieldPathUpdates = new ArrayList<>(); } @@ -114,7 +122,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP public DocumentUpdate applyTo(Document doc) { verifyType(doc); - for (FieldUpdate fieldUpdate : fieldUpdates) { + for (FieldUpdate fieldUpdate : id2FieldUpdateMap.values()) { fieldUpdate.applyTo(doc); } for (FieldPathUpdate fieldPathUpdate : fieldPathUpdates) { @@ -132,8 +140,9 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP public DocumentUpdate prune(Document doc) { verifyType(doc); - for (Iterator<FieldUpdate> iter = fieldUpdates.iterator(); iter.hasNext();) { - FieldUpdate update = iter.next(); + for (Iterator<Map.Entry<Integer, FieldUpdate>> iter = id2FieldUpdateMap.entrySet().iterator(); iter.hasNext();) { + Map.Entry<Integer, FieldUpdate> entry = iter.next(); + FieldUpdate update = entry.getValue(); if (!update.isEmpty()) { ValueUpdate last = update.getValueUpdate(update.size() - 1); if (last instanceof AssignValueUpdate) { @@ -162,20 +171,42 @@ 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() { return Collections.unmodifiableList(fieldUpdates); } /** + * Get an unmodifiable collection of all field updates that this document update specifies. + * + * @return a collection of all FieldUpdates in this DocumentUpdate + */ + public Collection<FieldUpdate> fieldUpdates() { + return Collections.unmodifiableCollection(id2FieldUpdateMap.values()); + } + + /** * 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 @@ -198,7 +229,9 @@ 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) { return fieldUpdates.get(index); } @@ -210,9 +243,20 @@ 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) { - return fieldUpdates.set(index, upd); + FieldUpdate old = fieldUpdates.get(index); + if (old.getField().equals(upd.getField())) { + fieldUpdates.set(index, upd); + id2FieldUpdateMap.put(upd.getField().getId(), upd); + } else { + throw new IllegalArgumentException("You can not replace a FieldUpdate for field '" + old.getField() + + "' with an update for field '" + upd.getField() + "'"); + } + + return old; } /** @@ -222,12 +266,13 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * @return the update for the field, or null if that field has no update in this */ public FieldUpdate getFieldUpdate(Field field) { - return getFieldUpdate(field.getName()); + return getFieldUpdateById(field.getId()); } /** Removes all field updates from the list for field updates. */ public void clearFieldUpdates() { fieldUpdates.clear(); + id2FieldUpdateMap.clear(); } /** @@ -237,27 +282,34 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * @return the update for the field, or null if that field has no update in this */ public FieldUpdate getFieldUpdate(String fieldName) { - for (FieldUpdate fieldUpdate : fieldUpdates) { - if (fieldUpdate.getField().getName().equals(fieldName)) { + for (FieldUpdate fieldUpdate : id2FieldUpdateMap.values()) { + if (fieldUpdate.getField().getName().equals(fieldName)) return fieldUpdate; - } } return null; } + private FieldUpdate getFieldUpdateById(Integer fieldId) { + return id2FieldUpdateMap.get(fieldId); + } /** * Assigns the field updates of this document update. * This document update receives ownership of the list - it can not be subsequently used - * by the caller. The list may not be unmodifiable. + * by the caller. * * @param fieldUpdates the new list of updates of this * @throws NullPointerException if the argument passed is null + * @deprecated Iterate and use addFieldUpdate instead */ - public void setFieldUpdates(List<FieldUpdate> fieldUpdates) { + @Deprecated + public void setFieldUpdates(Collection<FieldUpdate> fieldUpdates) { if (fieldUpdates == null) { throw new NullPointerException("The field updates of a document update can not be null"); } - this.fieldUpdates = fieldUpdates; + fieldUpdates.clear(); + for (FieldUpdate fieldUpdate : fieldUpdates) { + addFieldUpdate(fieldUpdate); + } } /** @@ -266,7 +318,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * @return the size of the List of FieldUpdates */ public int size() { - return fieldUpdates.size(); + return id2FieldUpdateMap.size(); } /** @@ -279,17 +331,17 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * field. */ public DocumentUpdate addFieldUpdate(FieldUpdate update) { - String fieldName = update.getField().getName(); - if (!documentType.hasField(fieldName)) { - throw new IllegalArgumentException("Document type '" + documentType.getName() + "' does not have field '" + - fieldName + "'."); + Integer fieldId = update.getField().getId(); + if (documentType.getField(fieldId) == null) { + throw new IllegalArgumentException("Document type '" + documentType.getName() + "' does not have field '" + update.getField().getName() + "'."); } - FieldUpdate prevUpdate = getFieldUpdate(fieldName); + FieldUpdate prevUpdate = getFieldUpdateById(fieldId); if (prevUpdate != update) { if (prevUpdate != null) { prevUpdate.addAll(update); } else { fieldUpdates.add(update); + id2FieldUpdateMap.put(fieldId, update); } } return this; @@ -305,12 +357,6 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP return this; } - // TODO: Remove this when we figure out correct behaviour. - - public void addFieldUpdateNoCheck(FieldUpdate fieldUpdate) { - fieldUpdates.add(fieldUpdate); - } - /** * Adds all the field- and field path updates of the given document update to this. If the given update refers to a * different document or document type than this, this method throws an exception. @@ -329,7 +375,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.fieldUpdates) { + for (FieldUpdate fieldUpd : update.fieldUpdates()) { addFieldUpdate(fieldUpd); } for (FieldPathUpdate pathUpd : update.fieldPathUpdates) { @@ -343,9 +389,17 @@ 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) { - return fieldUpdates.remove(index); + FieldUpdate prev = getFieldUpdate(index); + fieldUpdates.remove(index); + return removeFieldUpdate(prev.getField()); + } + + public FieldUpdate removeFieldUpdate(Field field) { + return id2FieldUpdateMap.remove(field.getId()); } /** @@ -385,7 +439,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP @Override public int hashCode() { int result = docId != null ? docId.hashCode() : 0; - result = 31 * result + (fieldUpdates != null ? fieldUpdates.hashCode() : 0); + result = 31 * result + (id2FieldUpdateMap != null ? id2FieldUpdateMap.hashCode() : 0); result = 31 * result + (fieldPathUpdates != null ? fieldPathUpdates.hashCode() : 0); result = 31 * result + (documentType != null ? documentType.hashCode() : 0); return result; @@ -402,7 +456,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP string.append(": "); string.append("["); - for (Iterator<FieldUpdate> i = fieldUpdates.iterator(); i.hasNext();) { + for (Iterator<FieldUpdate> i = id2FieldUpdateMap.values().iterator(); i.hasNext();) { FieldUpdate fieldUpdate = i.next(); string.append(fieldUpdate); if (i.hasNext()) { @@ -432,7 +486,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * @return True if this update is empty. */ public boolean isEmpty() { - return fieldUpdates.isEmpty() && fieldPathUpdates.isEmpty(); + return id2FieldUpdateMap.isEmpty() && fieldPathUpdates.isEmpty(); } /** 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 b9b273d691f..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.getFieldUpdates()) { + 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/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java index a048ea349eb..3f885844987 100644 --- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java +++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializer42.java @@ -472,7 +472,7 @@ public class VespaDocumentDeserializer42 extends VespaDocumentSerializer42 imple for (int i = 0; i < size; i++) { // TODO: Should use checked method, but doesn't work according to test now. - update.addFieldUpdateNoCheck(new FieldUpdate(this, update.getDocumentType(), serializationVersion)); + update.addFieldUpdate(new FieldUpdate(this, update.getDocumentType(), serializationVersion)); } } diff --git a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java index 7bdc6fd5355..4f8a26d3777 100644 --- a/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java +++ b/document/src/main/java/com/yahoo/document/serialization/VespaDocumentDeserializerHead.java @@ -29,7 +29,7 @@ public class VespaDocumentDeserializerHead extends VespaDocumentDeserializer42 { for (int i = 0; i < size; i++) { // TODO: Should use checked method, but doesn't work according to test now. - update.addFieldUpdateNoCheck(new FieldUpdate(this, update.getDocumentType(), 8)); + update.addFieldUpdate(new FieldUpdate(this, update.getDocumentType(), 8)); } int sizeAndFlags = getInt(null); diff --git a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java index 15319985591..243102c17df 100644 --- a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java @@ -1,10 +1,19 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document; -import com.yahoo.document.datatypes.*; +import com.yahoo.document.datatypes.Array; +import com.yahoo.document.datatypes.FloatFieldValue; +import com.yahoo.document.datatypes.IntegerFieldValue; +import com.yahoo.document.datatypes.StringFieldValue; +import com.yahoo.document.datatypes.TensorFieldValue; +import com.yahoo.document.datatypes.WeightedSet; import com.yahoo.document.fieldpathupdate.FieldPathUpdate; -import com.yahoo.document.select.parser.ParseException; -import com.yahoo.document.serialization.*; +import com.yahoo.document.serialization.DocumentDeserializer; +import com.yahoo.document.serialization.DocumentDeserializerFactory; +import com.yahoo.document.serialization.DocumentSerializer; +import com.yahoo.document.serialization.DocumentSerializerFactory; +import com.yahoo.document.serialization.DocumentUpdateFlags; +import com.yahoo.document.serialization.DocumentUpdateWriter; import com.yahoo.document.update.AssignValueUpdate; import com.yahoo.document.update.FieldUpdate; import com.yahoo.document.update.ValueUpdate; @@ -259,8 +268,8 @@ public class DocumentUpdateTestCase { update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(1))); update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(2))); - assertEquals(1, update.getFieldUpdates().size()); - FieldUpdate fieldUpdate = update.getFieldUpdate(0); + assertEquals(1, update.fieldUpdates().size()); + FieldUpdate fieldUpdate = update.getFieldUpdate(field); assertNotNull(fieldUpdate); assertEquals(field, fieldUpdate.getField()); assertEquals(2, fieldUpdate.getValueUpdates().size()); @@ -342,13 +351,16 @@ public class DocumentUpdateTestCase { assertEquals(new DocumentId("doc:update:test"), upd.getId()); assertEquals(type, upd.getType()); - FieldUpdate serAssignFU = upd.getFieldUpdate(0); + FieldUpdate serAssignFU = upd.getFieldUpdate(type.getField("intfield")); assertEquals(type.getField("intfield"), serAssignFU.getField()); ValueUpdate serAssign = serAssignFU.getValueUpdate(0); assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, serAssign.getValueUpdateClassID()); assertEquals(new IntegerFieldValue(4), serAssign.getValue()); - FieldUpdate serAddFU = upd.getFieldUpdate(2); + ValueUpdate serArith = serAssignFU.getValueUpdate(1); + assertEquals(ValueUpdate.ValueUpdateClassID.ARITHMETIC, serArith.getValueUpdateClassID()); + + FieldUpdate serAddFU = upd.getFieldUpdate(type.getField("arrayoffloatfield")); assertEquals(type.getField("arrayoffloatfield"), serAddFU.getField()); ValueUpdate serAdd1 = serAddFU.getValueUpdate(0); assertEquals(ValueUpdate.ValueUpdateClassID.ADD, serAdd1.getValueUpdateClassID()); @@ -363,12 +375,7 @@ public class DocumentUpdateTestCase { FloatFieldValue addparam3 = (FloatFieldValue)serAdd3.getValue(); assertEquals(new FloatFieldValue(-1.00f), addparam3); - FieldUpdate arithFU = upd.getFieldUpdate(3); - assertEquals(type.getField("intfield"), serAssignFU.getField()); - ValueUpdate serArith = arithFU.getValueUpdate(0); - assertEquals(ValueUpdate.ValueUpdateClassID.ARITHMETIC, serArith.getValueUpdateClassID()); - - FieldUpdate wsetFU = upd.getFieldUpdate(4); + FieldUpdate wsetFU = upd.getFieldUpdate(type.getField("wsfield")); assertEquals(type.getField("wsfield"), wsetFU.getField()); assertEquals(2, wsetFU.size()); ValueUpdate mapUpd = wsetFU.getValueUpdate(0); @@ -420,8 +427,8 @@ public class DocumentUpdateTestCase { barUpdate.addFieldUpdate(barField); fooUpdate.addAll(barUpdate); - assertEquals(1, fooUpdate.getFieldUpdates().size()); - FieldUpdate fieldUpdate = fooUpdate.getFieldUpdate(0); + assertEquals(1, fooUpdate.fieldUpdates().size()); + FieldUpdate fieldUpdate = fooUpdate.getFieldUpdate(field); assertNotNull(fieldUpdate); assertEquals(field, fieldUpdate.getField()); assertEquals(2, fieldUpdate.getValueUpdates().size()); @@ -465,6 +472,7 @@ public class DocumentUpdateTestCase { } @Test + @SuppressWarnings("deprecation") public void testFieldUpdatesInDocUp() { DocumentType t1 = new DocumentType("doo"); Field f1 = new Field("field1", DataType.STRING); @@ -493,14 +501,6 @@ public class DocumentUpdateTestCase { assertSame(fu1, documentUpdate.getFieldUpdate(f1)); - assertSame(fu1, documentUpdate.getFieldUpdate(0)); - assertSame(fu2, documentUpdate.getFieldUpdate(1)); - - documentUpdate.setFieldUpdate(0, fu2); - documentUpdate.setFieldUpdate(1, fu1); - assertEquals(2, documentUpdate.size()); - assertSame(fu1, documentUpdate.getFieldUpdate(1)); - assertSame(fu2, documentUpdate.getFieldUpdate(0)); try { documentUpdate.setFieldUpdates(null); @@ -515,12 +515,12 @@ public class DocumentUpdateTestCase { documentUpdate.setFieldUpdates(fus); assertEquals(2, documentUpdate.size()); - assertSame(fu1, documentUpdate.getFieldUpdate(0)); - assertSame(fu2, documentUpdate.getFieldUpdate(1)); + assertSame(fu1, documentUpdate.getFieldUpdate(fu1.getField())); + assertSame(fu2, documentUpdate.getFieldUpdate(fu2.getField())); - documentUpdate.removeFieldUpdate(1); + documentUpdate.removeFieldUpdate(fu2.getField()); assertEquals(1, documentUpdate.size()); - assertSame(fu1, documentUpdate.getFieldUpdate(0)); + assertSame(fu1, documentUpdate.getFieldUpdate(fu1.getField())); documentUpdate.toString(); 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 1fd45cb07c4..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.getFieldUpdates().size()); - FieldUpdate fu = put.getFieldUpdate(0); + 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.getFieldUpdates().size()); - FieldUpdate fu = put.getFieldUpdate(0); + 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 ea954f0da40..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.getFieldUpdates().size()); - FieldUpdate fieldUpd = upd.getFieldUpdate(0); + 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")); |