BUG-8733: add EmptyDataTreeCandidateNode 32/60632/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 21 Jul 2017 09:07:09 +0000 (11:07 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 21 Jul 2017 10:08:45 +0000 (12:08 +0200)
This class is used by multiple downstreams, hence it is useful to
expose it from DataTreeCandidateNodes.

Change-Id: I88e247c3a9a2cb7fffab4d73f6f8b7ef211a3ea0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 14f1f133238c61049894ee8047c9c253ae9a7b3a)

yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/DataTreeCandidateNodes.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/EmptyDataTreeCandidateNode.java [new file with mode: 0644]

index 8625b4e07856006e01f51f96ff861235af1e27fe..8e271e69cb4bd833732bcc91bdd04fbb04aa34dd 100644 (file)
@@ -14,6 +14,7 @@ import java.util.Iterator;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 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;
 
 @Beta
@@ -22,6 +23,15 @@ public final class DataTreeCandidateNodes {
         throw new UnsupportedOperationException();
     }
 
+    /**
+     * Return an empty {@link DataTreeCandidateNode} identified by specified {@link PathArgument}.
+     * @param identifier Node identifier
+     * @return An empty DataTreeCandidateNode
+     */
+    public static DataTreeCandidateNode empty(final PathArgument identifier) {
+        return new EmptyDataTreeCandidateNode(identifier);
+    }
+
     public static DataTreeCandidateNode fromNormalizedNode(final NormalizedNode<?, ?> node) {
         return new NormalizedNodeDataTreeCandidateNode(node);
     }
diff --git a/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/EmptyDataTreeCandidateNode.java b/yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/tree/EmptyDataTreeCandidateNode.java
new file mode 100644 (file)
index 0000000..bd5a95f
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.api.schema.tree;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+final class EmptyDataTreeCandidateNode implements DataTreeCandidateNode {
+
+    private final PathArgument identifier;
+
+    EmptyDataTreeCandidateNode(final PathArgument identifier) {
+        this.identifier = Preconditions.checkNotNull(identifier, "Identifier should not be null");
+    }
+
+    @Nonnull
+    @Override
+    public PathArgument getIdentifier() {
+        return identifier;
+    }
+
+    @Nonnull
+    @Override
+    public Collection<DataTreeCandidateNode> getChildNodes() {
+        return ImmutableList.of();
+    }
+
+    @Nullable
+    @Override
+    public DataTreeCandidateNode getModifiedChild(final PathArgument identifier) {
+        return null;
+    }
+
+    @Nonnull
+    @Override
+    public ModificationType getModificationType() {
+        return ModificationType.UNMODIFIED;
+    }
+
+    @Nonnull
+    @Override
+    public Optional<NormalizedNode<?, ?>> getDataAfter() {
+        return Optional.absent();
+    }
+
+    @Nonnull
+    @Override
+    public Optional<NormalizedNode<?, ?>> getDataBefore() {
+        return Optional.absent();
+    }
+}
\ No newline at end of file