public DocumentUpdate prune(Document doc) {
        verifyType(doc);

        for (Iterator<Map.Entry<Integer, FieldUpdate>> iter = id2FieldUpdates.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) {
                    FieldValue currentValue = doc.getFieldValue(update.getField());
                    if ((currentValue != null) && currentValue.equals(last.getValue())) {
                        iter.remove();
                    }
                } else if (last instanceof ClearValueUpdate) {
                    FieldValue currentValue = doc.getFieldValue(update.getField());
                    if (currentValue == null) {
                        iter.remove();
                    } else {
                        FieldValue copy = currentValue.clone();
                        copy.clear();
                        if (currentValue.equals(copy)) {
                            iter.remove();
                        }
                    }
                }
            }
        }
        return this;
    }
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
document/src/main/java/com/yahoo/document/DocumentUpdate.java