Merge "Tests for DOMDataTreeListener"
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / 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;
9
10 import com.google.common.base.Optional;
11 import com.google.common.base.Preconditions;
12 import java.util.Collection;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
17
18 /**
19  * A deserialized {@link DataTreeCandidateNode} which represents a modification in
20  * one of its children.
21  */
22 abstract class ModifiedDataTreeCandidateNode extends AbstractDataTreeCandidateNode {
23     private final Collection<DataTreeCandidateNode> children;
24
25     private ModifiedDataTreeCandidateNode(final Collection<DataTreeCandidateNode> children) {
26         super(ModificationType.SUBTREE_MODIFIED);
27         this.children = Preconditions.checkNotNull(children);
28     }
29
30     static DataTreeCandidateNode create(final Collection<DataTreeCandidateNode> children) {
31         return new ModifiedDataTreeCandidateNode(children) {
32             @Override
33             public PathArgument getIdentifier() {
34                 throw new UnsupportedOperationException("Root node does not have an identifier");
35             }
36         };
37     }
38
39     static DataTreeCandidateNode create(final PathArgument identifier, final Collection<DataTreeCandidateNode> children) {
40         return new ModifiedDataTreeCandidateNode(children) {
41             @Override
42             public final PathArgument getIdentifier() {
43                 return identifier;
44             }
45         };
46     }
47
48     @Override
49     public final Optional<NormalizedNode<?, ?>> getDataAfter() {
50         throw new UnsupportedOperationException("After-image not available after serialization");
51     }
52
53     @Override
54     public final Collection<DataTreeCandidateNode> getChildNodes() {
55         return children;
56     }
57 }