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