Merge "Bug 1437, Bug 1438 NormalizedNode Stream Writer API and Implementation"
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / ImmutableNodes.java
1 /*
2  * Copyright (c) 2014 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;
9
10 import org.opendaylight.yangtools.yang.common.QName;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
13 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
20 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
21 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
22 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
23
24 public final class ImmutableNodes {
25
26     private ImmutableNodes() {
27         throw new UnsupportedOperationException("Utilities class should not be instantiated");
28     }
29
30     public static final CollectionNodeBuilder<MapEntryNode, MapNode> mapNodeBuilder() {
31         return ImmutableMapNodeBuilder.create();
32     }
33
34     public static final CollectionNodeBuilder<MapEntryNode, MapNode> mapNodeBuilder(final QName name) {
35         return ImmutableMapNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(name));
36     }
37
38     /**
39      * Construct immutable leaf node
40      *
41      * @param name Identifier of leaf node
42      * @param value Value of leaf node
43      * @return Leaf node with supplied identifier and value
44      */
45     public static final <T> LeafNode<T> leafNode(final NodeIdentifier name,final T value) {
46         return ImmutableLeafNodeBuilder.<T>create()
47                 .withNodeIdentifier(name)
48                 .withValue(value)
49                 .build();
50     }
51
52     /**
53      *
54      * Construct immutable leaf node
55      *
56      * @param name QName which will be used as node identifier
57      * @param value Value of leaf node.
58      * @return Leaf node with supplied identifier and value
59      */
60     public static final <T> LeafNode<T> leafNode(final QName name,final T value) {
61         return leafNode(new NodeIdentifier(name), value);
62     }
63
64     public static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder(final QName nodeName,final QName keyName,final Object keyValue) {
65         return ImmutableMapEntryNodeBuilder.create()
66                 .withNodeIdentifier(new NodeIdentifierWithPredicates(nodeName, keyName,keyValue))
67                 .withChild(leafNode(keyName, keyValue));
68     }
69
70     public static MapEntryNode mapEntry(final QName nodeName,final QName keyName,final Object keyValue) {
71         return mapEntryBuilder(nodeName, keyName, keyValue).build();
72     }
73
74     public static DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder() {
75         return ImmutableMapEntryNodeBuilder.create();
76     }
77
78     public static NormalizedNode<?, ?> containerNode(final QName name) {
79         return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(name)).build();
80     }
81
82 }