+ * @param child Child we are looking to modify
+ * @param modVersion Version allocated by the calling {@link InMemoryDataTreeModification}
+ * @return Before-image tree node as observed by that child.
+ */
+ private Optional<TreeNode> findOriginalMetadata(@Nonnull final PathArgument child, final Version modVersion) {
+ switch (operation) {
+ case DELETE:
+ // DELETE implies non-presence
+ return Optional.absent();
+ case NONE:
+ case TOUCH:
+ case MERGE:
+ return metadataFromSnapshot(child);
+ case WRITE:
+ // WRITE implies presence based on written data
+ return metadataFromData(child, modVersion);
+ }
+
+ throw new IllegalStateException("Unhandled node operation " + operation);
+ }
+
+ /**
+ *
+ * Returns child modification if child was modified, creates {@link ModifiedNode}