diff options
Diffstat (limited to 'document')
-rw-r--r-- | document/src/main/java/com/yahoo/document/DocumentUpdate.java | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/document/src/main/java/com/yahoo/document/DocumentUpdate.java b/document/src/main/java/com/yahoo/document/DocumentUpdate.java index ef5fdc290c7..91e4a7091b8 100644 --- a/document/src/main/java/com/yahoo/document/DocumentUpdate.java +++ b/document/src/main/java/com/yahoo/document/DocumentUpdate.java @@ -97,6 +97,12 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP docId = id; } + private void verifyType(Document doc) { + if (!documentType.equals(doc.getDataType())) { + throw new IllegalArgumentException( + "Document " + doc.getId() + " with type " + doc.getDataType() + " must have same type as update, which is type " + documentType); + } + } /** * Applies this document update. * @@ -105,10 +111,7 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP * @throws IllegalArgumentException if the document does not have the same document type as this update */ public DocumentUpdate applyTo(Document doc) { - if (!documentType.equals(doc.getDataType())) { - throw new IllegalArgumentException( - "Document " + doc + " must have same type as update, which is type " + documentType); - } + verifyType(doc); for (FieldUpdate fieldUpdate : fieldUpdates) { fieldUpdate.applyTo(doc); @@ -120,18 +123,15 @@ public class DocumentUpdate extends DocumentOperation implements Iterable<FieldP } /** - * Will prune away any field update that will not modify any field in the document. - * @param doc + * Prune away any field update that will not modify any field in the document. + * @param doc document to check against * @return a reference to itself * @throws IllegalArgumentException if the document does not have the same document type as this update */ public DocumentUpdate prune(Document doc) { if ( ! fieldPathUpdates.isEmpty()) return this; - if (!documentType.equals(doc.getDataType())) { - throw new IllegalArgumentException( - "Document " + doc + " must have same type as update, which is type " + documentType); - } + verifyType(doc); for (Iterator<FieldUpdate> iter = fieldUpdates.iterator(); iter.hasNext();) { FieldUpdate update = iter.next(); |