Cleanup use of Guava library
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / RootModificationApplyOperation.java
index 5cddb0d6343c7bd21b9ca7ab89b0aee6d8449f1f..a300c8850296f2d155a373ee1fed49250d757828 100644 (file)
@@ -7,10 +7,10 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
-import com.google.common.base.Optional;
-
+import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
@@ -35,9 +35,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
  * <li><b>Not Upgradable</b> - operation is immutable, invocation of
  * {@link #upgradeIfPossible()} is no-op and method {@link #snapshot()} returns
  * pointer on same object.
- *
+ * </ul>
  * <h3>Upgradable Root Modification Operation</h3>
- *
  * Upgradable Root Modification Operation may be created using:
  * <ul>
  * <li> {@link #from(ModificationApplyOperation)} with other upgradable root
@@ -46,56 +45,73 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
  * Root Modification Operations and provides an option to set latest
  * implementation.
  * </ul>
+ *
  * <p>
  * Upgradable root operation is never upgraded to latest operation
  * automatically, but client code must explicitly invoke
  * {@link #upgradeIfPossible()} to get latest implementation.
  *
+ * <p>
  * Note: This is helpful for implementing
  * {@link org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification}
  * which may be derived from
  * {@link org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree} before
  * update of schema and user actually writes data after schema update. During
  * update user did not invoked any operation.
- *
  */
-abstract class RootModificationApplyOperation implements ModificationApplyOperation {
+abstract class RootModificationApplyOperation extends ModificationApplyOperation {
 
     @Override
-    public Optional<ModificationApplyOperation> getChild(final PathArgument child) {
+    public final Optional<ModificationApplyOperation> getChild(final PathArgument child) {
         return getDelegate().getChild(child);
     }
 
     @Override
-    public final void checkApplicable(final YangInstanceIdentifier path, final NodeModification modification, final Optional<TreeNode> current)
-            throws DataValidationFailedException {
-        getDelegate().checkApplicable(path, modification, current);
+    final void checkApplicable(final YangInstanceIdentifier path, final NodeModification modification,
+            final Optional<TreeNode> current, final Version version) throws DataValidationFailedException {
+        getDelegate().checkApplicable(path, modification, current, version);
     }
 
     @Override
-    public final Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
+    final Optional<TreeNode> apply(final ModifiedNode modification, final Optional<TreeNode> currentMeta,
             final Version version) {
         return getDelegate().apply(modification, currentMeta, version);
     }
 
     @Override
-    public boolean equals(final Object obj) {
+    public final boolean equals(final Object obj) {
         return getDelegate().equals(obj);
     }
 
     @Override
-    public int hashCode() {
+    public final int hashCode() {
         return getDelegate().hashCode();
     }
 
     @Override
-    public String toString() {
+    public final String toString() {
         return getDelegate().toString();
     }
 
     @Override
-    public void verifyStructure(final ModifiedNode modification) throws IllegalArgumentException {
-        getDelegate().verifyStructure(modification);
+    final void verifyStructure(final NormalizedNode<?, ?> modification, final boolean verifyChildren)
+            throws IllegalArgumentException {
+        getDelegate().verifyStructure(modification, verifyChildren);
+    }
+
+    @Override
+    void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
+        getDelegate().recursivelyVerifyStructure(value);
+    }
+
+    @Override
+    final ChildTrackingPolicy getChildPolicy() {
+        return getDelegate().getChildPolicy();
+    }
+
+    @Override
+    final void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode<?, ?> value, final Version version) {
+        getDelegate().mergeIntoModifiedNode(node, value, version);
     }
 
     /**
@@ -107,152 +123,31 @@ abstract class RootModificationApplyOperation implements ModificationApplyOperat
 
     /**
      * Creates a snapshot from this modification, which may have separate
-     * upgrade lifecycle and is not affected by upgrades
+     * upgrade lifecycle and is not affected by upgrades.
+     *
      * <p>
-     * Newly created snapshot uses backing implementation of this modi
+     * Newly created snapshot uses backing implementation of this modification.
      *
      * @return Derived {@link RootModificationApplyOperation} with separate
      *         upgrade lifecycle.
      */
-    public abstract RootModificationApplyOperation snapshot();
+    abstract RootModificationApplyOperation snapshot();
 
     /**
      * Upgrades backing implementation to latest available, if possible.
+     *
      * <p>
      * Latest implementation of {@link RootModificationApplyOperation} is
      * managed by {@link LatestOperationHolder} which was used to construct this
      * operation and latest operation is updated by
      * {@link LatestOperationHolder#setCurrent(ModificationApplyOperation)}.
      */
-    public abstract void upgradeIfPossible();
+    abstract void upgradeIfPossible();
 
-    public static RootModificationApplyOperation from(final ModificationApplyOperation resolver) {
+    static RootModificationApplyOperation from(final ModificationApplyOperation resolver) {
         if (resolver instanceof RootModificationApplyOperation) {
             return ((RootModificationApplyOperation) resolver).snapshot();
         }
-        return new NotUpgradable(resolver);
-    }
-
-    /**
-     * Implementation of Upgradable {@link RootModificationApplyOperation}
-     *
-     * This implementation is associated with {@link LatestOperationHolder}
-     * which holds latest available implementation, which may be used for
-     * upgrade.
-     *
-     * Upgrading {@link LatestOperationHolder} will not affect any instance,
-     * unless client invoked {@link #upgradeIfPossible()} which will result in
-     * changing delegate to the latest one.
-     *
-     */
-    private static final class Upgradable extends RootModificationApplyOperation {
-
-        private final LatestOperationHolder holder;
-        private ModificationApplyOperation delegate;
-
-        public Upgradable(final LatestOperationHolder holder, final ModificationApplyOperation delegate) {
-            this.holder = holder;
-            this.delegate = delegate;
-
-        }
-
-        @Override
-        public void upgradeIfPossible() {
-            ModificationApplyOperation holderCurrent = holder.getCurrent();
-            if (holderCurrent != delegate) {
-                // FIXME: Allow update only if there is addition of models, not
-                // removals.
-                delegate = holderCurrent;
-            }
-
-        }
-
-        @Override
-        ModificationApplyOperation getDelegate() {
-            return delegate;
-        }
-
-        @Override
-        public RootModificationApplyOperation snapshot() {
-            return new Upgradable(holder, getDelegate());
-        }
-
-    }
-
-    private static final class NotUpgradable extends RootModificationApplyOperation {
-
-        private final ModificationApplyOperation delegate;
-
-        public NotUpgradable(final ModificationApplyOperation delegate) {
-            this.delegate = delegate;
-        }
-
-        @Override
-        public ModificationApplyOperation getDelegate() {
-            return delegate;
-        }
-
-        @Override
-        public void upgradeIfPossible() {
-            // Intentional noop
-        }
-
-        @Override
-        public RootModificationApplyOperation snapshot() {
-            return this;
-        }
-    }
-
-    /**
-     * Holder and factory for upgradable root modifications
-     *
-     * This class is factory for upgradable root modifications and provides an
-     * access to set latest backing implementation.
-     *
-     */
-    static class LatestOperationHolder {
-
-        private ModificationApplyOperation current = new AlwaysFailOperation();
-
-        /**
-         * Return latest backing implemenation
-         *
-         * @return
-         */
-        public ModificationApplyOperation getCurrent() {
-            return current;
-        }
-
-        /**
-         * Sets latest backing implementation of associated
-         * {@link RootModificationApplyOperation}.
-         * <p>
-         * Note: This does not result in upgrading implementation of already
-         * existing {@link RootModificationApplyOperation}. Users, which
-         * obtained instances using {@link #newSnapshot()}, deriving
-         * {@link RootModificationApplyOperation} from this modification must
-         * explicitly invoke
-         * {@link RootModificationApplyOperation#upgradeIfPossible()} on their
-         * instance to be updated to latest backing implementation.
-         *
-         * @param newApplyOper
-         *            New backing implementation
-         */
-        public void setCurrent(final ModificationApplyOperation newApplyOper) {
-            current = newApplyOper;
-        }
-
-        /**
-         *
-         * Creates new upgradable {@link RootModificationApplyOperation}
-         * associated with holder.
-         *
-         * @return New upgradable {@link RootModificationApplyOperation} with
-         *         {@link #getCurrent()} used as backing implementation.
-         */
-        public RootModificationApplyOperation newSnapshot() {
-            return new Upgradable(this, current);
-        }
-
+        return new NotUpgradableModificationApplyOperation(resolver);
     }
 }