Migrate tests to use node.spi.ImmutableNodes
[yangtools.git] / data / yang-data-spi / src / main / java / org / opendaylight / yangtools / yang / data / spi / node / ImmutableNodes.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.spi.node;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
14 import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.AnyxmlNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
19 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
20 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode.BuilderFactory;
23 import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
24 import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
25 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
28 import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
29 import org.opendaylight.yangtools.yang.data.spi.node.impl.ImmutableBuilderFactory;
30 import org.opendaylight.yangtools.yang.data.spi.node.impl.ImmutableLeafNode;
31 import org.opendaylight.yangtools.yang.data.spi.node.impl.ImmutableLeafSetEntryNode;
32
33 /**
34  * Utilities for creating immutable implementations of various {@link NormalizedNode}s.
35  */
36 public final class ImmutableNodes {
37     private static final @NonNull ImmutableBuilderFactory BUILDER_FACTORY = new ImmutableBuilderFactory();
38
39     private ImmutableNodes() {
40         // Hidden on purpose
41     }
42
43     public static @NonNull BuilderFactory builderFactory() {
44         return BUILDER_FACTORY;
45     }
46
47     /**
48      * Construct an immutable {@link LeafNode}.
49      *
50      * @param <T> Type of leaf node value
51      * @param name Name of leaf node
52      * @param value Value of leaf node
53      * @return Leaf node with supplied name and value
54      * @throws NullPointerException if any argument is {@code null}
55      */
56     public static <T> @NonNull LeafNode<T> leafNode(final NodeIdentifier name, final T value) {
57         return ImmutableLeafNode.of(name, value);
58     }
59
60     /**
61      * Construct an immutable {@link LeafNode}.
62      *
63      * @param <T> Type of leaf node value
64      * @param name Name of leaf node
65      * @param value Value of leaf node
66      * @return Leaf node with supplied name and value
67      * @throws NullPointerException if any argument is {@code null}
68      */
69     public static <T> @NonNull LeafNode<T> leafNode(final QName name, final T value) {
70         return leafNode(NodeIdentifier.create(name), value);
71     }
72
73     public static <T> @NonNull LeafSetEntryNode<T> leafSetEntry(final NodeWithValue<T> name) {
74         return ImmutableLeafSetEntryNode.of(name);
75     }
76
77     public static <T> @NonNull LeafSetEntryNode<T> leafSetEntry(final QName name, final T value) {
78         return leafSetEntry(new NodeWithValue<>(name, value));
79     }
80
81     public static <T> AnydataNode.@NonNull Builder<T> newAnydataBuilder(final Class<T> objectModel) {
82         return BUILDER_FACTORY.newAnydataBuilder(objectModel);
83     }
84
85     public static <T> AnyxmlNode.@NonNull Builder<T, AnyxmlNode<T>> newAnyxmlBuilder(final Class<T> objectModel) {
86         return BUILDER_FACTORY.newAnyxmlBuilder(objectModel);
87     }
88
89     public static ChoiceNode.@NonNull Builder newChoiceBuilder() {
90         return BUILDER_FACTORY.newChoiceBuilder();
91     }
92
93     public static ContainerNode.@NonNull Builder newContainerBuilder() {
94         return BUILDER_FACTORY.newContainerBuilder();
95     }
96
97     public static MapEntryNode.@NonNull Builder newMapEntryBuilder() {
98         return BUILDER_FACTORY.newMapEntryBuilder();
99     }
100
101     public static SystemMapNode.@NonNull Builder newSystemMapBuilder() {
102         return BUILDER_FACTORY.newSystemMapBuilder();
103     }
104
105     public static UserMapNode.@NonNull Builder newUserMapBuilder() {
106         return BUILDER_FACTORY.newUserMapBuilder();
107     }
108
109     public static UnkeyedListEntryNode.@NonNull Builder newUnkeyedListEntryBuilder() {
110         return BUILDER_FACTORY.newUnkeyedListEntryBuilder();
111     }
112
113     public static UnkeyedListNode.@NonNull Builder newUnkeyedListBuilder() {
114         return BUILDER_FACTORY.newUnkeyedListBuilder();
115     }
116
117     public static <T> LeafNode.@NonNull Builder<T> newLeafBuilder() {
118         return BUILDER_FACTORY.newLeafBuilder();
119     }
120
121     public static <T> LeafSetEntryNode.@NonNull Builder<T> newLeafSetEntryBuilder() {
122         return BUILDER_FACTORY.newLeafSetEntryBuilder();
123     }
124
125     public static <T> SystemLeafSetNode.@NonNull Builder<T> newSystemLeafSetBuilder() {
126         return BUILDER_FACTORY.newSystemLeafSetBuilder();
127     }
128
129     public static <T> UserLeafSetNode.@NonNull Builder<T> newUserLeafSetBuilder() {
130         return BUILDER_FACTORY.newUserLeafSetBuilder();
131     }
132 }