BUG-1275: teach NormalizedNode builders about size hints
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableContainerNodeBuilder.java
1 /*
2  * Copyright (c) 2013 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.impl.schema.builder.impl;
9
10 import java.util.Map;
11
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
17 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerAttrNode;
18
19 public class ImmutableContainerNodeBuilder extends AbstractImmutableDataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> {
20
21     protected ImmutableContainerNodeBuilder() {
22         super();
23     }
24
25     protected ImmutableContainerNodeBuilder(final int sizeHint) {
26         super(sizeHint);
27     }
28
29     protected ImmutableContainerNodeBuilder(final ImmutableContainerNode node) {
30         super(node);
31     }
32
33     public static DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> create() {
34         return new ImmutableContainerNodeBuilder();
35     }
36
37     public static DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> create(final int sizeHint) {
38         return new ImmutableContainerNodeBuilder(sizeHint);
39     }
40
41     public static DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> create(final ContainerNode node) {
42         if (!(node instanceof ImmutableContainerNode)) {
43             throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
44         }
45         return new ImmutableContainerNodeBuilder((ImmutableContainerNode) node);
46     }
47
48     @Override
49     public ContainerNode build() {
50         return new ImmutableContainerNode(getNodeIdentifier(), buildValue(), getAttributes());
51     }
52
53     protected static final class ImmutableContainerNode extends
54     AbstractImmutableDataContainerAttrNode<YangInstanceIdentifier.NodeIdentifier> implements ContainerNode {
55
56         ImmutableContainerNode(
57                 final YangInstanceIdentifier.NodeIdentifier nodeIdentifier,
58                 final Map<YangInstanceIdentifier.PathArgument, DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?>> children,
59                 final Map<QName, String> attributes) {
60             super(children, nodeIdentifier, attributes);
61         }
62     }
63 }