Fix followerDistributedDataStore tear down
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / persisted / ModifiedDataTreeCandidateNode.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.datastore.persisted;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.Collection;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
17 import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
18
19 /**
20  * A deserialized {@link DataTreeCandidateNode} which represents a modification in
21  * one of its children.
22  */
23 abstract class ModifiedDataTreeCandidateNode extends AbstractDataTreeCandidateNode {
24     private final @NonNull Collection<DataTreeCandidateNode> children;
25
26     private ModifiedDataTreeCandidateNode(final ModificationType type,
27             final Collection<DataTreeCandidateNode> children) {
28         super(type);
29         this.children = requireNonNull(children);
30     }
31
32     static DataTreeCandidateNode create(final ModificationType type, final Collection<DataTreeCandidateNode> children) {
33         return new ModifiedDataTreeCandidateNode(type, children) {
34             @Override
35             public PathArgument name() {
36                 throw new UnsupportedOperationException("Root node does not have an identifier");
37             }
38         };
39     }
40
41     static DataTreeCandidateNode create(final PathArgument identifier, final ModificationType type,
42             final Collection<DataTreeCandidateNode> children) {
43         return new ModifiedDataTreeCandidateNode(type, children) {
44             @Override
45             public PathArgument name() {
46                 return identifier;
47             }
48         };
49     }
50
51     @Override
52     public final NormalizedNode dataAfter() {
53         throw new UnsupportedOperationException("After-image not available after serialization");
54     }
55
56     @Override
57     public final Collection<DataTreeCandidateNode> childNodes() {
58         return children;
59     }
60 }