Do not pretty-print body class
[yangtools.git] / data / 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 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.builder.DataContainerNodeBuilder;
16 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableDataContainerNode;
17
18 public class ImmutableContainerNodeBuilder
19         extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifier, ContainerNode> {
20     protected ImmutableContainerNodeBuilder() {
21
22     }
23
24     protected ImmutableContainerNodeBuilder(final int sizeHint) {
25         super(sizeHint);
26     }
27
28     protected ImmutableContainerNodeBuilder(final ImmutableContainerNode node) {
29         super(node);
30     }
31
32     public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create() {
33         return new ImmutableContainerNodeBuilder();
34     }
35
36     public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final int sizeHint) {
37         return new ImmutableContainerNodeBuilder(sizeHint);
38     }
39
40     public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final ContainerNode node) {
41         if (!(node instanceof ImmutableContainerNode)) {
42             throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
43         }
44         return new ImmutableContainerNodeBuilder((ImmutableContainerNode) node);
45     }
46
47     @Override
48     public ContainerNode build() {
49         return new ImmutableContainerNode(getNodeIdentifier(), buildValue());
50     }
51
52     protected static final class ImmutableContainerNode
53             extends AbstractImmutableDataContainerNode<NodeIdentifier, ContainerNode> implements ContainerNode {
54         ImmutableContainerNode(final NodeIdentifier nodeIdentifier, final Map<PathArgument, Object> children) {
55             super(children, nodeIdentifier);
56         }
57
58         @Override
59         protected Class<ContainerNode> implementedType() {
60             return ContainerNode.class;
61         }
62     }
63 }