X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=yang%2Fyang-data-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fdata%2Fimpl%2Fschema%2FImmutableNodes.java;h=5a96515d13da23583dae2dcaee0ee40d7f65f3d9;hb=bb60da5fe2d1928defb46ed92b290cfff93dcd81;hp=754a87047bafd4b0fbc57a8e3876b8d5e7f512d9;hpb=a8308b1c391a78973a66394d28e6ec3dc4188cbd;p=yangtools.git diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java index 754a87047b..5a96515d13 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ImmutableNodes.java @@ -10,10 +10,9 @@ package org.opendaylight.yangtools.yang.data.impl.schema; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Iterator; -import java.util.Map.Entry; import java.util.Optional; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.ModifyAction; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; @@ -39,21 +38,22 @@ import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.SchemaContext; public final class ImmutableNodes { + // FIXME: YANGTOOLS-1074: we do not want this name private static final NodeIdentifier SCHEMACONTEXT_NAME = NodeIdentifier.create(SchemaContext.NAME); private ImmutableNodes() { - throw new UnsupportedOperationException("Utilities class should not be instantiated"); + // Hidden on purpose } - public static CollectionNodeBuilder mapNodeBuilder() { + public static @NonNull CollectionNodeBuilder mapNodeBuilder() { return ImmutableMapNodeBuilder.create(); } - public static CollectionNodeBuilder mapNodeBuilder(final QName name) { + public static @NonNull CollectionNodeBuilder mapNodeBuilder(final QName name) { return mapNodeBuilder(NodeIdentifier.create(name)); } - public static CollectionNodeBuilder mapNodeBuilder(final NodeIdentifier name) { + public static @NonNull CollectionNodeBuilder mapNodeBuilder(final NodeIdentifier name) { return ImmutableMapNodeBuilder.create().withNodeIdentifier(name); } @@ -63,26 +63,38 @@ public final class ImmutableNodes { * @param name QName which will be used as node identifier * @return An unordered Map node */ - public static MapNode mapNode(final QName name) { - return mapNodeBuilder(name).build(); + public static @NonNull MapNode mapNode(final QName name) { + return mapNode(NodeIdentifier.create(name)); } - private static CollectionNodeBuilder orderedMapNodeBuilder(final QName qname) { - return orderedMapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(qname)); + /** + * Create an immutable map node. + * + * @param name QName which will be used as node identifier + * @return An unordered Map node + */ + public static @NonNull MapNode mapNode(final NodeIdentifier name) { + return mapNodeBuilder(name).build(); } - private static CollectionNodeBuilder orderedMapNodeBuilder() { - return ImmutableOrderedMapNodeBuilder.create(); + /** + * Create immutable ordered map node. + * + * @param name QName which will be used as node identifier + * @return An ordered Map node + */ + public static @NonNull OrderedMapNode orderedMapNode(final QName name) { + return orderedMapNode(NodeIdentifier.create(name)); } /** * Create immutable ordered map node. * - * @param name QName which will be used as node identifier + * @param name Node identifier * @return An ordered Map node */ - public static OrderedMapNode orderedMapNode(final QName name) { - return orderedMapNodeBuilder(name).build(); + public static @NonNull OrderedMapNode orderedMapNode(final NodeIdentifier name) { + return ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(name).build(); } /** @@ -93,11 +105,8 @@ public final class ImmutableNodes { * @param Type of leaf node value * @return Leaf node with supplied identifier and value */ - public static LeafNode leafNode(final NodeIdentifier name, final T value) { - return ImmutableLeafNodeBuilder.create() - .withNodeIdentifier(name) - .withValue(value) - .build(); + public static @NonNull LeafNode leafNode(final NodeIdentifier name, final T value) { + return ImmutableLeafNodeBuilder.createNode(name, value); } /** @@ -108,22 +117,22 @@ public final class ImmutableNodes { * @param Type of leaf node value * @return Leaf node with supplied identifier and value */ - public static LeafNode leafNode(final QName name, final T value) { + public static @NonNull LeafNode leafNode(final QName name, final T value) { return leafNode(NodeIdentifier.create(name), value); } - public static DataContainerNodeBuilder mapEntryBuilder( + public static @NonNull DataContainerNodeBuilder mapEntryBuilder( final QName nodeName, final QName keyName, final Object keyValue) { return ImmutableMapEntryNodeBuilder.create() - .withNodeIdentifier(new NodeIdentifierWithPredicates(nodeName, keyName, keyValue)) + .withNodeIdentifier(NodeIdentifierWithPredicates.of(nodeName, keyName, keyValue)) .withChild(leafNode(keyName, keyValue)); } - public static DataContainerNodeBuilder mapEntryBuilder() { + public static @NonNull DataContainerNodeBuilder mapEntryBuilder() { return ImmutableMapEntryNodeBuilder.create(); } - public static MapEntryNode mapEntry(final QName nodeName,final QName keyName,final Object keyValue) { + public static @NonNull MapEntryNode mapEntry(final QName nodeName, final QName keyName, final Object keyValue) { return mapEntryBuilder(nodeName, keyName, keyValue).build(); } @@ -133,8 +142,18 @@ public final class ImmutableNodes { * @param name QName which will be used as node identifier * @return A container node */ - public static ContainerNode containerNode(final QName name) { - return ImmutableContainerNodeBuilder.create().withNodeIdentifier(NodeIdentifier.create(name)).build(); + public static @NonNull ContainerNode containerNode(final QName name) { + return containerNode(NodeIdentifier.create(name)); + } + + /** + * Create an immutable container node. + * + * @param name Node identifier + * @return A container node + */ + public static @NonNull ContainerNode containerNode(final NodeIdentifier name) { + return ImmutableContainerNodeBuilder.create().withNodeIdentifier(name).build(); } /** @@ -143,8 +162,18 @@ public final class ImmutableNodes { * @param name QName which will be used as node identifier * @return A choice node */ - public static ChoiceNode choiceNode(final QName name) { - return ImmutableChoiceNodeBuilder.create().withNodeIdentifier(NodeIdentifier.create(name)).build(); + public static @NonNull ChoiceNode choiceNode(final QName name) { + return choiceNode(NodeIdentifier.create(name)); + } + + /** + * Create an immutable choice node. + * + * @param name Node identifier + * @return A choice node + */ + public static @NonNull ChoiceNode choiceNode(final NodeIdentifier name) { + return ImmutableChoiceNodeBuilder.create().withNodeIdentifier(name).build(); } /** @@ -153,8 +182,18 @@ public final class ImmutableNodes { * @param name QName which will be used as node identifier * @return An unkeyed list node */ - public static UnkeyedListNode listNode(final QName name) { - return ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(NodeIdentifier.create(name)).build(); + public static @NonNull UnkeyedListNode listNode(final QName name) { + return listNode(NodeIdentifier.create(name)); + } + + /** + * Create an immutable list node. + * + * @param name Node identifier + * @return An unkeyed list node + */ + public static @NonNull UnkeyedListNode listNode(final NodeIdentifier name) { + return ImmutableUnkeyedListNodeBuilder.create().withNodeIdentifier(name).build(); } /** @@ -164,8 +203,9 @@ public final class ImmutableNodes { * @param id instance identifier to convert to node structure starting from root * @return serialized normalized node for provided instance Id */ - public static NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id) { - return fromInstanceId(ctx, id, Optional.empty(), Optional.empty()); + public static @NonNull NormalizedNode fromInstanceId(final SchemaContext ctx, + final YangInstanceIdentifier id) { + return fromInstanceId(ctx, id, Optional.empty()); } /** @@ -177,9 +217,9 @@ public final class ImmutableNodes { * instance identifier * @return serialized normalized node for provided instance Id with overridden last child. */ - public static NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, + public static @NonNull NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, final NormalizedNode deepestElement) { - return fromInstanceId(ctx, id, Optional.of(deepestElement), Optional.empty()); + return fromInstanceId(ctx, id, Optional.of(deepestElement)); } /** @@ -189,19 +229,17 @@ public final class ImmutableNodes { * @param id instance identifier to convert to node structure starting from root * @param deepestElement pre-built deepest child that will be inserted at the last path argument of provided * instance identifier - * @param operation modify operation attribute to be added to the deepest child. QName is the operation attribute - * key and ModifyAction is the value. * @return serialized normalized node for provided instance Id with (optionally) overridden last child * and (optionally) marked with specific operation attribute. */ - public static NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, - final Optional> deepestElement, final Optional> operation) { + public static @NonNull NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id, + final Optional> deepestElement) { final PathArgument topLevelElement; final InstanceIdToNodes instanceIdToNodes; final Iterator it = id.getPathArguments().iterator(); if (it.hasNext()) { topLevelElement = it.next(); - final DataSchemaNode dataChildByName = ctx.getDataChildByName(topLevelElement.getNodeType()); + final DataSchemaNode dataChildByName = ctx.dataChildByName(topLevelElement.getNodeType()); checkNotNull(dataChildByName, "Cannot find %s node in schema context. Instance identifier has to start from root", topLevelElement); instanceIdToNodes = InstanceIdToNodes.fromSchemaAndQNameChecked(ctx, topLevelElement.getNodeType()); @@ -210,6 +248,6 @@ public final class ImmutableNodes { instanceIdToNodes = InstanceIdToNodes.fromDataSchemaNode(ctx); } - return instanceIdToNodes.create(topLevelElement, it, deepestElement, operation); + return instanceIdToNodes.create(topLevelElement, it, deepestElement); } }