2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.spi.node;
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;
34 * Utilities for creating immutable implementations of various {@link NormalizedNode}s.
36 public final class ImmutableNodes {
37 private static final @NonNull ImmutableBuilderFactory BUILDER_FACTORY = new ImmutableBuilderFactory();
39 private ImmutableNodes() {
43 public static @NonNull BuilderFactory builderFactory() {
44 return BUILDER_FACTORY;
48 * Construct an immutable {@link LeafNode}.
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}
56 public static <T> @NonNull LeafNode<T> leafNode(final NodeIdentifier name, final T value) {
57 return ImmutableLeafNode.of(name, value);
61 * Construct an immutable {@link LeafNode}.
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}
69 public static <T> @NonNull LeafNode<T> leafNode(final QName name, final T value) {
70 return leafNode(NodeIdentifier.create(name), value);
73 public static <T> @NonNull LeafSetEntryNode<T> leafSetEntry(final NodeWithValue<T> name) {
74 return ImmutableLeafSetEntryNode.of(name);
77 public static <T> @NonNull LeafSetEntryNode<T> leafSetEntry(final QName name, final T value) {
78 return leafSetEntry(new NodeWithValue<>(name, value));
81 public static <T> AnydataNode.@NonNull Builder<T> newAnydataBuilder(final Class<T> objectModel) {
82 return BUILDER_FACTORY.newAnydataBuilder(objectModel);
85 public static <T> AnyxmlNode.@NonNull Builder<T, AnyxmlNode<T>> newAnyxmlBuilder(final Class<T> objectModel) {
86 return BUILDER_FACTORY.newAnyxmlBuilder(objectModel);
89 public static ChoiceNode.@NonNull Builder newChoiceBuilder() {
90 return BUILDER_FACTORY.newChoiceBuilder();
93 public static ContainerNode.@NonNull Builder newContainerBuilder() {
94 return BUILDER_FACTORY.newContainerBuilder();
97 public static MapEntryNode.@NonNull Builder newMapEntryBuilder() {
98 return BUILDER_FACTORY.newMapEntryBuilder();
101 public static SystemMapNode.@NonNull Builder newSystemMapBuilder() {
102 return BUILDER_FACTORY.newSystemMapBuilder();
105 public static UserMapNode.@NonNull Builder newUserMapBuilder() {
106 return BUILDER_FACTORY.newUserMapBuilder();
109 public static UnkeyedListEntryNode.@NonNull Builder newUnkeyedListEntryBuilder() {
110 return BUILDER_FACTORY.newUnkeyedListEntryBuilder();
113 public static UnkeyedListNode.@NonNull Builder newUnkeyedListBuilder() {
114 return BUILDER_FACTORY.newUnkeyedListBuilder();
117 public static <T> LeafNode.@NonNull Builder<T> newLeafBuilder() {
118 return BUILDER_FACTORY.newLeafBuilder();
121 public static <T> LeafSetEntryNode.@NonNull Builder<T> newLeafSetEntryBuilder() {
122 return BUILDER_FACTORY.newLeafSetEntryBuilder();
125 public static <T> SystemLeafSetNode.@NonNull Builder<T> newSystemLeafSetBuilder() {
126 return BUILDER_FACTORY.newSystemLeafSetBuilder();
129 public static <T> UserLeafSetNode.@NonNull Builder<T> newUserLeafSetBuilder() {
130 return BUILDER_FACTORY.newUserLeafSetBuilder();