Revert "Fix mandatory enforcer failure on augmented nodes"
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / AbstractDataTreeTip.java
index c0ded40a8a5068e896045df9dc10cf50859f9cac..40c08b5b5ce9cc135c8e34e650f4db94c7bc3061 100644 (file)
@@ -7,9 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+
 import java.util.Optional;
-import javax.annotation.Nonnull;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
@@ -23,37 +25,39 @@ abstract class AbstractDataTreeTip implements DataTreeTip {
      *
      * @return Current tip root node, may not be null.
      */
-    @Nonnull protected abstract TreeNode getTipRoot();
+    protected abstract @NonNull TreeNode getTipRoot();
+
+    abstract @NonNull YangInstanceIdentifier getRootPath();
 
     @Override
     public final void validate(final DataTreeModification modification) throws DataValidationFailedException {
-        Preconditions.checkArgument(modification instanceof InMemoryDataTreeModification,
-            "Invalid modification class %s", modification.getClass());
-        final InMemoryDataTreeModification m = (InMemoryDataTreeModification)modification;
-        Preconditions.checkArgument(m.isSealed(), "Attempted to verify unsealed modification %s", m);
+        final InMemoryDataTreeModification m = checkedCast(modification);
+        checkArgument(m.isSealed(), "Attempted to verify unsealed modification %s", m);
 
-        m.getStrategy().checkApplicable(YangInstanceIdentifier.EMPTY, m.getRootModification(),
+        m.getStrategy().checkApplicable(new ModificationPath(getRootPath()), m.getRootModification(),
             Optional.of(getTipRoot()), m.getVersion());
     }
 
     @Override
     public final DataTreeCandidateTip prepare(final DataTreeModification modification) {
-        Preconditions.checkArgument(modification instanceof InMemoryDataTreeModification,
-            "Invalid modification class %s", modification.getClass());
-        final InMemoryDataTreeModification m = (InMemoryDataTreeModification)modification;
-        Preconditions.checkArgument(m.isSealed(), "Attempted to prepare unsealed modification %s", m);
+        final InMemoryDataTreeModification m = checkedCast(modification);
+        checkArgument(m.isSealed(), "Attempted to prepare unsealed modification %s", m);
 
         final ModifiedNode root = m.getRootModification();
 
         final TreeNode currentRoot = getTipRoot();
         if (root.getOperation() == LogicalOperation.NONE) {
-            return new NoopDataTreeCandidate(YangInstanceIdentifier.EMPTY, root, currentRoot);
+            return new NoopDataTreeCandidate(YangInstanceIdentifier.empty(), root, currentRoot);
         }
 
-        final Optional<TreeNode> newRoot = m.getStrategy().apply(m.getRootModification(),
+        final Optional<? extends TreeNode> newRoot = m.getStrategy().apply(m.getRootModification(),
             Optional.of(currentRoot), m.getVersion());
-        Preconditions.checkState(newRoot.isPresent(), "Apply strategy failed to produce root node for modification %s",
-            modification);
-        return new InMemoryDataTreeCandidate(YangInstanceIdentifier.EMPTY, root, currentRoot, newRoot.get());
+        checkState(newRoot.isPresent(), "Apply strategy failed to produce root node for modification %s", modification);
+        return new InMemoryDataTreeCandidate(YangInstanceIdentifier.empty(), root, currentRoot, newRoot.get());
+    }
+
+    private static InMemoryDataTreeModification checkedCast(final DataTreeModification mod) {
+        checkArgument(mod instanceof InMemoryDataTreeModification, "Invalid modification class %s", mod.getClass());
+        return (InMemoryDataTreeModification)mod;
     }
 }