diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2018-09-18 10:34:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-18 10:34:25 +0200 |
commit | 688961517b28efd58f3b0a3505bfacb608664a8f (patch) | |
tree | 24b753af4d53b711f7de1dbcdfb29ad65a8f393d /document | |
parent | 25a8bf88ab9a9dbe15c786772ab053ec74dea686 (diff) |
Revert "Revert "Revert "Do not expose fieldupdates as a list. Hide implementation details ins…"""
Diffstat (limited to 'document')
8 files changed, 97 insertions, 177 deletions
diff --git a/document/src/main/java/com/yahoo/document/DocumentUpdate.java b/document/src/main/java/com/yahoo/document/DocumentUpdate.java index 301d6af0f54..ad93942c1c0 100644 --- a/document/src/main/java/com/yahoo/document/DocumentUpdate.java +++ b/document/src/main/java/com/yahoo/document/DocumentUpdate.java @@ -13,12 +13,9 @@ 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; /** @@ -40,17 +37,14 @@ 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 public static final int CLASSID = 0x1000 + 6; private DocumentId docId; - private final List<FieldUpdate> fieldUpdates; - private final Map<Integer, FieldUpdate> id2FieldUpdateMap; - private final List<FieldPathUpdate> fieldPathUpdates; + private List<FieldUpdate> fieldUpdates; + private List<FieldPathUpdate> fieldPathUpdates; private DocumentType documentType; private Optional<Boolean> createIfNonExistent = Optional.empty(); @@ -61,7 +55,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 HashMap<>()); + this(docType, docId, new ArrayList<FieldUpdate>()); } /** @@ -71,7 +65,6 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP docId = null; documentType = null; fieldUpdates = new ArrayList<>(); - id2FieldUpdateMap = new HashMap<>(); fieldPathUpdates = new ArrayList<>(); reader.read(this); } @@ -86,11 +79,10 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP this(docType, new DocumentId(docId)); } - private DocumentUpdate(DocumentType docType, DocumentId docId, Map<Integer, FieldUpdate> id2fieldUpdateMap) { + private DocumentUpdate(DocumentType docType, DocumentId docId, List<FieldUpdate> fieldUpdates) { this.docId = docId; this.documentType = docType; - this.fieldUpdates = new ArrayList<>(id2fieldUpdateMap.values()); - id2FieldUpdateMap = id2fieldUpdateMap; + this.fieldUpdates = fieldUpdates; this.fieldPathUpdates = new ArrayList<>(); } @@ -122,7 +114,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP public DocumentUpdate applyTo(Document doc) { verifyType(doc); - for (FieldUpdate fieldUpdate : id2FieldUpdateMap.values()) { + for (FieldUpdate fieldUpdate : fieldUpdates) { fieldUpdate.applyTo(doc); } for (FieldPathUpdate fieldPathUpdate : fieldPathUpdates) { @@ -140,9 +132,8 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP public DocumentUpdate prune(Document doc) { verifyType(doc); - for (Iterator<Map.Entry<Integer, FieldUpdate>> iter = id2FieldUpdateMap.entrySet().iterator(); iter.hasNext();) { - Map.Entry<Integer, FieldUpdate> entry = iter.next(); - FieldUpdate update = entry.getValue(); + for (Iterator<FieldUpdate> iter = fieldUpdates.iterator(); iter.hasNext();) { + FieldUpdate update = iter.next(); if (!update.isEmpty()) { ValueUpdate last = update.getValueUpdate(update.size() - 1); if (last instanceof AssignValueUpdate) { @@ -171,42 +162,20 @@ 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 @@ -229,9 +198,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) { return fieldUpdates.get(index); } @@ -243,16 +210,9 @@ 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) { - FieldUpdate old = fieldUpdates.get(index); - fieldUpdates.set(index, upd); - id2FieldUpdateMap.remove(old.getField().getId()); - id2FieldUpdateMap.put(upd.getField().getId(), upd); - - return old; + return fieldUpdates.set(index, upd); } /** @@ -262,13 +222,12 @@ 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 getFieldUpdateById(field.getId()); + return getFieldUpdate(field.getName()); } /** Removes all field updates from the list for field updates. */ public void clearFieldUpdates() { fieldUpdates.clear(); - id2FieldUpdateMap.clear(); } /** @@ -278,33 +237,27 @@ 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) { - return getFieldUpdate(documentType.getField(fieldName)); - } - private FieldUpdate getFieldUpdateById(Integer fieldId) { - return id2FieldUpdateMap.get(fieldId); + for (FieldUpdate fieldUpdate : fieldUpdates) { + if (fieldUpdate.getField().getName().equals(fieldName)) { + return fieldUpdate; + } + } + return null; } /** * 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. Also note that there no assumptions can be made on the order of items - * after this call. They might have been joined if for the same field or reordered. + * by the caller. The list may not be unmodifiable. * * @param fieldUpdates the new list of updates of this * @throws NullPointerException if the argument passed is null */ - public void setFieldUpdates(Collection<FieldUpdate> fieldUpdates) { + public void setFieldUpdates(List<FieldUpdate> fieldUpdates) { if (fieldUpdates == null) { throw new NullPointerException("The field updates of a document update can not be null"); } - clearFieldUpdates(); - addFieldUpdates(fieldUpdates); - } - - public void addFieldUpdates(Collection<FieldUpdate> fieldUpdates) { - for (FieldUpdate fieldUpdate : fieldUpdates) { - addFieldUpdate(fieldUpdate); - } + this.fieldUpdates = fieldUpdates; } /** @@ -313,7 +266,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * @return the size of the List of FieldUpdates */ public int size() { - return id2FieldUpdateMap.size(); + return fieldUpdates.size(); } /** @@ -326,17 +279,17 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * field. */ public DocumentUpdate addFieldUpdate(FieldUpdate update) { - Integer fieldId = update.getField().getId(); - if (documentType.getField(fieldId) == null) { - throw new IllegalArgumentException("Document type '" + documentType.getName() + "' does not have field '" + update.getField().getName() + "'."); + String fieldName = update.getField().getName(); + if (!documentType.hasField(fieldName)) { + throw new IllegalArgumentException("Document type '" + documentType.getName() + "' does not have field '" + + fieldName + "'."); } - FieldUpdate prevUpdate = getFieldUpdateById(fieldId); + FieldUpdate prevUpdate = getFieldUpdate(fieldName); if (prevUpdate != update) { if (prevUpdate != null) { prevUpdate.addAll(update); } else { fieldUpdates.add(update); - id2FieldUpdateMap.put(fieldId, update); } } return this; @@ -352,6 +305,12 @@ 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. @@ -370,7 +329,9 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP if (!documentType.equals(update.documentType)) { throw new IllegalArgumentException("Expected " + documentType + ", got " + update.documentType + "."); } - addFieldUpdates(update.fieldUpdates()); + for (FieldUpdate fieldUpd : update.fieldUpdates) { + addFieldUpdate(fieldUpd); + } for (FieldPathUpdate pathUpd : update.fieldPathUpdates) { addFieldPathUpdate(pathUpd); } @@ -382,21 +343,9 @@ 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) { - FieldUpdate prev = getFieldUpdate(index); - fieldUpdates.remove(index); - return removeFieldUpdate(prev.getField()); - } - - public FieldUpdate removeFieldUpdate(Field field) { - return id2FieldUpdateMap.remove(field.getId()); - } - - public FieldUpdate removeFieldUpdate(String fieldName) { - return removeFieldUpdate(documentType.getField(fieldName)); + return fieldUpdates.remove(index); } /** @@ -427,7 +376,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP if (documentType != null ? !documentType.equals(that.documentType) : that.documentType != null) return false; if (fieldPathUpdates != null ? !fieldPathUpdates.equals(that.fieldPathUpdates) : that.fieldPathUpdates != null) return false; - if (id2FieldUpdateMap != null ? !id2FieldUpdateMap.equals(that.id2FieldUpdateMap) : that.id2FieldUpdateMap != null) return false; + if (fieldUpdates != null ? !fieldUpdates.equals(that.fieldUpdates) : that.fieldUpdates != null) return false; if (this.getCreateIfNonExistent() != ((DocumentUpdate) o).getCreateIfNonExistent()) return false; return true; @@ -436,7 +385,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP @Override public int hashCode() { int result = docId != null ? docId.hashCode() : 0; - result = 31 * result + (id2FieldUpdateMap != null ? id2FieldUpdateMap.hashCode() : 0); + result = 31 * result + (fieldUpdates != null ? fieldUpdates.hashCode() : 0); result = 31 * result + (fieldPathUpdates != null ? fieldPathUpdates.hashCode() : 0); result = 31 * result + (documentType != null ? documentType.hashCode() : 0); return result; @@ -453,7 +402,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP string.append(": "); string.append("["); - for (Iterator<FieldUpdate> i = id2FieldUpdateMap.values().iterator(); i.hasNext();) { + for (Iterator<FieldUpdate> i = fieldUpdates.iterator(); i.hasNext();) { FieldUpdate fieldUpdate = i.next(); string.append(fieldUpdate); if (i.hasNext()) { @@ -483,7 +432,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * @return True if this update is empty. */ public boolean isEmpty() { - return id2FieldUpdateMap.isEmpty() && fieldPathUpdates.isEmpty(); + return fieldUpdates.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 6adae27cadc..b9b273d691f 100644 --- a/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java +++ b/document/src/main/java/com/yahoo/document/json/DocumentUpdateJsonSerializer.java @@ -47,7 +47,6 @@ 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; @@ -106,11 +105,11 @@ public class DocumentUpdateJsonSerializer } generator.writeObjectFieldStart("fields"); - for (FieldUpdate up : update.fieldUpdates()) { + for (FieldUpdate up : update.getFieldUpdates()) { up.serialize(this); } - update.fieldPathUpdates().stream() + update.getFieldPathUpdates().stream() .collect(Collectors.groupingBy(FieldPathUpdate::getFieldPath)) .forEach((fieldPath, fieldPathUpdates) -> wrapIOException(() -> write(fieldPath, fieldPathUpdates, generator))); @@ -121,7 +120,7 @@ public class DocumentUpdateJsonSerializer }); } - private void write(FieldPath fieldPath, Collection<FieldPathUpdate> fieldPathUpdates, JsonGenerator generator) throws IOException { + private void write(FieldPath fieldPath, List<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 3f885844987..a048ea349eb 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.addFieldUpdate(new FieldUpdate(this, update.getDocumentType(), serializationVersion)); + update.addFieldUpdateNoCheck(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 4f8a26d3777..7bdc6fd5355 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.addFieldUpdate(new FieldUpdate(this, update.getDocumentType(), 8)); + update.addFieldUpdateNoCheck(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 53f68ca182c..15319985591 100644 --- a/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentUpdateTestCase.java @@ -1,19 +1,10 @@ // 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.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.datatypes.*; import com.yahoo.document.fieldpathupdate.FieldPathUpdate; -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.select.parser.ParseException; +import com.yahoo.document.serialization.*; import com.yahoo.document.update.AssignValueUpdate; import com.yahoo.document.update.FieldUpdate; import com.yahoo.document.update.ValueUpdate; @@ -268,8 +259,8 @@ public class DocumentUpdateTestCase { update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(1))); update.addFieldUpdate(FieldUpdate.createAssign(field, new IntegerFieldValue(2))); - assertEquals(1, update.fieldUpdates().size()); - FieldUpdate fieldUpdate = update.getFieldUpdate(field); + assertEquals(1, update.getFieldUpdates().size()); + FieldUpdate fieldUpdate = update.getFieldUpdate(0); assertNotNull(fieldUpdate); assertEquals(field, fieldUpdate.getField()); assertEquals(2, fieldUpdate.getValueUpdates().size()); @@ -351,16 +342,13 @@ public class DocumentUpdateTestCase { assertEquals(new DocumentId("doc:update:test"), upd.getId()); assertEquals(type, upd.getType()); - FieldUpdate serAssignFU = upd.getFieldUpdate(type.getField("intfield")); + FieldUpdate serAssignFU = upd.getFieldUpdate(0); assertEquals(type.getField("intfield"), serAssignFU.getField()); ValueUpdate serAssign = serAssignFU.getValueUpdate(0); assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, serAssign.getValueUpdateClassID()); assertEquals(new IntegerFieldValue(4), serAssign.getValue()); - ValueUpdate serArith = serAssignFU.getValueUpdate(1); - assertEquals(ValueUpdate.ValueUpdateClassID.ARITHMETIC, serArith.getValueUpdateClassID()); - - FieldUpdate serAddFU = upd.getFieldUpdate(type.getField("arrayoffloatfield")); + FieldUpdate serAddFU = upd.getFieldUpdate(2); assertEquals(type.getField("arrayoffloatfield"), serAddFU.getField()); ValueUpdate serAdd1 = serAddFU.getValueUpdate(0); assertEquals(ValueUpdate.ValueUpdateClassID.ADD, serAdd1.getValueUpdateClassID()); @@ -375,7 +363,12 @@ public class DocumentUpdateTestCase { FloatFieldValue addparam3 = (FloatFieldValue)serAdd3.getValue(); assertEquals(new FloatFieldValue(-1.00f), addparam3); - FieldUpdate wsetFU = upd.getFieldUpdate(type.getField("wsfield")); + 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); assertEquals(type.getField("wsfield"), wsetFU.getField()); assertEquals(2, wsetFU.size()); ValueUpdate mapUpd = wsetFU.getValueUpdate(0); @@ -427,8 +420,8 @@ public class DocumentUpdateTestCase { barUpdate.addFieldUpdate(barField); fooUpdate.addAll(barUpdate); - assertEquals(1, fooUpdate.fieldUpdates().size()); - FieldUpdate fieldUpdate = fooUpdate.getFieldUpdate(field); + assertEquals(1, fooUpdate.getFieldUpdates().size()); + FieldUpdate fieldUpdate = fooUpdate.getFieldUpdate(0); assertNotNull(fieldUpdate); assertEquals(field, fieldUpdate.getField()); assertEquals(2, fieldUpdate.getValueUpdates().size()); @@ -442,30 +435,6 @@ public class DocumentUpdateTestCase { } @Test - public void testgetAndRemoveByName() { - DocumentType docType = new DocumentType("my_type"); - Field my_int = new Field("my_int", DataType.INT); - Field your_int = new Field("your_int", DataType.INT); - docType.addField(my_int); - docType.addField(your_int); - DocumentUpdate update = new DocumentUpdate(docType, new DocumentId("doc:this:is:a:test")); - - update.addFieldUpdate(FieldUpdate.createAssign(my_int, new IntegerFieldValue(2))); - assertNull(update.getFieldUpdate("your_int")); - assertEquals(new IntegerFieldValue(2), update.getFieldUpdate("my_int").getValueUpdate(0).getValue()); - assertNull(update.removeFieldUpdate("your_int")); - assertEquals(new IntegerFieldValue(2), update.removeFieldUpdate("my_int").getValueUpdate(0).getValue()); - assertNull(update.getFieldUpdate("my_int")); - - update.addFieldUpdate(FieldUpdate.createAssign(my_int, new IntegerFieldValue(2))); - assertNull(update.getFieldUpdate(your_int)); - assertEquals(new IntegerFieldValue(2), update.getFieldUpdate(my_int).getValueUpdate(0).getValue()); - assertNull(update.removeFieldUpdate(your_int)); - assertEquals(new IntegerFieldValue(2), update.removeFieldUpdate(my_int).getValueUpdate(0).getValue()); - assertNull(update.getFieldUpdate(my_int)); - } - - @Test public void testInstantiationAndEqualsHashCode() { DocumentType type = new DocumentType("doo"); DocumentUpdate d1 = new DocumentUpdate(type, new DocumentId("doc:this:is:a:test")); @@ -496,7 +465,6 @@ public class DocumentUpdateTestCase { } @Test - @SuppressWarnings("deprecation") public void testFieldUpdatesInDocUp() { DocumentType t1 = new DocumentType("doo"); Field f1 = new Field("field1", DataType.STRING); @@ -525,6 +493,14 @@ 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); @@ -539,12 +515,12 @@ public class DocumentUpdateTestCase { documentUpdate.setFieldUpdates(fus); assertEquals(2, documentUpdate.size()); - assertSame(fu1, documentUpdate.getFieldUpdate(fu1.getField())); - assertSame(fu2, documentUpdate.getFieldUpdate(fu2.getField())); + assertSame(fu1, documentUpdate.getFieldUpdate(0)); + assertSame(fu2, documentUpdate.getFieldUpdate(1)); - documentUpdate.removeFieldUpdate(fu2.getField()); + documentUpdate.removeFieldUpdate(1); assertEquals(1, documentUpdate.size()); - assertSame(fu1, documentUpdate.getFieldUpdate(fu1.getField())); + assertSame(fu1, documentUpdate.getFieldUpdate(0)); 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 32f63e6c0b3..1fd45cb07c4 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.fieldUpdates().size()); - FieldUpdate fu = put.fieldUpdates().iterator().next(); + assertEquals(1, put.getFieldUpdates().size()); + FieldUpdate fu = put.getFieldUpdate(0); 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.fieldUpdates().size()); - FieldUpdate fu = put.fieldUpdates().iterator().next(); + assertEquals(1, put.getFieldUpdates().size()); + FieldUpdate fu = put.getFieldUpdate(0); 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 dcdea0975ad..ea954f0da40 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.fieldUpdates().size()); - FieldUpdate fieldUpd = upd.fieldUpdates().iterator().next(); + assertEquals(1, upd.getFieldUpdates().size()); + FieldUpdate fieldUpd = upd.getFieldUpdate(0); 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 1aad59f4c56..4c64f7c35cb 100755 --- a/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java +++ b/document/src/test/java/com/yahoo/vespaxmlparser/VespaXMLReaderTestCase.java @@ -5,7 +5,6 @@ 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; @@ -17,7 +16,6 @@ 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.*; @@ -689,105 +687,103 @@ public class VespaXMLReaderTestCase { DocumentUpdate docUpdate = op.getDocumentUpdate(); - assertEquals(20, docUpdate.fieldPathUpdates().size()); + assertEquals(20, docUpdate.getFieldPathUpdates().size()); - Iterator<FieldPathUpdate> updates = docUpdate.fieldPathUpdates().iterator(); { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(0); assertEquals("url", ass.getOriginalFieldPath()); assertEquals(new StringFieldValue("assignUrl"), ass.getNewValue()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(1); assertEquals("title", ass.getOriginalFieldPath()); assertEquals(new StringFieldValue("assignTitle"), ass.getNewValue()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(2); assertEquals("last_downloaded", ass.getOriginalFieldPath()); assertEquals("1", ass.getExpression()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(3); assertEquals("value_long", ass.getOriginalFieldPath()); assertEquals("2", ass.getExpression()); } - updates.next(); // Skip number 5 { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(5); assertEquals("stringarr", ass.getOriginalFieldPath()); assertEquals("[assignString1, assignString2]", ass.getNewValue().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(6); assertEquals("intarr", ass.getOriginalFieldPath()); assertEquals("[3, 4]", ass.getNewValue().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(7); assertEquals("longarr", ass.getOriginalFieldPath()); assertEquals("[5, 6]", ass.getNewValue().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(8); assertEquals("bytearr", ass.getOriginalFieldPath()); assertEquals("[7, 8]", ass.getNewValue().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(9); assertEquals("floatarr", ass.getOriginalFieldPath()); assertEquals("[9.0, 10.0]", ass.getNewValue().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(10); 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)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(11); 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)updates.next(); + AddFieldPathUpdate ass = (AddFieldPathUpdate)docUpdate.getFieldPathUpdates().get(12); assertEquals("stringarr", ass.getOriginalFieldPath()); assertEquals("[addString1, addString2]", ass.getNewValues().toString()); } { - AddFieldPathUpdate ass = (AddFieldPathUpdate)updates.next(); + AddFieldPathUpdate ass = (AddFieldPathUpdate)docUpdate.getFieldPathUpdates().get(13); assertEquals("longarr", ass.getOriginalFieldPath()); assertEquals("[5]", ass.getNewValues().toString()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(14); assertEquals("weightedsetint{13}", ass.getOriginalFieldPath()); assertEquals("13", ass.getExpression()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(15); assertEquals("weightedsetint{14}", ass.getOriginalFieldPath()); assertEquals("14", ass.getExpression()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(16); assertEquals("weightedsetstring{add13}", ass.getOriginalFieldPath()); assertEquals("1", ass.getExpression()); } { - AssignFieldPathUpdate ass = (AssignFieldPathUpdate)updates.next(); + AssignFieldPathUpdate ass = (AssignFieldPathUpdate)docUpdate.getFieldPathUpdates().get(17); assertEquals("weightedsetstring{assign13}", ass.getOriginalFieldPath()); assertEquals("130", ass.getExpression()); } { - RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)updates.next(); + RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)docUpdate.getFieldPathUpdates().get(18); assertEquals("weightedsetstring{assign14}", ass.getOriginalFieldPath()); } { - RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)updates.next(); + RemoveFieldPathUpdate ass = (RemoveFieldPathUpdate)docUpdate.getFieldPathUpdates().get(19); assertEquals("bytearr", ass.getOriginalFieldPath()); } Document doc = new Document(manager.getDocumentType("news"), new DocumentId("doc:test:test:test")); |