BUG-1886: split static classes into separate files 46/12146/1
authorRobert Varga <rovarga@cisco.com>
Tue, 16 Sep 2014 11:40:06 +0000 (13:40 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Wed, 22 Oct 2014 11:44:14 +0000 (13:44 +0200)
This is in preparation for better lifecycle management. Also reuses a
single instance of AlwaysFailOperation.

Change-Id: I13dab22841a9311b87bc6e9b79dd479c2792263e
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit fa617231bb83ab0c45e6a5c8cabeec2b8fe1efeb)

yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AlwaysFailOperation.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/InMemoryDataTree.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/LatestOperationHolder.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NotUpgradableModificationApplyOperation.java [new file with mode: 0644]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/RootModificationApplyOperation.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UpgradableModificationApplyOperation.java [new file with mode: 0644]

index 3c4ed612a5b3ba8c4ff147a34dabc05bc4e07ef6..8c167905230f2b054799db729b97111893501b57 100644 (file)
@@ -14,6 +14,12 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
  * perform anything meaningful.
  */
 final class AlwaysFailOperation implements ModificationApplyOperation {
+    public static final ModificationApplyOperation INSTANCE = new AlwaysFailOperation();
+
+    private AlwaysFailOperation() {
+
+    }
+
     @Override
     public Optional<TreeNode> apply(final ModifiedNode modification,
             final Optional<TreeNode> storeMeta, final Version version) {
index b8344d896387f9cbc7c35ebf785f6a5d681bfaf8..beed7771cecb298848dfdf95bcf8aa643fb0086b 100644 (file)
@@ -18,7 +18,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.tree.RootModificationApplyOperation.LatestOperationHolder;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/LatestOperationHolder.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/LatestOperationHolder.java
new file mode 100644 (file)
index 0000000..da5af3b
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+
+/**
+ * Holder and factory for upgradable root modifications
+ *
+ * This class is factory for upgradable root modifications and provides an
+ * access to set latest backing implementation.
+ */
+class LatestOperationHolder {
+
+    private ModificationApplyOperation current = AlwaysFailOperation.INSTANCE;
+
+    /**
+     * 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 UpgradableModificationApplyOperation(this, current);
+    }
+
+}
\ No newline at end of file
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NotUpgradableModificationApplyOperation.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NotUpgradableModificationApplyOperation.java
new file mode 100644 (file)
index 0000000..efb4ae2
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+
+final class NotUpgradableModificationApplyOperation extends RootModificationApplyOperation {
+    private final ModificationApplyOperation delegate;
+
+    public NotUpgradableModificationApplyOperation(final ModificationApplyOperation delegate) {
+        this.delegate = delegate;
+    }
+
+    @Override
+    public ModificationApplyOperation getDelegate() {
+        return delegate;
+    }
+
+    @Override
+    public void upgradeIfPossible() {
+        // Intentional noop
+    }
+
+    @Override
+    public RootModificationApplyOperation snapshot() {
+        return this;
+    }
+}
\ No newline at end of file
index 5cddb0d6343c7bd21b9ca7ab89b0aee6d8449f1f..18425dc243f7923d9e79ed81fed8776b45f1526a 100644 (file)
@@ -130,129 +130,6 @@ abstract class RootModificationApplyOperation implements ModificationApplyOperat
         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);
     }
 }
diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UpgradableModificationApplyOperation.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/UpgradableModificationApplyOperation.java
new file mode 100644 (file)
index 0000000..0727e44
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+
+/**
+ * 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.
+ *
+ */
+final class UpgradableModificationApplyOperation extends RootModificationApplyOperation {
+
+    private final LatestOperationHolder holder;
+    private ModificationApplyOperation delegate;
+
+    public UpgradableModificationApplyOperation(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 UpgradableModificationApplyOperation(holder, getDelegate());
+    }
+
+}
\ No newline at end of file