Adjust to yangtools-2.0.0 changes
[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 com.google.common.base.Preconditions;
11 import java.util.Collection;
12 import java.util.Optional;
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 ModificationType type,
26             final Collection<DataTreeCandidateNode> children) {
27         super(type);
28         this.children = Preconditions.checkNotNull(children);
29     }
30
31     static DataTreeCandidateNode create(final ModificationType type, final Collection<DataTreeCandidateNode> children) {
32         return new ModifiedDataTreeCandidateNode(type, children) {
33             @Override
34             public PathArgument getIdentifier() {
35                 throw new UnsupportedOperationException("Root node does not have an identifier");
36             }
37         };
38     }
39
40     static DataTreeCandidateNode create(final PathArgument identifier, final ModificationType type,
41             final Collection<DataTreeCandidateNode> children) {
42         return new ModifiedDataTreeCandidateNode(type, children) {
43             @Override
44             public PathArgument getIdentifier() {
45                 return identifier;
46             }
47         };
48     }
49
50     @Override
51     public final Optional<NormalizedNode<?, ?>> getDataAfter() {
52         throw new UnsupportedOperationException("After-image not available after serialization");
53     }
54
55     @Override
56     public final Collection<DataTreeCandidateNode> getChildNodes() {
57         return children;
58     }
59 }