Split out yang-data-spi
[yangtools.git] / data / yang-data-spi / src / main / java / org / opendaylight / yangtools / yang / data / spi / tree / LazyMutableContainerNode.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.yangtools.yang.data.spi.tree;
9
10 import java.util.Map;
11 import org.opendaylight.yangtools.util.MapAdaptor;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
13
14 /**
15  * A container node which may need further materialization. Materialized nodes are tracked in a map, which is consulted
16  * before creating a new child node from backing data. Since the child is immutable, we do not have to track it.
17  */
18 final class LazyMutableContainerNode extends AbstractMutableContainerNode {
19     LazyMutableContainerNode(final AbstractContainerNode parent) {
20         this(parent, MapAdaptor.getDefaultInstance().initialSnapshot(1));
21     }
22
23     LazyMutableContainerNode(final AbstractContainerNode parent, final Map<PathArgument, TreeNode> children) {
24         super(parent, children);
25     }
26
27     @Override
28     public TreeNode childByArg(final PathArgument arg) {
29         final TreeNode modified = getModifiedChild(arg);
30         return modified != null ? modified : AbstractContainerNode.getChildFromData(getData(), arg, getVersion());
31     }
32 }