Update MutableTreeNode methods
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / tree / spi / MutableTreeNode.java
1 /*
2  * Copyright (c) 2014 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.yangtools.yang.data.api.schema.tree.spi;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.eclipse.jdt.annotation.Nullable;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
13 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
15
16 /**
17  * A mutable tree node. This is a transient view materialized from a pre-existing node. Modifications are isolated. Once
18  * this object is {@link #seal()}ed, any interactions with it will result in undefined behavior.
19  */
20 public interface MutableTreeNode extends StoreTreeNode<TreeNode> {
21     /**
22      * Set the data component of the node.
23      *
24      * @param data New data component, may not be null.
25      * @throws NullPointerException if {@code data} is null
26      */
27     void setData(NormalizedNode<?, ?> data);
28
29     /**
30      * Set the new subtree version. This is typically invoked when the user
31      * has modified some of this node's children.
32      *
33      * @param subtreeVersion New subtree version.
34      * @throws NullPointerException if {@code subtreeVersion} is null
35      */
36     void setSubtreeVersion(Version subtreeVersion);
37
38     /**
39      * Add a new child node. This acts as add-or-replace operation, e.g. it succeeds even if a conflicting child is
40      * already present.
41      *
42      * @param child New child node.
43      * @return Replaced child, or null if there was no previous child
44      * @throws NullPointerException if {@code child} is null
45      */
46     @Nullable TreeNode putChild(TreeNode child);
47
48     /**
49      * Remove a child node. This acts as delete-or-nothing operation, e.g. it succeeds even if the corresponding child
50      * is not present.
51      *
52      * @param id Child identifier.
53      * @return Removed child, or null if there was no matching child
54      * @throws NullPointerException if {@code id} is null
55      */
56     @Nullable TreeNode removeChild(PathArgument id);
57
58     /**
59      * Finish node modification and return a read-only view of this node. After
60      * this method is invoked, any further calls to this object's method result
61      * in undefined behavior.
62      *
63      * @return Read-only view of this node.
64      */
65     @NonNull TreeNode seal();
66 }