Move NormalizedNode builders
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableChoiceNodeBuilder.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.ChoiceNode;
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 ImmutableChoiceNodeBuilder extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifier, ChoiceNode> {
19
20     protected ImmutableChoiceNodeBuilder() {
21
22     }
23
24     protected ImmutableChoiceNodeBuilder(final int sizeHint) {
25         super(sizeHint);
26     }
27
28     protected ImmutableChoiceNodeBuilder(final ImmutableChoiceNode node) {
29         super(node);
30     }
31
32     public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> create() {
33         return new ImmutableChoiceNodeBuilder();
34     }
35
36     public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> create(final int sizeHint) {
37         return new ImmutableChoiceNodeBuilder(sizeHint);
38     }
39
40     public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> create(final ChoiceNode node) {
41         if (!(node instanceof ImmutableChoiceNode)) {
42             throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
43         }
44
45         return new ImmutableChoiceNodeBuilder((ImmutableChoiceNode)node);
46     }
47
48     @Override
49     public ChoiceNode build() {
50         return new ImmutableChoiceNode(getNodeIdentifier(), buildValue());
51     }
52
53     private static final class ImmutableChoiceNode
54             extends AbstractImmutableDataContainerNode<NodeIdentifier, ChoiceNode> implements ChoiceNode {
55         ImmutableChoiceNode(final NodeIdentifier nodeIdentifier, final Map<PathArgument, Object> children) {
56             super(children, nodeIdentifier);
57         }
58
59         @Override
60         protected Class<ChoiceNode> implementedType() {
61             return ChoiceNode.class;
62         }
63     }
64 }