@NonNullByDefault
final class JaxenDocument extends AbstractEffectiveModelContextProvider implements XPathDocument {
private final DataSchemaContextNode<?> schema;
- private final NormalizedNode<?, ?> root;
+ private final NormalizedNode root;
- JaxenDocument(final EffectiveModelContext context, final DataSchemaContextTree tree,
- final NormalizedNode<?, ?> root) {
+ JaxenDocument(final EffectiveModelContext context, final DataSchemaContextTree tree, final NormalizedNode root) {
super(context);
this.root = requireNonNull(root);
this.schema = requireNonNull(tree.getRoot().getChild(root.getIdentifier()));
}
@Override
- public NormalizedNode<?, ?> getRootNode() {
+ public NormalizedNode getRootNode() {
return root;
}
}
@Override
- public XPathDocument createDocument(final NormalizedNode<?, ?> documentRoot) {
+ public XPathDocument createDocument(final NormalizedNode documentRoot) {
return new JaxenDocument(context, tree, documentRoot);
}
}
import com.google.common.collect.ImmutableMap;
import java.util.ArrayList;
import java.util.List;
-import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.checkerframework.checker.regex.qual.Regex;
boolean inNodeIdentifierPart = false;
NormalizedNodeContext nodeCtx = this.currentNodeCtx;
- NormalizedNode<?, ?> node = null;
+ NormalizedNode node = null;
for (String pathComponent : pathComponents) {
final Matcher matcher = NODE_IDENTIFIER_PATTERN.matcher(pathComponent);
if (UP_ONE_LEVEL.equals(pathComponent)) {
} else if (matcher.matches()) {
inNodeIdentifierPart = true;
if (node != null && node instanceof DataContainerNode) {
- final DataContainerNode dcn = (DataContainerNode) node;
- final Optional<NormalizedNode<?, ?>> possibleChild = dcn.getChild(new NodeIdentifier(nextQName()));
- node = possibleChild.isPresent() ? possibleChild.get() : null;
+ node = ((DataContainerNode<?>) node).childByArg(new NodeIdentifier(nextQName()));
}
} else {
throw new IllegalArgumentException(String.format(
}
if (node != null && node instanceof LeafNode) {
- return node.getValue();
+ return node.body();
}
throw new IllegalArgumentException("Could not resolve current function path value.");
private static final long serialVersionUID = 1L;
private final @Nullable NormalizedNodeContext parent;
private final DataSchemaContextNode<?> schema;
- private final NormalizedNode<?, ?> node;
+ private final NormalizedNode node;
private NormalizedNodeContext(final ContextSupport contextSupport, final DataSchemaContextNode<?> schema,
- final NormalizedNode<?, ?> node, final @Nullable NormalizedNodeContext parent) {
+ final NormalizedNode node, final @Nullable NormalizedNodeContext parent) {
super(contextSupport);
this.schema = requireNonNull(schema);
this.node = requireNonNull(node);
return new NormalizedNodeContext(contextSupport, document.getSchema(), document.getRootNode(), null);
}
- NormalizedNode<?, ?> getNode() {
+ NormalizedNode getNode() {
return node;
}
return schema;
}
- NormalizedNodeContext createChild(final NormalizedNode<?, ?> input) {
+ NormalizedNodeContext createChild(final NormalizedNode input) {
DataSchemaContextNode<?> childSchema = schema.getChild(input.getIdentifier());
if (childSchema == null) {
/* This feels very much like a hack: but solves lookup of child nodes with predicates.
}
Optional<NormalizedNodeContext> findChild(final PathArgument arg) {
- return node instanceof DataContainerNode ? ((DataContainerNode<?>)node).getChild(arg).map(this::createChild)
- : Optional.empty();
+ return node instanceof DataContainerNode
+ ? ((DataContainerNode<?>)node).findChildByArg(arg).map(this::createChild) : Optional.empty();
}
Optional<NormalizedNodeContext> findDescendant(final YangInstanceIdentifier path) {
}
NormalizedNodeContext ctxWalk = this;
- NormalizedNode<?, ?> dataWalk = node;
+ NormalizedNode dataWalk = node;
for (PathArgument arg : path.getPathArguments()) {
checkArgument(dataWalk instanceof DataContainerNode, "Path %s refers beyond node %s", path, dataWalk);
- final Optional<DataContainerChild<? extends @Nullable PathArgument, ?>> optChild =
- ((DataContainerNode)dataWalk).getChild(arg);
- if (!optChild.isPresent()) {
+ dataWalk = ((DataContainerNode<?>)dataWalk).childByArg(arg);
+ if (dataWalk == null) {
return Optional.empty();
}
- dataWalk = optChild.get();
ctxWalk = createChild(dataWalk);
}
}
Iterator<NormalizedNodeContext> iterateChildren(final DataContainerNode<?> data) {
- return Iterators.transform(((DataContainerNode<?>) node).getValue().iterator(), this::createChild);
+ return Iterators.transform(((DataContainerNode<?>) node).body().iterator(), this::createChild);
}
@Nullable Iterator<NormalizedNodeContext> iterateChildrenNamed(final DataContainerNode<?> data, final QName qname) {
- final NodeIdentifier arg = new NodeIdentifier(qname);
- final Optional<DataContainerChild<? extends @Nullable PathArgument, ?>> maybeChild = data.getChild(arg);
- if (!maybeChild.isPresent()) {
+ final DataContainerChild child = data.childByArg(new NodeIdentifier(qname));
+ if (child == null) {
return null;
}
- final NormalizedNode<?, ?> child = maybeChild.get();
- final Collection<? extends NormalizedNode<?, ?>> collection;
-
+ final Collection<? extends NormalizedNode> collection;
// The child may be a structural node
if (child instanceof MapNode) {
- collection = ((MapNode)child).getValue();
+ collection = ((MapNode)child).body();
} else if (child instanceof LeafSetNode) {
- collection = ((LeafSetNode<?>)child).getValue();
+ collection = ((LeafSetNode<?>)child).body();
} else {
return Iterators.singletonIterator(createChild(child));
}
NormalizedNodeContext createContext(final YangInstanceIdentifier path) {
NormalizedNodeContext result = root;
for (PathArgument arg : path.getPathArguments()) {
- final Optional<NormalizedNode<?, ?>> node = NormalizedNodes.getDirectChild(result.getNode(), arg);
+ final Optional<NormalizedNode> node = NormalizedNodes.getDirectChild(result.getNode(), arg);
checkArgument(node.isPresent(), "Node %s has no child %s", result.getNode(), arg);
result = result.createChild(node.get());
}
return (NormalizedNodeContext) context;
}
- private static NormalizedNode<?, ?> contextNode(final Object context) {
+ private static NormalizedNode contextNode(final Object context) {
return cast(context).getNode();
}
- private QName resolveQName(final NormalizedNode<?, ?> node, final String prefix, final String localName) {
+ private QName resolveQName(final NormalizedNode node, final String prefix, final String localName) {
final QNameModule module;
if (prefix.isEmpty()) {
module = node.getNodeType().getModule();
@Override
public String getElementStringValue(final Object element) {
- final NormalizedNode<?, ?> node = contextNode(element);
+ final NormalizedNode node = contextNode(element);
if (node instanceof LeafNode || node instanceof LeafSetEntryNode) {
- final Object value = node.getValue();
+ final Object value = node.body();
// TODO: This is a rather poor approximation of what the codec infrastructure, but it should be sufficient
// to work for now. Tracking SchemaPath will mean we will need to wrap each NormalizedNode with a
@Override
public Iterator<NormalizedNodeContext> getChildAxisIterator(final Object contextNode) {
final NormalizedNodeContext ctx = cast(contextNode);
- final NormalizedNode<?, ?> node = ctx.getNode();
+ final NormalizedNode node = ctx.getNode();
return node instanceof DataContainerNode ? ctx.iterateChildren((DataContainerNode<?>) node) : null;
}
public Iterator<NormalizedNodeContext> getChildAxisIterator(final Object contextNode, final String localName,
final String namespacePrefix, final String namespaceURI) {
final NormalizedNodeContext ctx = cast(contextNode);
- final NormalizedNode<?, ?> node = ctx.getNode();
+ final NormalizedNode node = ctx.getNode();
return node instanceof DataContainerNode
? ctx.iterateChildrenNamed((DataContainerNode<?>)node, resolveQName(node, namespacePrefix, localName))
: null;
return false;
}
- final Object nodeValue = currentNodeContext.getNode().getValue();
+ final Object nodeValue = currentNodeContext.getNode().body();
if (!(nodeValue instanceof Set)) {
return false;
}
}
// deref(node-set nodes) function as per https://tools.ietf.org/html/rfc7950#section-10.3.1
- private static NormalizedNode<?, ?> deref(final Context context, final List<?> args) throws FunctionCallException {
+ private static NormalizedNode deref(final Context context, final List<?> args) throws FunctionCallException {
if (!args.isEmpty()) {
throw new FunctionCallException("deref() takes only one argument: node-set nodes.");
}
final NormalizedNodeContext currentNodeContext = verifyContext(context);
final TypedDataSchemaNode correspondingSchemaNode = getCorrespondingTypedSchemaNode(currentNodeContext);
- final Object nodeValue = currentNodeContext.getNode().getValue();
+ final Object nodeValue = currentNodeContext.getNode().body();
final TypeDefinition<?> type = correspondingSchemaNode.getType();
if (type instanceof InstanceIdentifierTypeDefinition) {
return nodeValue instanceof YangInstanceIdentifier
final SchemaContext schemaContext = getSchemaContext(currentNodeContext);
return correspondingSchemaNode.getType() instanceof IdentityrefTypeDefinition
- && currentNodeContext.getNode().getValue() instanceof QName ? new SimpleImmutableEntry<>(
+ && currentNodeContext.getNode().body() instanceof QName ? new SimpleImmutableEntry<>(
getIdentitySchemaNodeFromString((String) args.get(0), schemaContext, correspondingSchemaNode),
- getIdentitySchemaNodeFromQName((QName) currentNodeContext.getNode().getValue(), schemaContext))
+ getIdentitySchemaNodeFromQName((QName) currentNodeContext.getNode().body(), schemaContext))
: null;
}
return DOUBLE_NAN;
}
- final Object nodeValue = currentNodeContext.getNode().getValue();
+ final Object nodeValue = currentNodeContext.getNode().body();
if (!(nodeValue instanceof String)) {
return DOUBLE_NAN;
}
+ " identity schema node in the module %s.", identityQName, module));
}
- private static NormalizedNode<?, ?> getNodeReferencedByInstanceIdentifier(final YangInstanceIdentifier path,
+ private static NormalizedNode getNodeReferencedByInstanceIdentifier(final YangInstanceIdentifier path,
final NormalizedNodeContext currentNodeContext) {
final NormalizedNodeNavigator navigator = (NormalizedNodeNavigator) currentNodeContext.getNavigator();
- final NormalizedNode<?, ?> rootNode = navigator.getDocument().getRootNode();
+ final NormalizedNode rootNode = navigator.getDocument().getRootNode();
final List<PathArgument> pathArguments = path.getPathArguments();
if (pathArguments.get(0).getNodeType().equals(rootNode.getNodeType())) {
final List<PathArgument> relPath = pathArguments.subList(1, pathArguments.size());
- final Optional<NormalizedNode<?, ?>> possibleNode = NormalizedNodes.findNode(rootNode, relPath);
+ final Optional<NormalizedNode> possibleNode = NormalizedNodes.findNode(rootNode, relPath);
if (possibleNode.isPresent()) {
return possibleNode.get();
}
return null;
}
- private static NormalizedNode<?, ?> getNodeReferencedByLeafref(final PathExpression xpath,
+ private static NormalizedNode getNodeReferencedByLeafref(final PathExpression xpath,
final NormalizedNodeContext currentNodeContext, final SchemaContext schemaContext,
final TypedDataSchemaNode correspondingSchemaNode, final Object nodeValue) {
- final NormalizedNode<?, ?> referencedNode = xpath.isAbsolute() ? getNodeReferencedByAbsoluteLeafref(xpath,
+ final NormalizedNode referencedNode = xpath.isAbsolute() ? getNodeReferencedByAbsoluteLeafref(xpath,
currentNodeContext, schemaContext, correspondingSchemaNode) : getNodeReferencedByRelativeLeafref(xpath,
currentNodeContext, schemaContext, correspondingSchemaNode);
return getReferencedLeafSetEntryNode((LeafSetNode<?>) referencedNode, nodeValue);
}
- if (referencedNode instanceof LeafNode && referencedNode.getValue().equals(nodeValue)) {
+ if (referencedNode instanceof LeafNode && referencedNode.body().equals(nodeValue)) {
return referencedNode;
}
return null;
}
- private static NormalizedNode<?, ?> getNodeReferencedByAbsoluteLeafref(final PathExpression xpath,
+ private static NormalizedNode getNodeReferencedByAbsoluteLeafref(final PathExpression xpath,
final NormalizedNodeContext currentNodeContext, final SchemaContext schemaContext,
final TypedDataSchemaNode correspondingSchemaNode) {
final LeafrefXPathStringParsingPathArgumentBuilder builder = new LeafrefXPathStringParsingPathArgumentBuilder(
xpath.getOriginalString(), schemaContext, correspondingSchemaNode, currentNodeContext);
final List<PathArgument> pathArguments = builder.build();
final NormalizedNodeNavigator navigator = (NormalizedNodeNavigator) currentNodeContext.getNavigator();
- final NormalizedNode<?, ?> rootNode = navigator.getDocument().getRootNode();
+ final NormalizedNode rootNode = navigator.getDocument().getRootNode();
if (pathArguments.get(0).getNodeType().equals(rootNode.getNodeType())) {
final List<PathArgument> relPath = pathArguments.subList(1, pathArguments.size());
- final Optional<NormalizedNode<?, ?>> possibleNode = NormalizedNodes.findNode(rootNode, relPath);
+ final Optional<NormalizedNode> possibleNode = NormalizedNodes.findNode(rootNode, relPath);
if (possibleNode.isPresent()) {
return possibleNode.get();
}
return null;
}
- private static NormalizedNode<?, ?> getNodeReferencedByRelativeLeafref(final PathExpression xpath,
+ private static NormalizedNode getNodeReferencedByRelativeLeafref(final PathExpression xpath,
final NormalizedNodeContext currentNodeContext, final SchemaContext schemaContext,
final TypedDataSchemaNode correspondingSchemaNode) {
NormalizedNodeContext relativeNodeContext = currentNodeContext;
final LeafrefXPathStringParsingPathArgumentBuilder builder = new LeafrefXPathStringParsingPathArgumentBuilder(
xPathStringBuilder.toString(), schemaContext, correspondingSchemaNode, currentNodeContext);
final List<PathArgument> pathArguments = builder.build();
- final NormalizedNode<?, ?> relativeNode = relativeNodeContext.getNode();
- final Optional<NormalizedNode<?, ?>> possibleNode = NormalizedNodes.findNode(relativeNode, pathArguments);
- if (possibleNode.isPresent()) {
- return possibleNode.get();
- }
-
- return null;
+ final NormalizedNode relativeNode = relativeNodeContext.getNode();
+ return NormalizedNodes.findNode(relativeNode, pathArguments).orElse(null);
}
private static LeafSetEntryNode<?> getReferencedLeafSetEntryNode(final LeafSetNode<?> referencedNode,
final Object currentNodeValue) {
- for (final LeafSetEntryNode<?> entryNode : referencedNode.getValue()) {
- if (currentNodeValue.equals(entryNode.getValue())) {
+ for (final LeafSetEntryNode<?> entryNode : referencedNode.body()) {
+ if (currentNodeValue.equals(entryNode.body())) {
return entryNode;
}
}
*
* @return This document's root node.
*/
- @NonNull NormalizedNode<?, ?> getRootNode();
+ @NonNull NormalizedNode getRootNode();
}
*/
@Beta
@Deprecated
-public interface XPathNodesetResult
- extends XPathResult<Collection<Entry<YangInstanceIdentifier, NormalizedNode<?, ?>>>> {
+public interface XPathNodesetResult extends XPathResult<Collection<Entry<YangInstanceIdentifier, NormalizedNode>>> {
}
* @return A new {@link XPathDocument} on which queries may be executed.
* @throws IllegalArgumentException if the document root is not known to this schema context.
*/
- @NonNull XPathDocument createDocument(@NonNull NormalizedNode<?, ?> documentRoot);
+ @NonNull XPathDocument createDocument(@NonNull NormalizedNode documentRoot);
}
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.jaxen.api.XPathDocument;
import org.opendaylight.yangtools.yang.data.jaxen.api.XPathSchemaContext;
final LeafNode<?> ordinaryLeafNode = Builders.leafBuilder()
.withNodeIdentifier(new NodeIdentifier(ORDINARY_LEAF)).withValue("test-value").build();
- final MapNode myListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST))
+ final SystemMapNode myListNode = Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MY_LIST))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
NodeIdentifierWithPredicates.of(MY_LIST, FLAGS, keyLeafValue))
.withChild(ordinaryLeafNode).build()).build();
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.jaxen.api.XPathDocument;
import org.opendaylight.yangtools.yang.data.jaxen.api.XPathSchemaContext;
final XPathSchemaContext jaxenSchemaContext = jaxenSchemaContextFactory.createContext(schemaContext);
- final LeafSetNode<?> referencedLeafListNode = Builders.leafSetBuilder().withNodeIdentifier(
- new NodeIdentifier(REFERENCED_LEAFLIST))
+ final SystemLeafSetNode<?> referencedLeafListNode = Builders.leafSetBuilder()
+ .withNodeIdentifier(new NodeIdentifier(REFERENCED_LEAFLIST))
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
new NodeWithValue<>(REFERENCED_LEAFLIST, "referenced-node-entry-value-a"))
.withValue("referenced-node-entry-value-a").build())
.getFunction(null, null, "deref");
Object derefResult = derefFunction.call(normalizedNodeContext, ImmutableList.of());
assertNotNull(derefResult);
- assertTrue(derefResult instanceof NormalizedNode<?, ?>);
+ assertTrue(derefResult instanceof NormalizedNode);
- final LeafSetEntryNode<?> referencedLeafListNodeEntry = referencedLeafListNode.getChild(
- new NodeWithValue<>(REFERENCED_LEAFLIST, "referenced-node-entry-value-b")).get();
+ final LeafSetEntryNode<?> referencedLeafListNodeEntry = referencedLeafListNode.childByArg(
+ new NodeWithValue<>(REFERENCED_LEAFLIST, "referenced-node-entry-value-b"));
assertSame(referencedLeafListNodeEntry, derefResult);
}
final LeafNode<?> iidLeafNode = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(IID_LEAF))
.withValue(iidPath).build();
- final MapNode myListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST))
+ final SystemMapNode myListNode = Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MY_LIST))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
NodeIdentifierWithPredicates.of(MY_LIST, keyValues))
.withChild(iidLeafNode)
final LeafNode<?> ordinaryLeafBNode = Builders.leafBuilder().withNodeIdentifier(
new NodeIdentifier(ORDINARY_LEAF_B)).withValue("value-b").build();
- final MapNode myListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST))
+ final SystemMapNode myListNode = Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MY_LIST))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
NodeIdentifierWithPredicates.of(MY_LIST, keyValues))
.withChild(referencedLeafNode).build())
}
// variant for a leafref that references a leaf-list
- private static ContainerNode buildMyContainerNodeForLeafrefTest(final LeafSetNode<?> referencedLeafListNode) {
+ private static ContainerNode buildMyContainerNodeForLeafrefTest(final SystemLeafSetNode<?> referencedLeafListNode) {
final LeafNode<?> leafListLeafrefNode = Builders.leafBuilder().withNodeIdentifier(
new NodeIdentifier(LEAFLIST_LEAFREF_LEAF)).withValue("referenced-node-entry-value-b").build();
.withChild(ordinaryLeafBNode).build();
final Map<QName, Object> keyValues = ImmutableMap.of(KEY_LEAF_A, "value-a", KEY_LEAF_B, "value-b");
-
- final MapNode myListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST))
+ final SystemMapNode myListNode = Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MY_LIST))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
NodeIdentifierWithPredicates.of(MY_LIST, keyValues))
.withChild(referencedLeafListNode).build())
.build();
- final ContainerNode myContainerNode = Builders.containerBuilder().withNodeIdentifier(
- new NodeIdentifier(MY_CONTAINER))
+ final ContainerNode myContainerNode = Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MY_CONTAINER))
.withChild(myListNode)
.withChild(myInnerContainerNode).build();
return myContainerNode;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.jaxen.api.XPathDocument;
import org.opendaylight.yangtools.yang.data.jaxen.api.XPathSchemaContext;
final LeafNode<?> idrefLeafNode = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(IDREF_LEAF))
.withValue(idrefLeafValue).build();
- final MapNode myListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST))
+ final SystemMapNode myListNode = Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MY_LIST))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
NodeIdentifierWithPredicates.of(MY_LIST, KEY_LEAF, "key-value"))
.withChild(idrefLeafNode).build()).build();
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.jaxen.api.XPathDocument;
import org.opendaylight.yangtools.yang.data.jaxen.api.XPathSchemaContext;
final LeafNode<?> ordinaryLeafNode = Builders.leafBuilder()
.withNodeIdentifier(new NodeIdentifier(ORDINARY_LEAF)).withValue("test-value").build();
- final MapNode alarmListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(ALARM))
+ final SystemMapNode alarmListNode = Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(ALARM))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
NodeIdentifierWithPredicates.of(ALARM, SEVERITY, keyLeafValue))
.withChild(ordinaryLeafNode).build()).build();
assertTrue(xpathResult instanceof XPathNodesetResult);
XPathNodesetResult nodeset = (XPathNodesetResult) xpathResult;
- Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = nodeset.getValue().iterator().next();
+ Entry<YangInstanceIdentifier, NormalizedNode> entry = nodeset.getValue().iterator().next();
assertNotNull(entry);
- assertEquals("three", entry.getValue().getValue());
+ assertEquals("three", entry.getValue().body());
convertNctx = new ConverterNamespaceContext(createPrefixes());
navigator = new NormalizedNodeNavigator(convertNctx, (JaxenDocument) xpathDocument);
assertTrue(xpathResult instanceof XPathNodesetResult);
XPathNodesetResult nodeset = (XPathNodesetResult) xpathResult;
- Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> entry = nodeset.getValue().iterator().next();
+ Entry<YangInstanceIdentifier, NormalizedNode> entry = nodeset.getValue().iterator().next();
assertNotNull(entry);
- assertEquals("two", entry.getValue().getValue());
+ assertEquals("two", entry.getValue().body());
}
@Test(expected = VerifyException.class)
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
*
* @return A test document instance.
*/
- public static NormalizedNode<?, ?> createNormalizedNodes() {
+ public static ContainerNode createNormalizedNodes() {
return ImmutableContainerNodeBuilder
.create()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(ROOT_QNAME))
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
private static final MapNode TEN_ITEM_INNER_LIST = initInnerListItems(10);
private static MapNode initInnerListItems(final int count) {
- final CollectionNodeBuilder<MapEntryNode, MapNode> mapEntryBuilder = ImmutableNodes
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapEntryBuilder = ImmutableNodes
.mapNodeBuilder(BenchmarkModel.INNER_LIST);
for (int i = 0; i < count; ++i) {
return mapEntryBuilder.build();
}
- private static final NormalizedNode<?, ?>[] OUTER_LIST_ONE_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_100K,
+ private static final NormalizedNode[] OUTER_LIST_ONE_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_100K,
ONE_ITEM_INNER_LIST);
- private static final NormalizedNode<?, ?>[] OUTER_LIST_TWO_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_50K,
+ private static final NormalizedNode[] OUTER_LIST_TWO_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_50K,
TWO_ITEM_INNER_LIST);
- private static final NormalizedNode<?, ?>[] OUTER_LIST_TEN_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_10K,
+ private static final NormalizedNode[] OUTER_LIST_TEN_ITEM_INNER_LIST = initOuterListItems(OUTER_LIST_10K,
TEN_ITEM_INNER_LIST);
- private static NormalizedNode<?,?>[] initOuterListItems(final int outerListItemsCount, final MapNode innerList) {
+ private static NormalizedNode[] initOuterListItems(final int outerListItemsCount, final MapNode innerList) {
return Arrays.stream(OUTER_LIST_IDS).limit(outerListItemsCount)
.map(id -> ImmutableNodes.mapEntryBuilder().withNodeIdentifier(id).withChild(innerList).build())
.collect(Collectors.toList()).toArray(new NormalizedNode[0]);
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.util;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableMap;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+import org.eclipse.jdt.annotation.NonNull;
+import org.gaul.modernizer_maven_annotations.SuppressModernizer;
+import org.opendaylight.yangtools.concepts.Immutable;
+
+/**
+ * An unmodifiable view over a {@link Map}. Unlike the view returned via {@link Collections#unmodifiableMap(Map)}, this
+ * class checks its argument to ensure multiple encapsulation does not occur.
+ *
+ * <p>This class checks the argument so it prevents multiple encapsulation. Subclasses of
+ * {@link ImmutableMap} are also recognized and not encapsulated.
+ *
+ * @param <K> the type of keys maintained by this map
+ * @param <V> the type of mapped values
+ */
+@Beta
+public final class UnmodifiableMap<K, V> implements Map<K, V>, Immutable {
+ private final @NonNull Map<K, V> delegate;
+
+ private UnmodifiableMap(@NonNull final Map<K, V> delegate) {
+ this.delegate = requireNonNull(delegate);
+ }
+
+ /**
+ * Create an unmodifiable view of the target {@link Map}. If the map is known to be unmodifiable, that same instance
+ * is returned. Otherwise an unmodifiable view of the map will be returned.
+ *
+ * @param map Target map
+ * @return An unmodifiable view of the map
+ * @throws NullPointerException if {@code map} is null
+ */
+ @SuppressModernizer
+ public static <K, V> @NonNull Map<K, V> of(final @NonNull Map<K, V> map) {
+ return map instanceof Immutable || map instanceof ImmutableMap || Collections.EMPTY_MAP == map
+ ? map : new UnmodifiableMap<>(map);
+ }
+
+ @Override
+ public int size() {
+ return delegate.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return delegate.isEmpty();
+ }
+
+ @Override
+ public boolean containsKey(final Object key) {
+ return delegate.containsKey(key);
+ }
+
+ @Override
+ public boolean containsValue(final Object value) {
+ return delegate.containsValue(value);
+ }
+
+ @Override
+ public V get(final Object key) {
+ return delegate.get(key);
+ }
+
+ @Override
+ public Set<K> keySet() {
+ return Collections.unmodifiableSet(delegate.keySet());
+ }
+
+ @Override
+ public Collection<V> values() {
+ return Collections.unmodifiableCollection(delegate.values());
+ }
+
+ @Override
+ public Set<Entry<K, V>> entrySet() {
+ return Collections.unmodifiableSet(delegate.entrySet());
+ }
+
+ @Override
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return obj == this || obj instanceof Map && delegate.equals(obj);
+ }
+
+ @Override
+ public String toString() {
+ return delegate.toString();
+ }
+
+ @Override
+ public V put(final K key, final V value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public V remove(final Object key) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ @SuppressWarnings("checkstyle:parameterName")
+ public void putAll(final Map<? extends K, ? extends V> m) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void clear() {
+ throw new UnsupportedOperationException();
+ }
+}
/**
* RFC7952 metadata counterpart to a {@link NormalizedNode}. This interface is meant to be used as a companion to
* a NormalizedNode instance, hence it does not support iterating over its structure like it is possible with
- * {@link NormalizedNode#getValue()}. Children may be inquired through {@link #getChildren()}.
+ * {@link NormalizedNode#body()}. Children may be inquired through {@link #getChildren()}.
*
* <p>
* This model of metadata <em>does not</em> have the RFC7952 restriction on metadata attachment to {@code list}s and
private final NormalizedMetadata metadata;
public ImmutableMetadataNormalizedAnydata(final EffectiveModelContext schemaContext,
- final DataSchemaNode contextNode, final NormalizedNode<?, ?> data, final NormalizedMetadata metadata) {
+ final DataSchemaNode contextNode, final NormalizedNode data, final NormalizedMetadata metadata) {
super(schemaContext, contextNode, data);
this.metadata = requireNonNull(metadata);
}
public static ImmutableNormalizedAnydata ofOptional(final EffectiveModelContext schemaContext,
- final DataSchemaNode contextNode, final NormalizedNode<?, ?> data,
+ final DataSchemaNode contextNode, final NormalizedNode data,
final Optional<NormalizedMetadata> metadata) {
return metadata.isPresent()
? new ImmutableMetadataNormalizedAnydata(schemaContext, contextNode, data, metadata.get())
* @throws IllegalArgumentException if metadata does not match data
* @throws IOException when thrown from the backing writer.
*/
- public @NonNull NormalizedMetadataWriter write(final NormalizedNode<?, ?> data, final NormalizedMetadata metadata)
+ public @NonNull NormalizedMetadataWriter write(final NormalizedNode data, final NormalizedMetadata metadata)
throws IOException {
final PathArgument dataId = data.getIdentifier();
final PathArgument metaId = metadata.getIdentifier();
* @throws IOException if an underlying error occurs
* @throws NullPointerException if any of the arguments is null
*/
- NormalizedNode<?, ?> normalizeTo(EffectiveModelContext schemaContext) throws IOException;
+ NormalizedNode normalizeTo(EffectiveModelContext schemaContext) throws IOException;
}
package org.opendaylight.yangtools.rfc8528.data.api;
import com.google.common.annotations.Beta;
-import java.util.Collection;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MixinNode;
* handle them, provided they get enough support from MountPointContext.
*/
@Beta
-public interface MountPointNode extends MixinNode, DataContainerNode<MountPointIdentifier>,
- DataContainerChild<MountPointIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> {
+public interface MountPointNode extends DataContainerNode<MountPointIdentifier>, DataContainerChild, MixinNode {
@Override
+ @Deprecated
default QName getNodeType() {
return getIdentifier().getLabel();
}
continue;
}
- final NormalizedNode<?, ?> libData;
+ final NormalizedNode libData;
try {
libData = entry.getValue().normalizeTo(optLibContext.get());
} catch (IOException e) {
return new EmptyMountPointContext(schemaContext);
}
- final NormalizedNode<?, ?> mountData;
+ final NormalizedNode mountData;
try {
mountData = schemaMounts.normalizeTo(schemaContext);
} catch (IOException e) {
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import java.util.Iterator;
-import java.util.Optional;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable;
final ContainerNode mountData) {
checkArgument(SCHEMA_MOUNTS.equals(mountData.getIdentifier()), "Unexpected top-level container %s", mountData);
- final Optional<DataContainerChild<?, ?>> optMountPoint = mountData.getChild(MOUNT_POINT);
- if (optMountPoint.isEmpty()) {
+ final DataContainerChild mountPoint = mountData.childByArg(MOUNT_POINT);
+ if (mountPoint == null) {
LOG.debug("mount-point list not present in {}", mountData);
return new EmptyMountPointContext(schemaContext);
}
-
- final DataContainerChild<?, ?> mountPoint = optMountPoint.get();
checkArgument(mountPoint instanceof MapNode, "mount-point list %s is not a MapNode", mountPoint);
- return new ImmutableMountPointContext(schemaContext, ((MapNode) mountPoint).getValue().stream().map(entry -> {
- final String moduleName = entry.getChild(MODULE).map(mod -> {
+ return new ImmutableMountPointContext(schemaContext, ((MapNode) mountPoint).body().stream().map(entry -> {
+ final String moduleName = entry.findChildByArg(MODULE).map(mod -> {
checkArgument(mod instanceof LeafNode, "Unexpected module leaf %s", mod);
- final Object value = mod.getValue();
+ final Object value = mod.body();
checkArgument(value instanceof String, "Unexpected module leaf value %s", value);
return (String) value;
}).orElseThrow(() -> new IllegalArgumentException("Mount module missing in " + entry));
final QNameModule module = it.next().getQNameModule();
return new MountPointDefinition(
- MountPointIdentifier.of(QName.create(module, entry.getChild(LABEL).map(lbl -> {
+ MountPointIdentifier.of(QName.create(module, entry.findChildByArg(LABEL).map(lbl -> {
checkArgument(lbl instanceof LeafNode, "Unexpected label leaf %s", lbl);
- final Object value = lbl.getValue();
+ final Object value = lbl.body();
checkArgument(value instanceof String, "Unexpected label leaf value %s", value);
return (String) value;
}).orElseThrow(() -> new IllegalArgumentException("Mount module missing in " + entry)))),
- entry.getChild(CONFIG).map(cfg -> {
+ entry.findChildByArg(CONFIG).map(cfg -> {
checkArgument(cfg instanceof LeafNode, "Unexpected config leaf %s", cfg);
- final Object value = cfg.getValue();
+ final Object value = cfg.body();
checkArgument(value instanceof Boolean, "Unexpected config leaf value %s", cfg);
return (Boolean) value;
}).orElse(Boolean.TRUE),
- getSchema(entry.getChild(SCHEMA_REF)
+ getSchema(entry.findChildByArg(SCHEMA_REF)
.orElseThrow(() -> new IllegalArgumentException("Missing schema-ref choice in " + entry))));
}).collect(Collectors.toList()), this::createContextFactory);
}
- private static ImmutableSet<String> getSchema(final DataContainerChild<?, ?> child) {
+ private static ImmutableSet<String> getSchema(final DataContainerChild child) {
checkArgument(child instanceof ChoiceNode, "Unexpected schema-ref choice %s", child);
final ChoiceNode schemaRef = (ChoiceNode) child;
- return schemaRef.getChild(SHARED_SCHEMA).map(sharedSchema -> {
+ return schemaRef.findChildByArg(SHARED_SCHEMA).map(sharedSchema -> {
checkArgument(sharedSchema instanceof ContainerNode, "Unexpected shared-schema container %s", sharedSchema);
- return ((ContainerNode) sharedSchema).getChild(PARENT_REFERENCE)
+ return ((ContainerNode) sharedSchema).findChildByArg(PARENT_REFERENCE)
// FIXME: 7.0.0: parse XPaths. Do we have enough context for that?
.map(parentRef -> ImmutableSet.<String>of())
.orElseGet(ImmutableSet::of);
}).orElseGet(() -> {
- checkArgument(schemaRef.getChild(INLINE).isPresent(), "Unhandled schema-ref type in %s", schemaRef);
+ checkArgument(schemaRef.findChildByArg(INLINE).isPresent(), "Unhandled schema-ref type in %s", schemaRef);
return ImmutableSet.of();
});
}
import com.google.common.annotations.Beta;
import com.google.common.base.MoreObjects.ToStringHelper;
import java.util.Collection;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable;
+import org.opendaylight.yangtools.concepts.AbstractIdentifiable;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext;
import org.opendaylight.yangtools.rfc8528.data.api.MountPointIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
@Beta
-public final class ImmutableMountPointNode extends AbstractSimpleIdentifiable<MountPointIdentifier>
+public final class ImmutableMountPointNode extends AbstractIdentifiable<PathArgument, MountPointIdentifier>
implements MountPointNode, Immutable {
-
private final @NonNull MountPointContext mountCtx;
private final @NonNull ContainerNode delegate;
}
@Override
- public Collection<DataContainerChild<? extends PathArgument, ?>> getValue() {
- return delegate.getValue();
+ public Collection<DataContainerChild> body() {
+ return delegate.body();
}
@Override
- public Optional<DataContainerChild<? extends PathArgument, ?>> getChild(final PathArgument child) {
- return delegate.getChild(child);
+ public DataContainerChild childByArg(final PathArgument child) {
+ return delegate.childByArg(child);
}
@Override
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.rfc8528.data.api.MountPointNode;
import org.opendaylight.yangtools.rfc8528.data.api.StreamWriterMountPointExtension;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
void writeMountPoint(final MountPointNode node) throws IOException {
try (MountPointNormalizedNodeWriter writer = forStreamWriter(mountWriter.startMountPoint(
node.getIdentifier(), node.getMountPointContext()))) {
- for (DataContainerChild<? extends PathArgument, ?> child : node.getValue()) {
+ for (DataContainerChild child : node.body()) {
writer.write(child);
}
}
}
@Override
- protected final boolean wasProcessedAsCompositeNode(final NormalizedNode<?, ?> node) throws IOException {
+ protected final boolean wasProcessedAsCompositeNode(final NormalizedNode node) throws IOException {
if (node instanceof MountPointNode) {
writeMountPoint((MountPointNode) node);
return true;
* @param <V> Value type, uniquely identifying the object model used for values
*/
@Beta
-public interface AnydataNode<V> extends ForeignDataNode<NodeIdentifier, V> {
-
+public interface AnydataNode<V> extends ForeignDataNode<V> {
+ @Override
+ NodeIdentifier getIdentifier();
}
* @param <V> Value type, uniquely identifying the object model used for values
*/
@Beta
-public interface AnyxmlNode<V> extends ForeignDataNode<NodeIdentifier, V> {
-
+public interface AnyxmlNode<V> extends ForeignDataNode<V> {
+ @Override
+ NodeIdentifier getIdentifier();
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import java.util.Collection;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
/**
* <p>
* Augmentation node MUST NOT be direct child of other augmentation node.
*/
-public interface AugmentationNode extends MixinNode, DataContainerNode<AugmentationIdentifier>,
- DataContainerChild<AugmentationIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> {
-
+public interface AugmentationNode extends DataContainerNode<AugmentationIdentifier>, DataContainerChild, MixinNode {
/**
* Gets identifier of augmentation node. Returned identifier of augmentation node contains all possible
* direct child QNames.
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import java.util.Collection;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
/**
* Node representing data instance of <code>choice</code>.
* {@link org.opendaylight.yangtools.yang.model.api.CaseSchemaNode}, which are retrieved via
* {@link org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode#getCases()}.
*/
-public interface ChoiceNode extends MixinNode, DataContainerNode<NodeIdentifier>,
- DataContainerChild<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> {
+public interface ChoiceNode extends MixinNode, DataContainerNode<NodeIdentifier>, DataContainerChild {
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import java.util.Collection;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
/**
* Data subtree with cardinality 0..1 in the context of parent node.
* Schema of this node is described by instance of
* {@link org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode}.
*/
-public interface ContainerNode extends DataContainerNode<NodeIdentifier>,
- DataContainerChild<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> {
+public interface ContainerNode extends DataContainerNode<NodeIdentifier>, DataContainerChild {
}
*/
public interface DOMSourceAnyxmlNode extends AnyxmlNode<DOMSource> {
@Override
- default Class<DOMSource> getValueObjectModel() {
+ default Class<DOMSource> bodyObjectModel() {
return DOMSource.class;
}
/**
- * Return value represented as a DOMSource. Returned source contains top level element
- * that duplicates the anyxml node.
+ * {@inheritDoc}
*
- * @return anyxml node value represented as DOMSource.
+ * <p>
+ * Returned value is a DOMSource representation. Returned source contains top level element that duplicates the
+ * anyxml node.
*/
@Override
- DOMSource getValue();
+ DOMSource body();
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-
/**
* Marker interface for direct children of {@link DataContainerNode}.
*
* This interface should not be implemented directly, but rather using one of its subinterfaces:
*
* <ul>
- * <li>{@link LeafNode}
- * <li>{@link ContainerNode}
- * <li>{@link ChoiceNode}
- * <li>{@link MapNode}
- * <li>{@link AugmentationNode}
+ * <li>{@link AugmentationNode}</li>
+ * <li>{@link ChoiceNode}</li>
+ * <li>{@link ContainerNode}</li>
+ * <li>{@link ForeignDataNode}</li>
+ * <li>{@link LeafNode}</li>
+ * <li>{@link LeafSetNode}</li>
+ * <li>{@link MapNode} and its specializations</li>
+ * <li>{@link UnkeyedListNode}</li>
* </ul>
- *
- * @param <K> Path Argument Type which is used to identify node
- * @param <V> Value type
*/
-public interface DataContainerChild<K extends PathArgument,V> extends NormalizedNode<K, V> {
- @Override
- K getIdentifier();
+public interface DataContainerChild extends NormalizedNode {
+
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import java.util.Collection;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
/**
* Abstract node which does not have value but contains valid {@link DataContainerChild} nodes. Schema of this node is
* described by instance of {@link org.opendaylight.yangtools.yang.model.api.DataNodeContainer}.
*
+ * <p>
+ * <b>NOTE:</b>
+ * All implementations of this interface are assumed to be {@link OrderingAware.System}, i.e. order-independent.
+ *
* <h2>Implementation notes</h2>
* This interface should not be implemented directly, but rather implementing one of it's subclasses
* <ul>
- * <li>{@link ContainerNode}
- * <li>{@link MapEntryNode}
- * <li>{@link UnkeyedListEntryNode}
- * <li>{@link ChoiceNode}
- * <li>{@link AugmentationNode}
+ * <li>{@link AugmentationNode}</li>
+ * <li>{@link ChoiceNode}</li>
+ * <li>{@link ContainerNode}</li>
+ * <li>{@link MapEntryNode} and its specializations</li>
+ * <li>{@link UnkeyedListEntryNode}</li>
* </ul>
*
- * @param <K> {@link PathArgument} which identifies instance of {@link DataContainerNode}
+ * @param <K> {@link PathArgument} which identifies this instance {@link DataContainerNode}
*/
-public interface DataContainerNode<K extends PathArgument> extends
- NormalizedNodeContainer<K, PathArgument, DataContainerChild<? extends PathArgument, ?>> {
- /**
- * Returns iteration of all child nodes. Order of returned child nodes may be defined by subinterfaces.
- *
- * <p>
- * <b>Implementation Notes:</b>
- * All nodes returned in this iterable, MUST also be accessible via {@link #getChild(PathArgument)} using their
- * associated identifier.
- *
- * @return Iteration of all child nodes
- */
+public interface DataContainerNode<K extends PathArgument>
+ extends DistinctNodeContainer<K, PathArgument, DataContainerChild>, OrderingAware.System {
+ @Override
+ int hashCode();
+
@Override
- Collection<DataContainerChild<? extends PathArgument, ?>> getValue();
+ boolean equals(Object obj);
}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.api.schema;
+
+import java.util.Collection;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+
+/**
+ * A {@link NormalizedNodeContainer} which contains directly-addressable children. It
+ *
+ * <p>
+ * NormalizedNodeContainer does not have a value, but it has a child nodes. Definition of possible and valid child nodes
+ * is introduced in subclasses of this interface.
+ *
+ * <p>
+ * This interface should not be used directly, but rather use of of derived subclasses such as
+ * {@link DataContainerNode}, {@link MapNode}, {@link LeafSetNode}.
+ *
+ * @param <I> Path argument type
+ * @param <K> Child path argument type
+ * @param <V> Child Node type
+ */
+public interface DistinctNodeContainer<I extends PathArgument, K extends PathArgument, V extends NormalizedNode>
+ extends NormalizedNodeContainer<I, V> {
+ /**
+ * {@inheritDoc}
+ *
+ * <p>
+ * All nodes returned in this iterable, MUST also be accessible via {@link #childByArg(PathArgument)} using their
+ * associated identifier.
+ *
+ * @return Iteration of all child nodes
+ */
+ @Override
+ Collection<@NonNull V> body();
+
+ /**
+ * Returns a child node identified by provided key.
+ *
+ * @param key Path argument identifying child node
+ * @return Matching child node, or null if no matching child exists
+ * @throws NullPointerException if {@code key} is null
+ */
+ @Nullable V childByArg(K key);
+
+ /**
+ * Attempts to find a child node identified by provided key.
+ *
+ * @param key Path argument identifying child node
+ * @return Optional with child node if child exists. {@link Optional#empty()} if child does not exist
+ * @throws NullPointerException if {@code key} is null
+ */
+ default Optional<V> findChildByArg(final K key) {
+ return Optional.ofNullable(childByArg(key));
+ }
+}
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
final class DuplicateFinder {
- private final Map<NormalizedNode<?, ?>, DuplicateEntry> identities = new IdentityHashMap<>();
- private final Map<NormalizedNode<?, ?>, DuplicateEntry> duplicates = new HashMap<>();
+ private final Map<NormalizedNode, DuplicateEntry> identities = new IdentityHashMap<>();
+ private final Map<NormalizedNode, DuplicateEntry> duplicates = new HashMap<>();
private DuplicateFinder() {
// Hidden on purpose
}
- private void findDuplicates(final YangInstanceIdentifier path, final NormalizedNode<?, ?> node) {
+ private void findDuplicates(final YangInstanceIdentifier path, final NormalizedNode node) {
final DuplicateEntry i = identities.get(node);
if (i == null) {
final DuplicateEntry d = duplicates.get(node);
d.addDuplicate(path);
}
- if (node instanceof NormalizedNodeContainer<?, ?, ?>) {
- final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) node;
+ if (node instanceof NormalizedNodeContainer<?, ?>) {
+ final NormalizedNodeContainer<?, ?> container = (NormalizedNodeContainer<?, ?>) node;
- for (NormalizedNode<?, ?> c : container.getValue()) {
+ for (NormalizedNode c : container.body()) {
findDuplicates(path.node(c.getIdentifier()), c);
}
}
* @param node Root node, may not be null.
* @return List of entries
*/
- static Map<NormalizedNode<?, ?>, DuplicateEntry> findDuplicates(final NormalizedNode<?, ?> node) {
+ static Map<NormalizedNode, DuplicateEntry> findDuplicates(final NormalizedNode node) {
final DuplicateFinder finder = new DuplicateFinder();
finder.findDuplicates(YangInstanceIdentifier.empty(), node);
return finder.identities;
import com.google.common.annotations.Beta;
import javax.xml.transform.dom.DOMSource;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
/**
* A NormalizedNode holding a value in some foreign object model. The object model is identified by a single class,
* <p>
* This interface should not be implemented directly, but rather further specialized, like {@link AnyxmlNode}.
*
- * @param <K> Local identifier of node
* @param <V> Value type, uniquely identifying the object model used for values
*/
@Beta
-public interface ForeignDataNode<K extends PathArgument, V> extends DataContainerChild<K, V> {
+public interface ForeignDataNode<V> extends DataContainerChild {
/**
- * Return the object model class, which identifies it. For example {@link DOMSourceAnyxmlNode}
- * uses {@link DOMSource} as its value object model.
+ * {@inheritDoc}
+ *
+ * <p>
+ * The body follows the object model exposed through {@link #bodyObjectModel()}
+ */
+ @Override
+ V body();
+
+ /**
+ * Return the object model class, which identifies it. For example {@link DOMSourceAnyxmlNode} uses
+ * {@link DOMSource} as its value object model.
*
* @return Object model class
*/
- @NonNull Class<V> getValueObjectModel();
+ @NonNull Class<V> bodyObjectModel();
}
*
* @param <T> Value type
*/
-public interface LeafNode<T> extends DataContainerChild<NodeIdentifier, T>, ValueNode<NodeIdentifier, T> {
- /**
- * Returns value of this leaf node.
- *
- * @return Returned value of this leaf node. Value SHOULD meet criteria defined by schema.
- */
+public interface LeafNode<T> extends ValueNode<T>, DataContainerChild {
@Override
- T getValue();
+ NodeIdentifier getIdentifier();
}
*
* @param <T> Value type
*/
-public interface LeafSetEntryNode<T> extends NormalizedNode<NodeWithValue, T>, ValueNode<NodeWithValue, T> {
+public interface LeafSetEntryNode<T> extends ValueNode<T> {
/**
- * Returns {@link NodeWithValue} which identifies this leaf set entry. Returned {@link NodeWithValue} contains same
- * value as this node.
+ * {@inheritDoc}
*
+ * <p>
* <b>Implementation note</b>
* Invocation of {@link NodeWithValue#getValue()} on returned instance of {@link NodeWithValue} must return the
- * same value as invocation of {@link #getValue()}, such as following condition is always met:
- * {@code true == this.getIdentifier().getValue().equals(this.getValue())}.
- *
- * @return {@link NodeWithValue} which identifies this leaf set entry.
+ * same value as invocation of {@code #body()}, such as following condition is always met:
+ * {@code true == this.getIdentifier().getValue().equals(this.body())}.
*/
@Override
- NodeWithValue getIdentifier();
+ NodeWithValue<T> getIdentifier();
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import java.util.Collection;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
*
* @param <T> Type of leaf node values.
*/
-public interface LeafSetNode<T> extends MixinNode, DataContainerChild<NodeIdentifier, Collection<LeafSetEntryNode<T>>>,
- NormalizedNodeContainer<NodeIdentifier, NodeWithValue, LeafSetEntryNode<T>> {
+public interface LeafSetNode<T>
+ extends DistinctNodeContainer<NodeIdentifier, NodeWithValue<?>, LeafSetEntryNode<T>>, DataContainerChild,
+ MixinNode {
}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
/**
* Contents of identifier is defined by <code>key</code> (
* {@link org.opendaylight.yangtools.yang.model.api.ListSchemaNode#getKeyDefinition()}
* ) statement in YANG schema for associated list item and child {@link LeafNode}s
- * values with {@link org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier}
- * as defined in the schema.
+ * values with {@link NodeIdentifier} as defined in the schema.
*
* @return identifier of this node in the context of parent node
*/
*/
package org.opendaylight.yangtools.yang.data.api.schema;
+import com.google.common.annotations.Beta;
import java.util.Collection;
+import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
/**
- * Containment node, which contains {@link MapEntryNode} of the same type, which may
- * be quickly retrieved using key.
+ * Containment node, which contains {@link MapEntryNode} of the same type, which may be quickly retrieved using a key.
*
* <p>
- * This node maps to the list node in YANG schema, schema and semantics of this node,
- * its children and key construction is defined by YANG <code>list</code>
- * statement and its <code>key</code> and <code>ordered-by</code> substatements.
+ * This node maps to the list node in YANG schema, schema and semantics of this node, its children and key construction
+ * is defined by YANG {@code list} statement and its {@code key} and {@code ordered-by} substatements.
*/
-public interface MapNode extends MixinNode, DataContainerChild<NodeIdentifier, Collection<MapEntryNode>>,
- NormalizedNodeContainer<NodeIdentifier, NodeIdentifierWithPredicates, MapEntryNode> {
+public interface MapNode
+ extends DistinctNodeContainer<NodeIdentifier, NodeIdentifierWithPredicates, MapEntryNode>, DataContainerChild,
+ MixinNode {
+ /**
+ * Return a {@link Map} view of this node. Note that the iteration order of the returned is map is not defined in
+ * this interface.
+ *
+ * @return Map view of this node.
+ */
+ @Beta
+ @NonNull Map<NodeIdentifierWithPredicates, MapEntryNode> asMap();
+ @Override
+ default Collection<@NonNull MapEntryNode> body() {
+ return asMap().values();
+ }
+
+ @Override
+ default int size() {
+ return asMap().size();
+ }
+
+ @Override
+ default boolean isEmpty() {
+ return asMap().isEmpty();
+ }
}
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
/**
- * An {@link AnydataNode#getValueObjectModel() anydata value object model} which can be normalized to
+ * An {@link AnydataNode#bodyObjectModel() anydata value object model} which can be normalized to
* {@link NormalizedAnydata} when provided with proper context.
*/
@Beta
DataSchemaNode getContextNode();
- NormalizedNode<?, ?> getData();
+ NormalizedNode getData();
default void writeTo(final NormalizedNodeStreamWriter writer) throws IOException {
writeTo(writer, true);
*
* <p>
* See subinterfaces of this interface for concretization of node.
- *
- * @param <K> Local identifier of node
- * @param <V> Value of node
*/
/*
* FIXME: 7.0.0: NormalizedNode represents the perfectly-compliant view of the data, as evaluated by an implementation,
* do not agree on details. Furthermore things get way more complicated when we have a cross-schema
* boundary -- like RFC8528. Hence we cannot really have a reasonably-structured concept of unverified
* data. Nevertheless, this interface should be named 'NormalizedData'.
- *
- * FIXME: YANGTOOLS-1074: eliminate Identifiable<K> and K type argument
- * FIXME: YANGTOOLS-1074: eliminate V type argument
*/
-public interface NormalizedNode<K extends PathArgument, V> extends Identifiable<K> {
+public interface NormalizedNode extends Identifiable<PathArgument> {
/**
* QName of the node as defined in YANG schema.
*
* @return QName of this node, non-null.
*/
- // FIXME: YANGTOOLS-1074: eliminate this method
- QName getNodeType();
+ // FIXME: YANGTOOLS-1074: eliminate this method: the problem is that it down not with with AugmentationIdentifier
+ // At least we need a 'QNameModule namespace()' method, as that is the common contract.
+ @Deprecated(forRemoval = true)
+ default @NonNull QName getNodeType() {
+ return getIdentifier().getNodeType();
+ }
- /**
- * Locally unique identifier of the node.
- *
- * @return Node identifier, non-null.
- */
@Override
- K getIdentifier();
+ // We override here, so that NormalizedNode.getIdentifier() has fewer implementations
+ PathArgument getIdentifier();
/**
- * Value of node.
+ * Returns the body of this node. While the return value specifies {@link Object}, this method's return value has
+ * further semantics. The returned object must be a well-published contract, such as {@code String},
+ * {@code Collection<NormalizedNode>} or {@code DOMSource}.
*
- * @return Value of the node, may be null.
+ * @return Returned value of this node.
*/
- // FIXME: YANGTOOLS-1074: eliminate this method
- @NonNull V getValue();
+ @NonNull Object body();
}
package org.opendaylight.yangtools.yang.data.api.schema;
import java.util.Collection;
-import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
/**
- * Node which is not leaf, but has child {@link NormalizedNode}s as its value.
+ * Node which is not leaf, but has child {@link NormalizedNode}s as its value. It provides iteration over its child
+ * nodes via {@link #body()}. More convenient access to child nodes are provided by {@link DistinctNodeContainer} and
+ * {@link OrderedNodeContainer}.
*
- * <p>
- * NormalizedNodeContainer does not have a value, but it has a child nodes. Definition of possible and valid child nodes
- * is introduced in subclasses of this interface.
- *
- * <p>
- * This interface should not be used directly, but rather use of of derived subclasses such as
- * {@link DataContainerNode}, {@link MapNode}, {@link LeafSetNode}.
- *
- * @param <I> Node Identifier type
- * @param <K> Child Node Identifier type
+ * @param <I> Path argument type
* @param <V> Child Node type
*/
-public interface NormalizedNodeContainer<I extends PathArgument, K extends PathArgument,
- V extends NormalizedNode<? extends K, ?>> extends NormalizedNode<I, Collection<V>> {
-
+public interface NormalizedNodeContainer<I extends PathArgument, V extends NormalizedNode>
+ extends NormalizedNode, OrderingAware {
@Override
I getIdentifier();
/**
- * Returns immutable iteration of child nodes of this node.
+ * {@inheritDoc}
+ *
+ * <p>
+ * Returns iteration of all child nodes. Order of returned child nodes may be defined by subinterfaces.
*/
@Override
- Collection<V> getValue();
+ Collection<@NonNull V> body();
/**
- * Return the logical size of this container, i.e. the number of children in contains.
- *
- * <p>
- * Default implementation defers to the collection returned by {@link #getValue()}. Implementations are strongly
- * encouraged to provide a more efficient implementation of this method.
+ * Return the logical size of this container body. The default implementation defers to {@code body().size()}.
*
- * @return Number of child nodes in this container.
+ * @return Size of this container's body.
*/
- // FIXME: 7.0.0: consider making this method non-default, but then it will conflict in OrderedLeafSet
default int size() {
- return getValue().size();
+ return body().size();
}
/**
- * Returns child node identified by provided key.
+ * Determine whether this container body is empty. The default implementation defers to {@code body().isEmpty()}.
*
- * @param child Path argument identifying child node
- * @return Optional with child node if child exists. {@link Optional#empty()} if child does not exist.
+ * @return True if this container has an empty body.
*/
- Optional<V> getChild(K child);
+ default boolean isEmpty() {
+ return body().isEmpty();
+ }
}
* @param node A normalized node subtree, may not be null
* @return A Map of NormalizedNode/DuplicateEntry relationships.
*/
- public static Map<NormalizedNode<?, ?>, DuplicateEntry> findDuplicates(final @NonNull NormalizedNode<?, ?> node) {
+ public static Map<NormalizedNode, DuplicateEntry> findDuplicates(final @NonNull NormalizedNode node) {
return Maps.filterValues(DuplicateFinder.findDuplicates(node), input -> !input.getDuplicates().isEmpty());
}
- public static Optional<NormalizedNode<?, ?>> findNode(final YangInstanceIdentifier rootPath,
- final NormalizedNode<?, ?> rootNode, final YangInstanceIdentifier childPath) {
+ public static Optional<NormalizedNode> findNode(final YangInstanceIdentifier rootPath,
+ final NormalizedNode rootNode, final YangInstanceIdentifier childPath) {
final Optional<YangInstanceIdentifier> relativePath = childPath.relativeTo(rootPath);
return relativePath.isPresent() ? findNode(rootNode, relativePath.get()) : Optional.empty();
}
- public static Optional<NormalizedNode<?, ?>> findNode(final Optional<NormalizedNode<?, ?>> parent,
+ public static Optional<NormalizedNode> findNode(final Optional<NormalizedNode> parent,
final Iterable<PathArgument> relativePath) {
final Iterator<PathArgument> pathIterator = requireNonNull(relativePath, "Relative path must not be null")
.iterator();
- Optional<NormalizedNode<?, ?>> currentNode = requireNonNull(parent, "Parent must not be null");
+ Optional<NormalizedNode> currentNode = requireNonNull(parent, "Parent must not be null");
while (currentNode.isPresent() && pathIterator.hasNext()) {
currentNode = getDirectChild(currentNode.get(), pathIterator.next());
}
return currentNode;
}
- public static Optional<NormalizedNode<?, ?>> findNode(final Optional<NormalizedNode<?, ?>> parent,
+ public static Optional<NormalizedNode> findNode(final Optional<NormalizedNode> parent,
final PathArgument pathArg) {
return parent.flatMap(node -> getDirectChild(node, pathArg));
}
- public static Optional<NormalizedNode<?, ?>> findNode(final Optional<NormalizedNode<?, ?>> parent,
+ public static Optional<NormalizedNode> findNode(final Optional<NormalizedNode> parent,
final PathArgument... relativePath) {
return findNode(parent, Arrays.asList(relativePath));
}
- public static Optional<NormalizedNode<?, ?>> findNode(final @Nullable NormalizedNode<?, ?> parent,
+ public static Optional<NormalizedNode> findNode(final @Nullable NormalizedNode parent,
final PathArgument pathArg) {
return parent == null ? Optional.empty() : getDirectChild(parent, pathArg);
}
- public static Optional<NormalizedNode<?, ?>> findNode(final NormalizedNode<?, ?> parent,
+ public static Optional<NormalizedNode> findNode(final NormalizedNode parent,
final Iterable<PathArgument> relativePath) {
return findNode(Optional.ofNullable(parent), relativePath);
}
* @deprecated Use {@link #findNode(NormalizedNode, Descendant)} instead.
*/
@Deprecated(forRemoval = true)
- public static Optional<NormalizedNode<?, ?>> findNode(final NormalizedNode<?, ?> parent,
+ public static Optional<NormalizedNode> findNode(final NormalizedNode parent,
final SchemaPath relativePath) {
checkArgument(!relativePath.isAbsolute(), "%s is not a relative path", relativePath);
return findNode(Optional.ofNullable(parent), Iterables.transform(relativePath.getPathFromRoot(),
NodeIdentifier::new));
}
- public static Optional<NormalizedNode<?, ?>> findNode(final NormalizedNode<?, ?> parent, final Descendant path) {
+ public static Optional<NormalizedNode> findNode(final NormalizedNode parent, final Descendant path) {
return findNode(Optional.ofNullable(parent),
Iterables.transform(path.getNodeIdentifiers(), NodeIdentifier::new));
}
- public static Optional<NormalizedNode<?, ?>> findNode(final NormalizedNode<?, ?> parent,
+ public static Optional<NormalizedNode> findNode(final NormalizedNode parent,
final PathArgument... relativePath) {
return findNode(parent, Arrays.asList(relativePath));
}
- public static Optional<NormalizedNode<?, ?>> findNode(final NormalizedNode<?, ?> tree,
+ public static Optional<NormalizedNode> findNode(final NormalizedNode tree,
final YangInstanceIdentifier path) {
return findNode(Optional.of(requireNonNull(tree, "Tree must not be null")),
requireNonNull(path, "Path must not be null").getPathArguments());
}
@SuppressWarnings({ "unchecked", "rawtypes" })
- public static Optional<NormalizedNode<?, ?>> getDirectChild(final NormalizedNode<?, ?> node,
+ public static Optional<NormalizedNode> getDirectChild(final NormalizedNode node,
final PathArgument pathArg) {
if (node instanceof DataContainerNode) {
- return (Optional) ((DataContainerNode<?>) node).getChild(pathArg);
+ return (Optional) ((DataContainerNode<?>) node).findChildByArg(pathArg);
} else if (node instanceof MapNode && pathArg instanceof NodeIdentifierWithPredicates) {
- return (Optional) ((MapNode) node).getChild((NodeIdentifierWithPredicates) pathArg);
+ return (Optional) ((MapNode) node).findChildByArg((NodeIdentifierWithPredicates) pathArg);
} else if (node instanceof LeafSetNode && pathArg instanceof NodeWithValue) {
- return (Optional) ((LeafSetNode<?>) node).getChild((NodeWithValue) pathArg);
+ return (Optional) ((LeafSetNode<?>) node).findChildByArg((NodeWithValue<?>) pathArg);
}
// Anything else, including ValueNode
return Optional.empty();
* @param node Data subtree root
* @return String containing a human-readable form of the subtree.
*/
- public static String toStringTree(final NormalizedNode<?, ?> node) {
+ public static String toStringTree(final NormalizedNode node) {
final StringBuilder builder = new StringBuilder();
toStringTree(builder, node, 0);
return builder.toString();
}
- private static void toStringTree(final StringBuilder builder, final NormalizedNode<?, ?> node, final int offset) {
+ private static void toStringTree(final StringBuilder builder, final NormalizedNode node, final int offset) {
final String prefix = " ".repeat(offset);
builder.append(prefix).append(toStringTree(node.getIdentifier()));
if (node instanceof NormalizedNodeContainer) {
- final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) node;
-
builder.append(" {\n");
- for (NormalizedNode<?, ?> child : container.getValue()) {
+ for (NormalizedNode child : ((NormalizedNodeContainer<?, ?>) node).body()) {
toStringTree(builder, child, offset + STRINGTREE_INDENT);
}
-
builder.append(prefix).append('}');
} else {
- builder.append(' ').append(node.getValue());
+ builder.append(' ').append(node.body());
}
builder.append('\n');
}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.api.schema;
-
-/**
- * Map node which preserves user-supplied ordering.
- *
- * <p>
- * This node represents a data instance of <code>list</code> with
- * <code>ordered-by user;</code> substatement and <code>key</code> definition.
- *
- * <p>
- * Except preserving user-ordering all other semantics and behaviour is same as
- * in {@link MapNode}.
- */
-public interface OrderedMapNode extends MapNode, OrderedNodeContainer<MapEntryNode> {
-
-}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import java.util.Collection;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
/**
- * Normalized Node container which preserves user supplied ordering
- * and allows addressing of child elements by position.
+ * A {@link NormalizedNodeContainer} which preserves user supplied ordering and allows addressing of child elements by
+ * position. All implementations of this interface must also implement {@link OrderingAware.User}.
*
* @param <V> child type
*/
-public interface OrderedNodeContainer<V extends NormalizedNode<?, ?>> extends MixinNode,
- NormalizedNode<NodeIdentifier, Collection<V>> {
+public interface OrderedNodeContainer<V extends NormalizedNode>
+ extends NormalizedNodeContainer<NodeIdentifier, V>, MixinNode, OrderingAware.User {
/**
* Returns child node by position.
*
* @return Child Node
* @throws IndexOutOfBoundsException Out of bound Exception
*/
- V getChild(int position);
+ // FIXME: 7.0.0: rename to 'childAt(int)'
+ @NonNull V getChild(int position);
- /**
- * Returns count of child nodes.
- *
- * @return count of child nodes.
- */
- int getSize();
+ // FIXME: 7.0.0: do we really mean 'List' for body?
+ // @Override
+ // List<V> body();
+
+ @Override
+ int hashCode();
+
+ @Override
+ boolean equals(Object obj);
}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.api.schema;
+
+import com.google.common.annotations.Beta;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.concepts.ItemOrder.Ordered;
+import org.opendaylight.yangtools.concepts.ItemOrder.Unordered;
+import org.opendaylight.yangtools.yang.common.Ordering;
+
+/**
+ * Marker interfaces for {@link NormalizedNodeContainer}s which have distinct ordering requirements.
+ */
+@Beta
+@NonNullByDefault
+public interface OrderingAware {
+ /**
+ * Marker interface for NormalizedNodeContainer implementations which correspond to {@code ordered-by system}. These
+ * follow the {@link Unordered} contract.
+ */
+ public interface System extends OrderingAware, Unordered {
+ @Override
+ default Ordering ordering() {
+ return Ordering.SYSTEM;
+ }
+ }
+
+ /**
+ * Marker interface for NormalizedNodeContainer implementations which correspond to {@code ordered-by user}. These
+ * follow the {@link Ordered} contract.
+ */
+ public interface User extends OrderingAware, Ordered {
+ @Override
+ default Ordering ordering() {
+ return Ordering.USER;
+ }
+ }
+
+ /**
+ * Ordering items within this object.
+ *
+ * @return This object's item ordering.
+ */
+ Ordering ordering();
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.api.schema;
+
+/**
+ * Node representing set of simple leaf nodes. Node containing instances of {@link LeafSetEntryNode}.
+ *
+ * <p>
+ * Schema and semantics of this node are described by instance of
+ * {@link org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode}.
+ *
+ * @param <T> Type of leaf node values.
+ */
+public interface SystemLeafSetNode<T> extends LeafSetNode<T>, OrderingAware.System {
+ @Override
+ int hashCode();
+
+ @Override
+ boolean equals(Object obj);
+}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.api.schema;
+
+/**
+ * {@link MapNode} which additionally preserves user-supplied ordering. This node represents a data instance of
+ * a {@code list} with {@code ordered-by user;} substatement and a {@code key} definition.
+ */
+public interface SystemMapNode extends MapNode, OrderingAware.System {
+ @Override
+ int hashCode();
+
+ @Override
+ boolean equals(Object obj);
+}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import java.util.Collection;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-
/**
- * Containment node, which contains {@link UnkeyedListEntryNode} of the same type, which may
- * be quickly retrieved using key.
- *
- * <p>
- * This node maps to the <code>list</code> statement in YANG schema,
- * which did not define <code>key</code> substatement.
+ * Containment node, which contains {@link UnkeyedListEntryNode} of the same type, which may be quickly retrieved using
+ * key. This node maps to the <code>list</code> statement in YANG schema, which did not define {@code key} substatement.
*
* <p>
- * Ordering of the elements is user-defined during construction of instance of this
- * interface. Ordered view of elements (iteration)
- * is provided by {@link #getValue()} call.
+ * Ordering of the elements is user-defined during construction of instance of this interface. Ordered view of elements
+ * (iteration) is provided by {@link #body()} call.
*/
-public interface UnkeyedListNode extends DataContainerChild<NodeIdentifier, Collection<UnkeyedListEntryNode>>,
- OrderedNodeContainer<UnkeyedListEntryNode> {
+public interface UnkeyedListNode extends OrderedNodeContainer<UnkeyedListEntryNode>, DataContainerChild {
}
package org.opendaylight.yangtools.yang.data.api.schema;
/**
- * Leaf set node which preserves user-supplied ordering.
- *
- * <p>
- * This node represents a data instance of <code>leaf-list</code> with
- * <code>ordered-by user;</code> substatement.
- *
- * <p>
- * Except preserving user-ordering all other semantics and behaviour is same
- * as in {@link LeafSetNode}.
+ * {@link LeafSetNode} which preserves user-supplied ordering. This node represents a data instance of
+ * a {@code leaf-list} with a {@code ordered-by user;} substatement.
*
* @param <T> Value type of Leaf entries
*/
-public interface OrderedLeafSetNode<T> extends LeafSetNode<T>, OrderedNodeContainer<LeafSetEntryNode<T>> {
+public interface UserLeafSetNode<T> extends LeafSetNode<T>, OrderedNodeContainer<LeafSetEntryNode<T>> {
}
--- /dev/null
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.api.schema;
+
+import java.util.Map;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+
+/**
+ * {@link MapNode} which additionally preserves user-supplied ordering. This node represents a data instance of
+ * a {@code list} with {@code ordered-by user;} substatement and a {@code key} definition.
+ */
+public interface UserMapNode extends MapNode, OrderedNodeContainer<MapEntryNode> {
+ /**
+ * {@inheritDoc}
+ *
+ * <p>
+ * The implementation is required to define a user-visible iteration order, which must match {@link #getChild(int)}.
+ */
+ @Override
+ Map<NodeIdentifierWithPredicates, MapEntryNode> asMap();
+}
*/
package org.opendaylight.yangtools.yang.data.api.schema;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-
/**
* Interface holding the common trait of {@link LeafSetEntryNode} and {@link LeafNode}, which both hold a value.
*
- * @param <K> Local identifier of node
- * @param <V> Value of node
+ * @param <V> Value of node, which needs to be a well-published simple value type.
*/
-public interface ValueNode<K extends PathArgument, V> extends NormalizedNode<K, V> {
+public interface ValueNode<V> extends NormalizedNode {
/**
- * Returns value of held by this node.
+ * {@inheritDoc}
*
+ * <p>
* <b>Implementation note</b>
- * Invocation of {@link #getValue()} must provide the same value as value in {@link #getIdentifier()}.
- * {@code true == this.getIdentifier().getValue().equals(this.getValue())}.
- *
- * @return Returned value of this node. Value SHOULD meet criteria defined by schema.
+ * Invocation of {@code body()} must provide the same value as value in {@link #getIdentifier()}.
+ * {@code true == this.getIdentifier().getValue().equals(this.body())}.
*/
@Override
- V getValue();
+ V body();
}
package org.opendaylight.yangtools.yang.data.api.schema;
import com.google.common.annotations.Beta;
-import java.util.Collection;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
/**
* AnyXML node with schema of contained XML data.
+ *
+ * @deprecated This interface is wrong abstraction. It should be expressed as {@link NormalizableAnydata} equivalent.
*/
@Beta
-public interface YangModeledAnyXmlNode extends DataContainerNode<NodeIdentifier>,
- DataContainerChild<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> {
-
+@Deprecated
+public interface YangModeledAnyXmlNode extends DataContainerNode<NodeIdentifier>, DataContainerChild {
/**
* Returns the schema corresponding to the node's datea.
*
* node, which can occur only once per parent node; its leaves are MapEntryNode
* nodes.
* <ul>
- * <li> {@link org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode} -
+ * <li> {@link org.opendaylight.yangtools.yang.data.api.schema.UserMapNode} -
* Special node, which can occur only once per parent node; its leaves are
* MapEntryNode nodes.</li>
* </ul>
import java.io.Flushable;
import java.io.IOException;
import java.util.Collection;
-import java.util.Optional;
import java.util.Set;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.dom.DOMSource;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.YangModeledAnyXmlNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @return NormalizedNodeWriter this
* @throws IOException when thrown from the backing writer.
*/
- public NormalizedNodeWriter write(final NormalizedNode<?, ?> node) throws IOException {
+ public NormalizedNodeWriter write(final NormalizedNode node) throws IOException {
if (wasProcessedAsCompositeNode(node)) {
return this;
}
return children instanceof Collection ? ((Collection<?>) children).size() : UNKNOWN_SIZE;
}
- protected boolean wasProcessAsSimpleNode(final NormalizedNode<?, ?> node) throws IOException {
+ protected boolean wasProcessAsSimpleNode(final NormalizedNode node) throws IOException {
if (node instanceof LeafSetEntryNode) {
final LeafSetEntryNode<?> nodeAsLeafList = (LeafSetEntryNode<?>)node;
writer.startLeafSetEntryNode(nodeAsLeafList.getIdentifier());
- writer.scalarValue(nodeAsLeafList.getValue());
+ writer.scalarValue(nodeAsLeafList.body());
writer.endNode();
return true;
} else if (node instanceof LeafNode) {
final LeafNode<?> nodeAsLeaf = (LeafNode<?>)node;
writer.startLeafNode(nodeAsLeaf.getIdentifier());
- writer.scalarValue(nodeAsLeaf.getValue());
+ writer.scalarValue(nodeAsLeaf.body());
writer.endNode();
return true;
} else if (node instanceof AnyxmlNode) {
final AnyxmlNode<?> anyxmlNode = (AnyxmlNode<?>)node;
- final Class<?> model = anyxmlNode.getValueObjectModel();
+ final Class<?> model = anyxmlNode.bodyObjectModel();
if (writer.startAnyxmlNode(anyxmlNode.getIdentifier(), model)) {
- final Object value = node.getValue();
+ final Object value = node.body();
if (DOMSource.class.isAssignableFrom(model)) {
verify(value instanceof DOMSource, "Inconsistent anyxml node %s", anyxmlNode);
writer.domSourceValue((DOMSource) value);
LOG.debug("Ignoring unhandled anyxml node {}", anyxmlNode);
} else if (node instanceof AnydataNode) {
final AnydataNode<?> anydata = (AnydataNode<?>) node;
- final Class<?> model = anydata.getValueObjectModel();
+ final Class<?> model = anydata.bodyObjectModel();
if (writer.startAnydataNode(anydata.getIdentifier(), model)) {
- writer.scalarValue(anydata.getValue());
+ writer.scalarValue(anydata.body());
writer.endNode();
return true;
}
* @return True
* @throws IOException when the writer reports it
*/
- protected boolean writeChildren(final Iterable<? extends NormalizedNode<?, ?>> children) throws IOException {
- for (final NormalizedNode<?, ?> child : children) {
+ protected boolean writeChildren(final Iterable<? extends NormalizedNode> children) throws IOException {
+ for (final NormalizedNode child : children) {
write(child);
}
}
protected boolean writeMapEntryNode(final MapEntryNode node) throws IOException {
- writer.startMapEntryNode(node.getIdentifier(), childSizeHint(node.getValue()));
- return writeChildren(node.getValue());
+ writer.startMapEntryNode(node.getIdentifier(), childSizeHint(node.body()));
+ return writeChildren(node.body());
}
- protected boolean wasProcessedAsCompositeNode(final NormalizedNode<?, ?> node) throws IOException {
+ protected boolean wasProcessedAsCompositeNode(final NormalizedNode node) throws IOException {
if (node instanceof ContainerNode) {
final ContainerNode n = (ContainerNode) node;
- writer.startContainerNode(n.getIdentifier(), childSizeHint(n.getValue()));
- return writeChildren(n.getValue());
+ writer.startContainerNode(n.getIdentifier(), childSizeHint(n.body()));
+ return writeChildren(n.body());
}
if (node instanceof YangModeledAnyXmlNode) {
final YangModeledAnyXmlNode n = (YangModeledAnyXmlNode) node;
- writer.startYangModeledAnyXmlNode(n.getIdentifier(), childSizeHint(n.getValue()));
- return writeChildren(n.getValue());
+ writer.startYangModeledAnyXmlNode(n.getIdentifier(), childSizeHint(n.body()));
+ return writeChildren(n.body());
}
if (node instanceof MapEntryNode) {
return writeMapEntryNode((MapEntryNode) node);
}
if (node instanceof UnkeyedListEntryNode) {
final UnkeyedListEntryNode n = (UnkeyedListEntryNode) node;
- writer.startUnkeyedListItem(n.getIdentifier(), childSizeHint(n.getValue()));
- return writeChildren(n.getValue());
+ writer.startUnkeyedListItem(n.getIdentifier(), childSizeHint(n.body()));
+ return writeChildren(n.body());
}
if (node instanceof ChoiceNode) {
final ChoiceNode n = (ChoiceNode) node;
- writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.getValue()));
- return writeChildren(n.getValue());
+ writer.startChoiceNode(n.getIdentifier(), childSizeHint(n.body()));
+ return writeChildren(n.body());
}
if (node instanceof AugmentationNode) {
final AugmentationNode n = (AugmentationNode) node;
writer.startAugmentationNode(n.getIdentifier());
- return writeChildren(n.getValue());
+ return writeChildren(n.body());
}
if (node instanceof UnkeyedListNode) {
final UnkeyedListNode n = (UnkeyedListNode) node;
- writer.startUnkeyedList(n.getIdentifier(), childSizeHint(n.getValue()));
- return writeChildren(n.getValue());
+ writer.startUnkeyedList(n.getIdentifier(), childSizeHint(n.body()));
+ return writeChildren(n.body());
}
- if (node instanceof OrderedMapNode) {
- final OrderedMapNode n = (OrderedMapNode) node;
- writer.startOrderedMapNode(n.getIdentifier(), childSizeHint(n.getValue()));
- return writeChildren(n.getValue());
+ if (node instanceof UserMapNode) {
+ final UserMapNode n = (UserMapNode) node;
+ writer.startOrderedMapNode(n.getIdentifier(), childSizeHint(n.body()));
+ return writeChildren(n.body());
}
- if (node instanceof MapNode) {
- final MapNode n = (MapNode) node;
- writer.startMapNode(n.getIdentifier(), childSizeHint(n.getValue()));
- return writeChildren(n.getValue());
+ if (node instanceof SystemMapNode) {
+ final SystemMapNode n = (SystemMapNode) node;
+ writer.startMapNode(n.getIdentifier(), childSizeHint(n.body()));
+ return writeChildren(n.body());
}
- if (node instanceof OrderedLeafSetNode) {
- final LeafSetNode<?> n = (LeafSetNode<?>) node;
- writer.startOrderedLeafSet(n.getIdentifier(), childSizeHint(n.getValue()));
- return writeChildren(n.getValue());
+ if (node instanceof UserLeafSetNode) {
+ final UserLeafSetNode<?> n = (UserLeafSetNode<?>) node;
+ writer.startOrderedLeafSet(n.getIdentifier(), childSizeHint(n.body()));
+ return writeChildren(n.body());
}
- if (node instanceof LeafSetNode) {
- final LeafSetNode<?> n = (LeafSetNode<?>) node;
- writer.startLeafSet(n.getIdentifier(), childSizeHint(n.getValue()));
- return writeChildren(n.getValue());
+ if (node instanceof SystemLeafSetNode) {
+ final SystemLeafSetNode<?> n = (SystemLeafSetNode<?>) node;
+ writer.startLeafSet(n.getIdentifier(), childSizeHint(n.body()));
+ return writeChildren(n.body());
}
return false;
@Override
protected boolean writeMapEntryNode(final MapEntryNode node) throws IOException {
final NormalizedNodeStreamWriter nnWriter = getWriter();
- nnWriter.startMapEntryNode(node.getIdentifier(), childSizeHint(node.getValue()));
+ nnWriter.startMapEntryNode(node.getIdentifier(), childSizeHint(node.body()));
final Set<QName> qnames = node.getIdentifier().keySet();
// Write out all the key children
for (final QName qname : qnames) {
- final Optional<? extends NormalizedNode<?, ?>> child = node.getChild(new NodeIdentifier(qname));
- if (child.isPresent()) {
- write(child.get());
+ final DataContainerChild child = node.childByArg(new NodeIdentifier(qname));
+ if (child != null) {
+ write(child);
} else {
LOG.info("No child for key element {} found", qname);
}
}
// Write all the rest
- return writeChildren(Iterables.filter(node.getValue(), input -> {
+ return writeChildren(Iterables.filter(node.body(), input -> {
if (input instanceof AugmentationNode) {
return true;
}
*
* @return Result of streaming.
*/
- NormalizedNode<?, ?> getResult();
+ NormalizedNode getResult();
/**
* Reset this writer to initial state.
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
abstract class AbstractAvailableLeafCandidateNode extends AbstractLeafCandidateNode {
- AbstractAvailableLeafCandidateNode(final NormalizedNode<?, ?> dataAfter) {
+ AbstractAvailableLeafCandidateNode(final NormalizedNode dataAfter) {
super(dataAfter);
}
@Override
- public final Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public final Optional<NormalizedNode> getDataAfter() {
return dataOptional();
}
}
\ No newline at end of file
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
abstract class AbstractDataTreeCandidateNode implements DataTreeCandidateNode {
- private final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?,?>> data;
+ private final DistinctNodeContainer<?, PathArgument, NormalizedNode> data;
- AbstractDataTreeCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data) {
+ AbstractDataTreeCandidateNode(final DistinctNodeContainer<?, PathArgument, NormalizedNode> data) {
this.data = requireNonNull(data);
}
return data.getIdentifier();
}
- final @NonNull Optional<NormalizedNode<?, ?>> dataOptional() {
+ final @NonNull Optional<NormalizedNode> dataOptional() {
return Optional.of(data);
}
- final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data() {
+ final DistinctNodeContainer<?, PathArgument, NormalizedNode> data() {
return data;
}
import static java.util.Objects.requireNonNull;
import java.util.Collection;
-import java.util.Collections;
+import java.util.List;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
abstract class AbstractLeafCandidateNode implements DataTreeCandidateNode {
- private final NormalizedNode<?, ?> data;
+ private final NormalizedNode data;
- AbstractLeafCandidateNode(final NormalizedNode<?, ?> data) {
+ AbstractLeafCandidateNode(final NormalizedNode data) {
this.data = requireNonNull(data);
}
- final @NonNull Optional<NormalizedNode<?, ?>> dataOptional() {
+ final @NonNull Optional<NormalizedNode> dataOptional() {
return Optional.of(data);
}
@Override
public final Collection<DataTreeCandidateNode> getChildNodes() {
- return Collections.emptyList();
+ return List.of();
}
@Override
import java.util.Collection;
import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
abstract class AbstractRecursiveCandidateNode extends AbstractDataTreeCandidateNode {
- AbstractRecursiveCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data) {
+ AbstractRecursiveCandidateNode(final DistinctNodeContainer<?, PathArgument, NormalizedNode> data) {
super(data);
}
@Override
public final Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument identifier) {
- return data().getChild(identifier).map(this::createChild);
+ return data().findChildByArg(identifier).map(this::createChild);
}
@Override
public final Collection<DataTreeCandidateNode> getChildNodes() {
- return Collections2.transform(data().getValue(), this::createChild);
+ return Collections2.transform(data().body(), this::createChild);
}
- abstract DataTreeCandidateNode createContainer(
- NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> childData);
+ abstract DataTreeCandidateNode createContainer(DistinctNodeContainer<?, PathArgument, NormalizedNode> childData);
- abstract DataTreeCandidateNode createLeaf(NormalizedNode<?,?> childData);
+ abstract DataTreeCandidateNode createLeaf(NormalizedNode childData);
@SuppressWarnings("unchecked")
- private DataTreeCandidateNode createChild(final NormalizedNode<?, ?> childData) {
- if (childData instanceof NormalizedNodeContainer) {
- return createContainer((NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) childData);
+ private DataTreeCandidateNode createChild(final NormalizedNode childData) {
+ if (childData instanceof DistinctNodeContainer) {
+ return createContainer((DistinctNodeContainer<?, PathArgument, NormalizedNode>) childData);
}
return createLeaf(childData);
}
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
abstract class AbstractWriteCandidate extends AbstractAvailableLeafCandidateNode {
- AbstractWriteCandidate(final NormalizedNode<?, ?> dataAfter) {
+ AbstractWriteCandidate(final NormalizedNode dataAfter) {
super(dataAfter);
}
* @return Node data as they will be present in the tree after
* the modification is applied.
*/
- @NonNull Optional<NormalizedNode<?, ?>> getDataAfter();
+ @NonNull Optional<NormalizedNode> getDataAfter();
/**
* Return the before-image of data corresponding to the node.
* @return Node data as they were present in the tree before
* the modification was applied.
*/
- @NonNull Optional<NormalizedNode<?, ?>> getDataBefore();
+ @NonNull Optional<NormalizedNode> getDataBefore();
}
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
* @param node Unchanged normalized node
* @return An empty DataTreeCandidateNode
*/
- public static @NonNull DataTreeCandidateNode unmodified(final NormalizedNode<?, ?> node) {
- if (node instanceof NormalizedNodeContainer) {
- return new RecursiveUnmodifiedCandidateNode(
- (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) node);
+ public static @NonNull DataTreeCandidateNode unmodified(final NormalizedNode node) {
+ if (node instanceof DistinctNodeContainer) {
+ return new RecursiveUnmodifiedCandidateNode((DistinctNodeContainer<?, PathArgument, NormalizedNode>) node);
}
return new UnmodifiedLeafCandidateNode(node);
}
* @return An empty DataTreeCandidateNode
* @throws NullPointerException if {@code node} is null
*/
- public static @NonNull DataTreeCandidateNode written(final NormalizedNode<?, ?> node) {
+ public static @NonNull DataTreeCandidateNode written(final NormalizedNode node) {
return new NormalizedNodeDataTreeCandidateNode(node);
}
* @return Collection of changes
*/
public static @NonNull Collection<DataTreeCandidateNode> containerDelta(
- final @Nullable NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
- final @Nullable NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData) {
+ final @Nullable DistinctNodeContainer<?, PathArgument, NormalizedNode> oldData,
+ final @Nullable DistinctNodeContainer<?, PathArgument, NormalizedNode> newData) {
if (newData == null) {
return oldData == null ? ImmutableList.of()
- : Collections2.transform(oldData.getValue(), DataTreeCandidateNodes::deleteNode);
+ : Collections2.transform(oldData.body(), DataTreeCandidateNodes::deleteNode);
}
if (oldData == null) {
- return Collections2.transform(newData.getValue(), DataTreeCandidateNodes::writeNode);
+ return Collections2.transform(newData.body(), DataTreeCandidateNodes::writeNode);
}
/*
* iterate over old data and looking up each child in new data.
*/
final Collection<DataTreeCandidateNode> result = new ArrayList<>();
- for (NormalizedNode<?, ?> child : newData.getValue()) {
+ for (NormalizedNode child : newData.body()) {
final DataTreeCandidateNode node;
- final Optional<NormalizedNode<?, ?>> maybeOldChild = oldData.getChild(child.getIdentifier());
-
- if (maybeOldChild.isPresent()) {
+ final NormalizedNode oldChild = oldData.childByArg(child.getIdentifier());
+ if (oldChild != null) {
// This does not find children which have not in fact been modified, as doing that
// reliably would require us running a full equals() on the two nodes.
- node = replaceNode(maybeOldChild.get(), child);
+ node = replaceNode(oldChild, child);
} else {
node = writeNode(child);
}
}
// Process removals next, looking into new data to see if we processed it
- for (NormalizedNode<?, ?> child : oldData.getValue()) {
- if (newData.getChild(child.getIdentifier()).isEmpty()) {
+ for (NormalizedNode child : oldData.body()) {
+ if (newData.childByArg(child.getIdentifier()) == null) {
result.add(deleteNode(child));
}
}
* @return A {@link DataTreeCandidateNode} describing the change, or empty if the node is not present
*/
public static @NonNull Optional<DataTreeCandidateNode> containerDelta(
- final @Nullable NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
- final @Nullable NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData,
+ final @Nullable DistinctNodeContainer<?, PathArgument, NormalizedNode> oldData,
+ final @Nullable DistinctNodeContainer<?, PathArgument, NormalizedNode> newData,
final @NonNull PathArgument child) {
- final Optional<NormalizedNode<?, ?>> maybeNewChild = getChild(newData, child);
- final Optional<NormalizedNode<?, ?>> maybeOldChild = getChild(oldData, child);
- if (maybeOldChild.isPresent()) {
- final NormalizedNode<?, ?> oldChild = maybeOldChild.get();
- return Optional.of(maybeNewChild.isPresent() ? replaceNode(oldChild, maybeNewChild.get())
- : deleteNode(oldChild));
+ final NormalizedNode newChild = getChild(newData, child);
+ final NormalizedNode oldChild = getChild(oldData, child);
+ if (oldChild != null) {
+ return Optional.of(newChild != null ? replaceNode(oldChild, newChild) : deleteNode(oldChild));
+ } else if (newChild != null) {
+ return Optional.of(DataTreeCandidateNodes.writeNode(newChild));
+ } else {
+ return Optional.empty();
}
-
- return maybeNewChild.map(DataTreeCandidateNodes::writeNode);
}
/**
}
}
- private static Optional<NormalizedNode<?, ?>> getChild(
- final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> container,
- final PathArgument identifier) {
- return container == null ? Optional.empty() : container.getChild(identifier);
+ private static @Nullable NormalizedNode getChild(
+ final DistinctNodeContainer<?, PathArgument, ?> container, final PathArgument identifier) {
+ return container == null ? null : container.childByArg(identifier);
}
@SuppressWarnings("unchecked")
- private static @NonNull DataTreeCandidateNode deleteNode(final NormalizedNode<?, ?> data) {
+ private static @NonNull DataTreeCandidateNode deleteNode(final NormalizedNode data) {
if (data instanceof NormalizedNodeContainer) {
return new RecursiveDeleteCandidateNode(
- (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) data);
+ (DistinctNodeContainer<?, PathArgument, NormalizedNode>) data);
}
return new DeleteLeafCandidateNode(data);
}
@SuppressWarnings("unchecked")
- private static @NonNull DataTreeCandidateNode replaceNode(final NormalizedNode<?, ?> oldData,
- final NormalizedNode<?, ?> newData) {
- if (oldData instanceof NormalizedNodeContainer) {
+ private static @NonNull DataTreeCandidateNode replaceNode(final NormalizedNode oldData,
+ final NormalizedNode newData) {
+ if (oldData instanceof DistinctNodeContainer) {
return new RecursiveReplaceCandidateNode(
- (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) oldData,
- (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) newData);
+ (DistinctNodeContainer<?, PathArgument, NormalizedNode>) oldData,
+ (DistinctNodeContainer<?, PathArgument, NormalizedNode>) newData);
}
return new ReplaceLeafCandidateNode(oldData, newData);
}
@SuppressWarnings("unchecked")
- private static @NonNull DataTreeCandidateNode writeNode(final NormalizedNode<?, ?> data) {
- if (data instanceof NormalizedNodeContainer) {
- return new RecursiveWriteCandidateNode(
- (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) data);
+ private static @NonNull DataTreeCandidateNode writeNode(final NormalizedNode data) {
+ if (data instanceof DistinctNodeContainer) {
+ return new RecursiveWriteCandidateNode((DistinctNodeContainer<?, PathArgument, NormalizedNode>) data);
}
return new WriteLeafCandidateNode(data);
}
}
public static @NonNull DataTreeCandidate fromNormalizedNode(final YangInstanceIdentifier rootPath,
- final NormalizedNode<?, ?> node) {
+ final NormalizedNode node) {
return new DefaultDataTreeCandidate(rootPath, new NormalizedNodeDataTreeCandidateNode(node));
}
final List<DataTreeCandidateNode> input) {
final DataTreeCandidateNode last = input.get(input.size() - 1);
ModificationType nodeModification = last.getModificationType();
- Optional<NormalizedNode<?, ?>> dataBefore = first.getDataBefore();
- Optional<NormalizedNode<?, ?>> dataAfter = last.getDataAfter();
+ Optional<NormalizedNode> dataBefore = first.getDataBefore();
+ Optional<NormalizedNode> dataAfter = last.getDataAfter();
switch (nodeModification) {
case DELETE:
ModificationType previous = first.getModificationType();
for (Iterator<DataTreeCandidateNode> iterator = childNodes.iterator(); iterator.hasNext(); ) {
cleanUpTree(finalNode, (TerminalDataTreeCandidateNode) iterator.next());
}
- Optional<NormalizedNode<?, ?>> dataBefore = finalNode.getDataBefore(identifier);
+ Optional<NormalizedNode> dataBefore = finalNode.getDataBefore(identifier);
switch (nodeModification) {
case UNMODIFIED:
package org.opendaylight.yangtools.yang.data.api.schema.tree;
import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
/**
* @throws IllegalArgumentException if a mismatch between the arguments is detected
*/
@NonNull DataTree create(DataTreeConfiguration treeConfig, EffectiveModelContext initialSchemaContext,
- NormalizedNodeContainer<?, ?, ?> initialRoot) throws DataValidationFailedException;
+ DistinctNodeContainer<?, ?, ?> initialRoot) throws DataValidationFailedException;
}
* @param path Node path
* @param data Data to be merged
*/
- void merge(YangInstanceIdentifier path, NormalizedNode<?, ?> data);
+ void merge(YangInstanceIdentifier path, NormalizedNode data);
/**
* Replace the data at specified path with supplied data.
* @param path Node path
* @param data New node data
*/
- void write(YangInstanceIdentifier path, NormalizedNode<?, ?> data);
+ void write(YangInstanceIdentifier path, NormalizedNode data);
/**
* Finish creation of a modification, making it ready for application
* @throws BackendFailedException when implementation-specific errors occurs
* while servicing the request.
*/
- void merge(PathArgument child, NormalizedNode<?, ?> data);
+ void merge(PathArgument child, NormalizedNode data);
/**
* Replace the data at specified path with supplied data.
* @throws BackendFailedException when implementation-specific errors occurs
* while servicing the request.
*/
- void write(PathArgument child, NormalizedNode<?, ?> data);
+ void write(PathArgument child, NormalizedNode data);
}
* @param path Path of the node
* @return Optional result encapsulating the presence and value of the node
*/
- Optional<NormalizedNode<?, ?>> readNode(YangInstanceIdentifier path);
+ Optional<NormalizedNode> readNode(YangInstanceIdentifier path);
/**
* Create a new data tree modification based on this snapshot, using the
* servicing the request.
* @throws IllegalArgumentException when specified path does not identify a valid child.
*/
- Optional<NormalizedNode<?, ?>> readNode(@NonNull PathArgument child);
+ Optional<NormalizedNode> readNode(@NonNull PathArgument child);
/**
* Close this cursor. Attempting any further operations on the cursor will lead
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final class DeleteLeafCandidateNode extends AbstractLeafCandidateNode {
- DeleteLeafCandidateNode(final NormalizedNode<?, ?> data) {
+ DeleteLeafCandidateNode(final NormalizedNode data) {
super(data);
}
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public Optional<NormalizedNode> getDataAfter() {
return Optional.empty();
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return dataOptional();
}
}
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public Optional<NormalizedNode> getDataAfter() {
return Optional.empty();
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return Optional.empty();
}
}
\ No newline at end of file
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
/**
* Utility implementation of {@link DataTreeCandidateNode} which acts as if
* the {@link NormalizedNode} passed to it at creation time were freshly written.
*/
final class NormalizedNodeDataTreeCandidateNode implements DataTreeCandidateNode {
- private final NormalizedNode<?, ?> data;
+ private final NormalizedNode data;
/**
* Create a new instance backed by supplied data.
*
* @param data Backing {@link NormalizedNode} data.
*/
- NormalizedNodeDataTreeCandidateNode(final @NonNull NormalizedNode<?, ?> data) {
+ NormalizedNodeDataTreeCandidateNode(final @NonNull NormalizedNode data) {
this.data = requireNonNull(data);
}
@Override
public Collection<DataTreeCandidateNode> getChildNodes() {
- if (data instanceof NormalizedNodeContainer) {
- return Collections2.transform(((NormalizedNodeContainer<?, ?, ?>) data).getValue(),
+ if (data instanceof DistinctNodeContainer) {
+ return Collections2.transform(((DistinctNodeContainer<?, ?, ?>) data).body(),
input -> input == null ? null : new NormalizedNodeDataTreeCandidateNode(input));
}
return ImmutableList.of();
}
@Override
+ @SuppressWarnings({ "rawtypes", "unchecked" })
public Optional<DataTreeCandidateNode> getModifiedChild(final PathArgument childIdentifier) {
- if (data instanceof NormalizedNodeContainer) {
- @SuppressWarnings({ "rawtypes", "unchecked" })
- final Optional<? extends NormalizedNode<?, ?>> child =
- ((NormalizedNodeContainer)data).getChild(childIdentifier);
- return child.map(NormalizedNodeDataTreeCandidateNode::new);
+ if (data instanceof DistinctNodeContainer) {
+ return ((Optional<@NonNull NormalizedNode>) ((DistinctNodeContainer)data).findChildByArg(childIdentifier))
+ .map(NormalizedNodeDataTreeCandidateNode::new);
}
return Optional.empty();
}
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public Optional<NormalizedNode> getDataAfter() {
return Optional.of(data);
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return Optional.empty();
}
}
import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
final class RecursiveDeleteCandidateNode extends AbstractRecursiveCandidateNode {
- RecursiveDeleteCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data) {
+ RecursiveDeleteCandidateNode(final DistinctNodeContainer<?, PathArgument, NormalizedNode> data) {
super(data);
}
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public Optional<NormalizedNode> getDataAfter() {
return Optional.empty();
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return dataOptional();
}
@Override
- DataTreeCandidateNode createContainer(
- final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> childData) {
+ DataTreeCandidateNode createContainer(final DistinctNodeContainer<?, PathArgument, NormalizedNode> childData) {
return new RecursiveDeleteCandidateNode(childData);
}
@Override
- DataTreeCandidateNode createLeaf(final NormalizedNode<?, ?> childData) {
+ DataTreeCandidateNode createLeaf(final NormalizedNode childData) {
return new DeleteLeafCandidateNode(childData);
}
}
import java.util.Collection;
import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
final class RecursiveReplaceCandidateNode extends AbstractDataTreeCandidateNode {
- private final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData;
+ private final DistinctNodeContainer<?, PathArgument, NormalizedNode> oldData;
- RecursiveReplaceCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> oldData,
- final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> newData) {
+ RecursiveReplaceCandidateNode(final DistinctNodeContainer<?, PathArgument, NormalizedNode> oldData,
+ final DistinctNodeContainer<?, PathArgument, NormalizedNode> newData) {
super(newData);
this.oldData = requireNonNull(oldData);
}
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public Optional<NormalizedNode> getDataAfter() {
return dataOptional();
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return Optional.of(oldData);
}
import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
final class RecursiveUnmodifiedCandidateNode extends AbstractRecursiveCandidateNode {
- RecursiveUnmodifiedCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data) {
+ RecursiveUnmodifiedCandidateNode(final DistinctNodeContainer<?, PathArgument, NormalizedNode> data) {
super(data);
}
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public Optional<NormalizedNode> getDataAfter() {
return dataOptional();
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return dataOptional();
}
@Override
- DataTreeCandidateNode createContainer(
- final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> childData) {
+ DataTreeCandidateNode createContainer(final DistinctNodeContainer<?, PathArgument, NormalizedNode> childData) {
return new RecursiveUnmodifiedCandidateNode(childData);
}
@Override
- DataTreeCandidateNode createLeaf(final NormalizedNode<?, ?> childData) {
+ DataTreeCandidateNode createLeaf(final NormalizedNode childData) {
return new UnmodifiedLeafCandidateNode(childData);
}
}
import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
final class RecursiveWriteCandidateNode extends AbstractRecursiveCandidateNode {
- RecursiveWriteCandidateNode(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data) {
+ RecursiveWriteCandidateNode(final DistinctNodeContainer<?, PathArgument, NormalizedNode> data) {
super(data);
}
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public Optional<NormalizedNode> getDataAfter() {
return dataOptional();
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return Optional.empty();
}
@Override
- DataTreeCandidateNode createContainer(
- final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> childData) {
+ DataTreeCandidateNode createContainer(final DistinctNodeContainer<?, PathArgument, NormalizedNode> childData) {
return new RecursiveWriteCandidateNode(childData);
}
@Override
- DataTreeCandidateNode createLeaf(final NormalizedNode<?, ?> childData) {
+ DataTreeCandidateNode createLeaf(final NormalizedNode childData) {
return new WriteLeafCandidateNode(childData);
}
}
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final class ReplaceLeafCandidateNode extends AbstractWriteCandidate {
- private final NormalizedNode<?, ?> oldData;
+ private final NormalizedNode oldData;
- ReplaceLeafCandidateNode(final NormalizedNode<?, ?> oldData, final NormalizedNode<?, ?> newData) {
+ ReplaceLeafCandidateNode(final NormalizedNode oldData, final NormalizedNode newData) {
super(newData);
this.oldData = requireNonNull(oldData);
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return Optional.of(oldData);
}
}
\ No newline at end of file
}
@Override
- public synchronized Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier path) {
+ public synchronized Optional<NormalizedNode> readNode(final YangInstanceIdentifier path) {
return delegate.readNode(path);
}
}
@Override
- public synchronized void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+ public synchronized void merge(final YangInstanceIdentifier path, final NormalizedNode data) {
delegate.merge(path, data);
}
@Override
- public synchronized void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+ public synchronized void write(final YangInstanceIdentifier path, final NormalizedNode data) {
delegate.write(path, data);
}
class TerminalDataTreeCandidateNode implements DataTreeCandidateNode {
private ModificationType modificationType;
private final PathArgument identifier;
- private final NormalizedNode<?, ?> before;
- private NormalizedNode<?, ?> after;
+ private final NormalizedNode before;
+ private NormalizedNode after;
private final HashMap<PathArgument, TerminalDataTreeCandidateNode> childNodes = new HashMap<>();
private TerminalDataTreeCandidateNode parentNode;
- TerminalDataTreeCandidateNode(PathArgument identifier, NormalizedNode<?, ?> data,
+ TerminalDataTreeCandidateNode(PathArgument identifier, NormalizedNode data,
TerminalDataTreeCandidateNode parentNode) {
this(identifier, data);
this.parentNode = requireNonNull(parentNode);
}
- TerminalDataTreeCandidateNode(PathArgument identifier, NormalizedNode<?, ?> data) {
+ TerminalDataTreeCandidateNode(PathArgument identifier, NormalizedNode data) {
this(identifier, ModificationType.UNMODIFIED, data, data);
}
TerminalDataTreeCandidateNode(PathArgument identifier, ModificationType modificationType,
- NormalizedNode<?, ?> before, NormalizedNode<?, ?> after) {
+ NormalizedNode before, NormalizedNode after) {
this.modificationType = modificationType;
this.identifier = identifier;
this.before = before;
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public Optional<NormalizedNode> getDataAfter() {
return Optional.ofNullable(after);
}
- @NonNull Optional<NormalizedNode<?, ?>> getDataAfter(PathArgument id) {
+ @NonNull Optional<NormalizedNode> getDataAfter(PathArgument id) {
return getNode(id).flatMap(TerminalDataTreeCandidateNode::getDataAfter);
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return Optional.ofNullable(before);
}
- @NonNull Optional<NormalizedNode<?, ?>> getDataBefore(PathArgument id) {
+ @NonNull Optional<NormalizedNode> getDataBefore(PathArgument id) {
Optional<TerminalDataTreeCandidateNode> node = getNode(id);
if (node.isPresent()) {
return node.get().getDataBefore();
return Optional.empty();
}
- void setAfter(NormalizedNode<?, ?> after) {
+ void setAfter(NormalizedNode after) {
this.after = after;
}
return findNode(id);
}
- void setData(PathArgument id, NormalizedNode<?, ?> node) {
+ void setData(PathArgument id, NormalizedNode node) {
TerminalDataTreeCandidateNode terminalDataTreeCandidateNode = getNode(id).get();
terminalDataTreeCandidateNode.setAfter(node);
}
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final class UnmodifiedLeafCandidateNode extends AbstractAvailableLeafCandidateNode {
- UnmodifiedLeafCandidateNode(final NormalizedNode<?, ?> data) {
+ UnmodifiedLeafCandidateNode(final NormalizedNode data) {
super(data);
}
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return dataOptional();
}
}
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final class WriteLeafCandidateNode extends AbstractWriteCandidate {
- WriteLeafCandidateNode(final NormalizedNode<?, ?> data) {
+ WriteLeafCandidateNode(final NormalizedNode data) {
super(data);
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return Optional.empty();
}
}
*/
package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
-import java.util.Optional;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
/**
* A TreeNode capable of holding child nodes. The fact that any of the children
* changed is tracked by the subtree version.
*/
abstract class AbstractContainerNode extends AbstractTreeNode {
- protected AbstractContainerNode(final NormalizedNode<?, ?> data, final Version version) {
+ protected AbstractContainerNode(final NormalizedNode data, final Version version) {
super(data, version);
}
@SuppressWarnings("unchecked")
- protected final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> castData() {
- return (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) getData();
+ protected final DistinctNodeContainer<?, PathArgument, NormalizedNode> castData() {
+ return (DistinctNodeContainer<?, PathArgument, NormalizedNode>) getData();
}
protected final @Nullable TreeNode getChildFromData(final PathArgument childId) {
return getChildFromData(castData(), childId, getVersion());
}
- static TreeNode getChildFromData(final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> data,
+ static TreeNode getChildFromData(final DistinctNodeContainer<?, PathArgument, NormalizedNode> data,
final PathArgument childId, final Version version) {
- final Optional<NormalizedNode<?, ?>> child = data.getChild(childId);
- return child.isPresent() ? TreeNodeFactory.createTreeNode(child.get(), version) : null;
+ final NormalizedNode child = data.childByArg(childId);
+ return child != null ? TreeNodeFactory.createTreeNode(child, version) : null;
}
}
private final Map<PathArgument, TreeNode> children;
private final Version subtreeVersion;
- protected AbstractModifiedContainerNode(final NormalizedNode<?, ?> data, final Version version,
+ protected AbstractModifiedContainerNode(final NormalizedNode data, final Version version,
final Map<PathArgument, TreeNode> children, final Version subtreeVersion) {
super(data, version);
this.subtreeVersion = requireNonNull(subtreeVersion);
import java.util.Map;
import org.opendaylight.yangtools.util.MapAdaptor;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
/**
* Abstract base for container-based {@link MutableTreeNode}s. It tracks modified nodes in a map and deals with
abstract class AbstractMutableContainerNode implements MutableTreeNode {
private final Version version;
private Map<PathArgument, TreeNode> children;
- private NormalizedNode<?, ?> data;
+ private NormalizedNode data;
private Version subtreeVersion;
protected AbstractMutableContainerNode(final AbstractContainerNode parent,
}
@SuppressWarnings("unchecked")
- protected final NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> getData() {
- return (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>) data;
+ protected final DistinctNodeContainer<?, PathArgument, NormalizedNode> getData() {
+ return (DistinctNodeContainer<?, PathArgument, NormalizedNode>) data;
}
@Override
}
@Override
- public final void setData(final NormalizedNode<?, ?> data) {
+ public final void setData(final NormalizedNode data) {
this.data = requireNonNull(data);
}
*/
if (!version.equals(subtreeVersion)) {
final Map<PathArgument, TreeNode> newChildren = MapAdaptor.getDefaultInstance().optimize(children);
- final int dataSize = getData().size();
+ final int dataSize = getData().body().size();
final int childrenSize = newChildren.size();
if (dataSize != childrenSize) {
verify(dataSize > childrenSize, "Detected %s modified children, data has only %s",
*/
@NonNullByDefault
abstract class AbstractTreeNode implements TreeNode {
- private final NormalizedNode<?, ?> data;
+ private final NormalizedNode data;
private final Version version;
- protected AbstractTreeNode(final NormalizedNode<?, ?> data, final Version version) {
+ protected AbstractTreeNode(final NormalizedNode data, final Version version) {
this.data = requireNonNull(data);
this.version = requireNonNull(version);
}
}
@Override
- public final NormalizedNode<?, ?> getData() {
+ public final NormalizedNode getData() {
return data;
}
* instantiating a child node from data node. Resulting node is not cached.
*/
final class LazyContainerNode extends AbstractModifiedContainerNode {
- LazyContainerNode(final NormalizedNode<?, ?> data, final Version version, final Version subtreeVersion) {
+ LazyContainerNode(final NormalizedNode data, final Version version, final Version subtreeVersion) {
this(data, version, MapAdaptor.getDefaultInstance().initialSnapshot(1), subtreeVersion);
}
- LazyContainerNode(final NormalizedNode<?, ?> data, final Version version,
+ LazyContainerNode(final NormalizedNode data, final Version version,
final Map<PathArgument, TreeNode> children, final Version subtreeVersion) {
super(data, version, children, subtreeVersion);
}
@Override
public MutableTreeNode mutable() {
final Map<PathArgument, TreeNode> snapshot = snapshotChildren();
- if (snapshot.size() == castData().size()) {
+ if (snapshot.size() == castData().body().size()) {
return new MaterializedMutableContainerNode(this, snapshot);
}
return new LazyMutableContainerNode(this, snapshot);
@Override
protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
// Modified children add added by superclass. Here we filter the other children.
- return super.addToStringAttributes(helper).add("untouched", Collections2.filter(castData().getValue(),
+ return super.addToStringAttributes(helper).add("untouched", Collections2.filter(castData().body(),
input -> getModifiedChild(input.getIdentifier()) == null));
}
}
* A fully-modified node -- we know we have all children, so it performs lookups only.
*/
final class MaterializedContainerNode extends AbstractModifiedContainerNode {
- protected MaterializedContainerNode(final NormalizedNode<?, ?> data, final Version version,
+ protected MaterializedContainerNode(final NormalizedNode data, final Version version,
final Map<PathArgument, TreeNode> children, final Version subtreeVersion) {
super(data, version, children, subtreeVersion);
}
* @param data New data component, may not be null.
* @throws NullPointerException if {@code data} is null
*/
- void setData(NormalizedNode<?, ?> data);
+ void setData(NormalizedNode data);
/**
* Set the new subtree version. This is typically invoked when the user
* A container node which has not seen a modification. All nodes underneath it share the same subtree version.
*/
final class SimpleContainerNode extends AbstractContainerNode {
- protected SimpleContainerNode(final NormalizedNode<?, ?> data, final Version version) {
+ protected SimpleContainerNode(final NormalizedNode data, final Version version) {
super(data, version);
}
*
* @return Unmodifiable view of the underlying data.
*/
- NormalizedNode<?, ?> getData();
+ NormalizedNode getData();
/**
* Get a mutable, isolated copy of the node.
*/
package org.opendaylight.yangtools.yang.data.api.schema.tree.spi;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.OrderedNodeContainer;
/**
* @param version data node version
* @return new AbstractTreeNode instance, covering the data tree provided
*/
- public static TreeNode createTreeNode(final NormalizedNode<?, ?> data, final Version version) {
- if (data instanceof NormalizedNodeContainer<?, ?, ?>) {
+ public static TreeNode createTreeNode(final NormalizedNode data, final Version version) {
+ if (data instanceof DistinctNodeContainer<?, ?, ?>) {
@SuppressWarnings("unchecked")
- final NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>> container =
- (NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>>) data;
+ final DistinctNodeContainer<?, ?, NormalizedNode> container =
+ (DistinctNodeContainer<?, ?, NormalizedNode>) data;
return new SimpleContainerNode(container, version);
}
if (data instanceof OrderedNodeContainer<?>) {
- @SuppressWarnings("unchecked")
- final OrderedNodeContainer<NormalizedNode<?, ?>> container =
- (OrderedNodeContainer<NormalizedNode<?, ?>>) data;
- return new SimpleContainerNode(container, version);
+ return new SimpleContainerNode(data, version);
}
return new ValueNode(data, version);
}
final class ValueNode extends AbstractTreeNode {
private static final Logger LOG = LoggerFactory.getLogger(ValueNode.class);
- protected ValueNode(final NormalizedNode<?, ?> data, final Version version) {
+ protected ValueNode(final NormalizedNode data, final Version version) {
super(data, version);
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.yangtools.yang.data.api.schema;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import com.google.common.collect.ImmutableSet;
-import java.util.Collections;
+import java.util.List;
import java.util.Optional;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class NormalizedNodesTest {
@Test
final DataContainerNode<?> mockedDataContainerNode = mock(DataContainerNode.class);
final ContainerNode mockedContainerNode = mock(ContainerNode.class);
- doReturn(Optional.of(mockedContainerNode)).when(mockedDataContainerNode).getChild(any(PathArgument.class));
+ doReturn(mockedContainerNode).when(mockedDataContainerNode).childByArg(any(PathArgument.class));
+ doCallRealMethod().when(mockedDataContainerNode).findChildByArg(any(PathArgument.class));
+
assertEquals(mockedContainerNode, NormalizedNodes.getDirectChild(mockedDataContainerNode, mockedPathArgument)
.get());
- final MapNode mockedMapNode = mock(MapNode.class);
+ final SystemMapNode mockedMapNode = mock(SystemMapNode.class);
final QName listQName = QName.create("test-ns", "test-list");
final QName listKeyQName = QName.create("test-ns", "test-list-key");
final NodeIdentifierWithPredicates nodeIdentifierWithPredicates =
NodeIdentifierWithPredicates.of(listQName, listKeyQName, "str-value");
final MapEntryNode mockedMapEntryNode = mock(MapEntryNode.class);
- doReturn(Optional.of(mockedMapEntryNode)).when(mockedMapNode).getChild(any(NodeIdentifierWithPredicates.class));
+ doReturn(mockedMapEntryNode).when(mockedMapNode).childByArg(any(NodeIdentifierWithPredicates.class));
+ doCallRealMethod().when(mockedMapNode).findChildByArg(any(NodeIdentifierWithPredicates.class));
+
assertEquals(mockedMapEntryNode, NormalizedNodes.getDirectChild(mockedMapNode, nodeIdentifierWithPredicates)
.get());
assertEquals(Optional.empty(), NormalizedNodes.getDirectChild(mockedMapNode, mockedPathArgument));
- final LeafSetNode<?> mockedLeafSetNode = mock(LeafSetNode.class);
+ final SystemLeafSetNode<?> mockedLeafSetNode = mock(SystemLeafSetNode.class);
final QName leafListQName = QName.create("test-ns", "test-leaf-list");
final NodeWithValue<?> nodeWithValue = new NodeWithValue<>(leafListQName, "str-value");
- doReturn(Optional.of(mockedLeafSetEntryNode)).when(mockedLeafSetNode).getChild(any(NodeWithValue.class));
+ doReturn(mockedLeafSetEntryNode).when(mockedLeafSetNode).childByArg(any(NodeWithValue.class));
+ doCallRealMethod().when(mockedLeafSetNode).findChildByArg(any(NodeWithValue.class));
assertEquals(mockedLeafSetEntryNode, NormalizedNodes.getDirectChild(mockedLeafSetNode, nodeWithValue).get());
}
final DataContainerNode<?> mockedDataContainerNode = mock(DataContainerNode.class);
final ContainerNode mockedContainerNode = mock(ContainerNode.class);
final LeafNode<?> mockedLeafNode = mock(LeafNode.class);
- doReturn(Optional.of(mockedContainerNode)).when(mockedDataContainerNode).getChild(any(PathArgument.class));
- doReturn(Optional.of(mockedLeafNode)).when(mockedContainerNode).getChild(any(PathArgument.class));
+ doReturn(mockedContainerNode).when(mockedDataContainerNode).childByArg(any(PathArgument.class));
+ doCallRealMethod().when(mockedDataContainerNode).findChildByArg(any(PathArgument.class));
+ doReturn(mockedLeafNode).when(mockedContainerNode).childByArg(any(PathArgument.class));
+ doCallRealMethod().when(mockedContainerNode).findChildByArg(any(PathArgument.class));
final QName node1QName = QName.create("test-ns", "2016-09-16", "node1");
final QName node2Qname = QName.create("test-ns", "2016-09-16", "node2");
final QName leafNodeQName = QName.create("test-ns", "2016-09-16", "leaf-node");
final NodeIdentifier leafNodeId = new NodeIdentifier(leafNodeQName);
doReturn(leafNodeId).when(mockedLeafNode).getIdentifier();
- doReturn("str-value-1").when(mockedLeafNode).getValue();
+ doReturn("str-value-1").when(mockedLeafNode).body();
String stringTree = NormalizedNodes.toStringTree(mockedLeafNode);
assertNotNull(stringTree);
final AugmentationIdentifier augNodeId = new AugmentationIdentifier(ImmutableSet.of(listQName));
doReturn(augNodeId).when(mockedAugmentationNode).getIdentifier();
- final MapNode mockedMapNode = mock(MapNode.class);
+ final SystemMapNode mockedMapNode = mock(SystemMapNode.class);
final NodeIdentifier listNodeId = new NodeIdentifier(listQName);
doReturn(listNodeId).when(mockedMapNode).getIdentifier();
- doReturn(Collections.singletonList(mockedMapNode)).when(mockedAugmentationNode).getValue();
+ doReturn(List.of(mockedMapNode)).when(mockedAugmentationNode).body();
final MapEntryNode mockedMapEntryNode = mock(MapEntryNode.class);
final NodeIdentifierWithPredicates listEntryNodeId = NodeIdentifierWithPredicates.of(listQName,
leafNodeQName, "key-leaf-value");
doReturn(listEntryNodeId).when(mockedMapEntryNode).getIdentifier();
- doReturn(Collections.singletonList(mockedMapEntryNode)).when(mockedMapNode).getValue();
+ doReturn(List.of(mockedMapEntryNode)).when(mockedMapNode).body();
- doReturn(Collections.singletonList(mockedLeafNode)).when(mockedMapEntryNode).getValue();
+ doReturn(List.of(mockedLeafNode)).when(mockedMapEntryNode).body();
stringTree = NormalizedNodes.toStringTree(mockedAugmentationNode);
assertNotNull(stringTree);
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.net.URI;
-import java.util.Optional;
import java.util.Set;
import javax.xml.transform.dom.DOMSource;
import org.junit.Before;
import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.YangModeledAnyXmlNode;
public class NormalizedNodeWriterTest {
() -> orderedNormalizedNodeWriter.write(mock(NormalizedNode.class)));
assertTrue(ex.getMessage().startsWith("It wasn't possible to serialize node"));
- final NormalizedNode<?, ?> mockedLeafSetEntryNode = mock(LeafSetEntryNode.class);
+ final LeafSetEntryNode<?> mockedLeafSetEntryNode = mock(LeafSetEntryNode.class);
doReturn(new NodeWithValue<>(myLeafList, "leaflist-value-1")).when(mockedLeafSetEntryNode).getIdentifier();
- doReturn("leaflist-value-1").when(mockedLeafSetEntryNode).getValue();
+ doReturn("leaflist-value-1").when(mockedLeafSetEntryNode).body();
assertNotNull(orderedNormalizedNodeWriter.write(mockedLeafSetEntryNode));
- final NormalizedNode<?, ?> mockedLeafNode = mock(LeafNode.class);
- doReturn("leaf-value-1").when(mockedLeafNode).getValue();
+ final LeafNode<?> mockedLeafNode = mock(LeafNode.class);
+ doReturn("leaf-value-1").when(mockedLeafNode).body();
assertNotNull(orderedNormalizedNodeWriter.write(mockedLeafNode));
final DOMSourceAnyxmlNode mockedAnyXmlNode = mock(DOMSourceAnyxmlNode.class);
- doCallRealMethod().when(mockedAnyXmlNode).getValueObjectModel();
- doReturn(new DOMSource()).when(mockedAnyXmlNode).getValue();
+ doCallRealMethod().when(mockedAnyXmlNode).bodyObjectModel();
+ doReturn(new DOMSource()).when(mockedAnyXmlNode).body();
assertNotNull(orderedNormalizedNodeWriter.write(mockedAnyXmlNode));
- final NormalizedNode<?, ?> mockedContainerNode = mock(ContainerNode.class);
+ final NormalizedNode mockedContainerNode = mock(ContainerNode.class);
assertNotNull(orderedNormalizedNodeWriter.write(mockedContainerNode));
- final NormalizedNode<?, ?> mockedYangModeledAnyXmlNode = mock(YangModeledAnyXmlNode.class);
+ final NormalizedNode mockedYangModeledAnyXmlNode = mock(YangModeledAnyXmlNode.class);
assertNotNull(orderedNormalizedNodeWriter.write(mockedYangModeledAnyXmlNode));
final MapEntryNode mockedMapEntryNode = mock(MapEntryNode.class);
doReturn(NodeIdentifierWithPredicates.of(myKeyedList, myKeyLeaf, "list-key-value-1"))
.when(mockedMapEntryNode).getIdentifier();
- doReturn(Optional.empty()).when(mockedMapEntryNode).getChild(any(NodeIdentifier.class));
+ doReturn(null).when(mockedMapEntryNode).childByArg(any(NodeIdentifier.class));
assertNotNull(orderedNormalizedNodeWriter.write(mockedMapEntryNode));
final UnkeyedListEntryNode mockedUnkeyedListEntryNode = mock(UnkeyedListEntryNode.class);
assertNotNull(orderedNormalizedNodeWriter.write(mockedUnkeyedListEntryNode));
- final ChoiceNode mockedChoiceNode = mock(ChoiceNode.class);
- assertNotNull(orderedNormalizedNodeWriter.write(mockedChoiceNode));
+ assertNotNull(orderedNormalizedNodeWriter.write(mock(ChoiceNode.class)));
- final AugmentationNode mockedAugmentationNode = mock(AugmentationNode.class);
- assertNotNull(orderedNormalizedNodeWriter.write(mockedAugmentationNode));
+ assertNotNull(orderedNormalizedNodeWriter.write(mock(AugmentationNode.class)));
final UnkeyedListNode mockedUnkeyedListNode = mock(UnkeyedListNode.class);
- final Set<?> value = ImmutableSet.builder().add(mockedUnkeyedListEntryNode).build();
- doReturn(value).when(mockedUnkeyedListNode).getValue();
+ final Set<?> value = Set.of(mockedUnkeyedListEntryNode);
+ doReturn(value).when(mockedUnkeyedListNode).body();
assertNotNull(orderedNormalizedNodeWriter.write(mockedUnkeyedListNode));
- final OrderedMapNode mockedOrderedMapNode = mock(OrderedMapNode.class);
- assertNotNull(orderedNormalizedNodeWriter.write(mockedOrderedMapNode));
+ assertNotNull(orderedNormalizedNodeWriter.write(mock(UserMapNode.class)));
- final MapNode mockedMapNode = mock(MapNode.class);
- assertNotNull(orderedNormalizedNodeWriter.write(mockedMapNode));
+ assertNotNull(orderedNormalizedNodeWriter.write(mock(SystemMapNode.class)));
- final OrderedLeafSetNode<?> mockedOrderedLeafSetNode = mock(OrderedLeafSetNode.class);
- assertNotNull(orderedNormalizedNodeWriter.write(mockedOrderedLeafSetNode));
+ assertNotNull(orderedNormalizedNodeWriter.write(mock(UserLeafSetNode.class)));
- final LeafSetNode<?> mockedLeafSetNode = mock(LeafSetNode.class);
- assertNotNull(orderedNormalizedNodeWriter.write(mockedLeafSetNode));
+ assertNotNull(orderedNormalizedNodeWriter.write(mock(SystemLeafSetNode.class)));
orderedNormalizedNodeWriter.flush();
orderedNormalizedNodeWriter.close();
public class DataTreeCandidateNodesTest {
@Test
public void testFromNormalizedNode() {
- final NormalizedNode<?, ?> mockedNormalizedNode = mock(NormalizedNode.class);
+ final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
final DataTreeCandidateNode dataTreeCandidateNode = DataTreeCandidateNodes.written(mockedNormalizedNode);
assertNotNull(dataTreeCandidateNode);
}
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).getModificationType();
- final NormalizedNode<?, ?> mockedNormalizedNode = mock(NormalizedNode.class);
+ final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
doReturn(Optional.of(mockedNormalizedNode)).when(mockedDataTreeCandidateNode).getDataAfter();
DataTreeCandidateNodes.applyToCursor(mockedCursor, mockedDataTreeCandidateNode);
verify(mockedCursor, times(1)).write(isNull(), any(NormalizedNode.class));
final DataTreeCandidateNode mockedChildNode2 = mock(DataTreeCandidateNode.class);
doReturn(ModificationType.WRITE).when(mockedChildNode2).getModificationType();
- final NormalizedNode<?, ?> mockedNormalizedNode = mock(NormalizedNode.class);
+ final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
doReturn(Optional.of(mockedNormalizedNode)).when(mockedChildNode2).getDataAfter();
final DataTreeCandidateNode mockedChildNode3 = mock(DataTreeCandidateNode.class);
final DataTreeModificationCursor mockedCursor = mock(DataTreeModificationCursor.class);
doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).getModificationType();
- final NormalizedNode<?, ?> mockedNormalizedNode = mock(NormalizedNode.class);
+ final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
doReturn(Optional.of(mockedNormalizedNode)).when(mockedDataTreeCandidateNode).getDataAfter();
DataTreeCandidateNodes.applyRootedNodeToCursor(mockedCursor, mockedRootPath, mockedDataTreeCandidateNode);
verify(mockedCursor, times(1)).write(isNull(), any(NormalizedNode.class));
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
public class DataTreeCandidatesAggregateTest {
@Test
public void testLeafUnmodifiedUnmodified() {
- NormalizedNode<?, ?> normalizedNode1 = normalizedNode("value1");
- NormalizedNode<?, ?> normalizedNode2 = normalizedNode("value1");
- NormalizedNode<?, ?> normalizedNode3 = normalizedNode("value1");
+ NormalizedNode normalizedNode1 = normalizedNode("value1");
+ NormalizedNode normalizedNode2 = normalizedNode("value1");
+ NormalizedNode normalizedNode3 = normalizedNode("value1");
DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, normalizedNode2,
ModificationType.UNMODIFIED);
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(Arrays.asList(candidate1, candidate2));
assertEquals(ModificationType.UNMODIFIED, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().getValue());
- assertEquals("value1", aggregationResult.getRootNode().getDataAfter().get().getValue());
+ assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().body());
+ assertEquals("value1", aggregationResult.getRootNode().getDataAfter().get().body());
}
@Test
public void testLeaftUnmodifiedWrite() {
- NormalizedNode<?, ?> normalizedNode1 = normalizedNode("value1");
- NormalizedNode<?, ?> normalizedNode2 = normalizedNode("value1");
- NormalizedNode<?, ?> normalizedNode3 = normalizedNode("value2");
+ NormalizedNode normalizedNode1 = normalizedNode("value1");
+ NormalizedNode normalizedNode2 = normalizedNode("value1");
+ NormalizedNode normalizedNode3 = normalizedNode("value2");
DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, normalizedNode2,
ModificationType.UNMODIFIED);
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(Arrays.asList(candidate1, candidate2));
assertEquals(ModificationType.WRITE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().getValue());
- assertEquals("value2", aggregationResult.getRootNode().getDataAfter().get().getValue());
+ assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().body());
+ assertEquals("value2", aggregationResult.getRootNode().getDataAfter().get().body());
}
@Test
public void testLeafUnmodifiedDelete() {
- NormalizedNode<?, ?> normalizedNode1 = normalizedNode("value1");
- NormalizedNode<?, ?> normalizedNode2 = normalizedNode("value1");
+ NormalizedNode normalizedNode1 = normalizedNode("value1");
+ NormalizedNode normalizedNode2 = normalizedNode("value1");
DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, normalizedNode2,
ModificationType.UNMODIFIED);
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(Arrays.asList(candidate1, candidate2));
assertEquals(ModificationType.DELETE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().getValue());
+ assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().body());
assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
}
@Test
public void testLeafWriteUnmodified() {
- NormalizedNode<?, ?> normalizedNode1 = normalizedNode("value1");
- NormalizedNode<?, ?> normalizedNode2 = normalizedNode("value2");
+ NormalizedNode normalizedNode1 = normalizedNode("value1");
+ NormalizedNode normalizedNode2 = normalizedNode("value2");
DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, normalizedNode2,
ModificationType.WRITE);
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(Arrays.asList(candidate1, candidate2));
assertEquals(ModificationType.WRITE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().getValue());
- assertEquals("value2", aggregationResult.getRootNode().getDataAfter().get().getValue());
+ assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().body());
+ assertEquals("value2", aggregationResult.getRootNode().getDataAfter().get().body());
}
@Test
public void testLeafWriteWrite() {
- NormalizedNode<?, ?> normalizedNode1 = normalizedNode("value1");
- NormalizedNode<?, ?> normalizedNode2 = normalizedNode("value2");
- NormalizedNode<?, ?> normalizedNode3 = normalizedNode("value3");
+ NormalizedNode normalizedNode1 = normalizedNode("value1");
+ NormalizedNode normalizedNode2 = normalizedNode("value2");
+ NormalizedNode normalizedNode3 = normalizedNode("value3");
DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, normalizedNode2,
ModificationType.WRITE);
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(Arrays.asList(candidate1, candidate2));
assertEquals(ModificationType.WRITE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().getValue());
- assertEquals("value3", aggregationResult.getRootNode().getDataAfter().get().getValue());
+ assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().body());
+ assertEquals("value3", aggregationResult.getRootNode().getDataAfter().get().body());
}
@Test
public void testLeafWriteDeleteWithoutChanges() {
- NormalizedNode<?, ?> normalizedNode = normalizedNode("value1");
+ NormalizedNode normalizedNode = normalizedNode("value1");
DataTreeCandidateNode node1 = dataTreeCandidateNode(null, normalizedNode,
ModificationType.WRITE);
@Test
public void testLeafWriteDelete() {
- NormalizedNode<?, ?> normalizedNode1 = normalizedNode("value1");
- NormalizedNode<?, ?> normalizedNode2 = normalizedNode("value2");
+ NormalizedNode normalizedNode1 = normalizedNode("value1");
+ NormalizedNode normalizedNode2 = normalizedNode("value2");
DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, normalizedNode2,
ModificationType.WRITE);
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(Arrays.asList(candidate1, candidate2));
assertEquals(ModificationType.DELETE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().getValue());
+ assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().body());
assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
}
@Test
public void testLeafDeleteUnmodified() {
- NormalizedNode<?, ?> normalizedNode = normalizedNode("value");
+ NormalizedNode normalizedNode = normalizedNode("value");
DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode, null,
ModificationType.DELETE);
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(Arrays.asList(candidate1, candidate2));
assertEquals(ModificationType.DELETE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value", aggregationResult.getRootNode().getDataBefore().get().getValue());
+ assertEquals("value", aggregationResult.getRootNode().getDataBefore().get().body());
assertEquals(Optional.empty(), aggregationResult.getRootNode().getDataAfter());
}
@Test
public void testLeafDeleteWrite() {
- NormalizedNode<?, ?> normalizedNode1 = normalizedNode("value1");
- NormalizedNode<?, ?> normalizedNode2 = normalizedNode("value2");
+ NormalizedNode normalizedNode1 = normalizedNode("value1");
+ NormalizedNode normalizedNode2 = normalizedNode("value2");
DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, null,
ModificationType.DELETE);
DataTreeCandidate aggregationResult = DataTreeCandidates.aggregate(Arrays.asList(candidate1, candidate2));
assertEquals(ModificationType.WRITE, aggregationResult.getRootNode().getModificationType());
- assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().getValue());
- assertEquals("value2", aggregationResult.getRootNode().getDataAfter().get().getValue());
+ assertEquals("value1", aggregationResult.getRootNode().getDataBefore().get().body());
+ assertEquals("value2", aggregationResult.getRootNode().getDataAfter().get().body());
}
@Test
public void testLeafDeleteDelete() {
- NormalizedNode<?, ?> normalizedNode1 = normalizedNode("value1");
+ NormalizedNode normalizedNode1 = normalizedNode("value1");
DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, null,
ModificationType.DELETE);
@Test
public void testLeafDeleteDisappear() {
- NormalizedNode<?, ?> normalizedNode1 = normalizedNode("value1");
+ NormalizedNode normalizedNode1 = normalizedNode("value1");
DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, null,
ModificationType.DELETE);
@Test
public void testLeafDeleteSubtreeModified() {
- NormalizedNode<?, ?> normalizedNode1 = normalizedNode("value1");
+ NormalizedNode normalizedNode1 = normalizedNode("value1");
DataTreeCandidateNode node1 = dataTreeCandidateNode(normalizedNode1, null,
ModificationType.DELETE);
@Test
public void testUnmodifiedUnmodified() throws NoSuchFieldException {
- NormalizedNode<?, ?> parentNode = normalizedNode("container");
- NormalizedNode<?, ?> childNode = normalizedNode("child");
+ NormalizedNode parentNode = normalizedNode("container");
+ NormalizedNode childNode = normalizedNode("child");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode, parentNode,
ModificationType.UNMODIFIED);
@Test
public void testUnmodifiedDelete() {
- NormalizedNode<?, ?> parentNode = normalizedNode("container");
- NormalizedNode<?, ?> childNode = normalizedNode("child");
+ NormalizedNode parentNode = normalizedNode("container");
+ NormalizedNode childNode = normalizedNode("child");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode, parentNode,
ModificationType.UNMODIFIED);
@Test
public void testUnmodifiedWrite() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container2");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode2 = normalizedNode("container2");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode1,
ModificationType.UNMODIFIED);
@Test
public void testUnmodifiedSubtreeModifiedWithoutDataBefore() {
- NormalizedNode<?, ?> parentNode = normalizedNode("container");
- NormalizedNode<?, ?> childNode = normalizedNode("child");
+ NormalizedNode parentNode = normalizedNode("container");
+ NormalizedNode childNode = normalizedNode("child");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, null,
ModificationType.UNMODIFIED);
//FIXME
@Test
public void testUnmodifiedSubtreeModified() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode2 = normalizedNode("container1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode1,
ModificationType.UNMODIFIED);
@Test
public void testUnmodifiedAppearedWithDataBefore() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode2 = normalizedNode("container1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode1,
ModificationType.UNMODIFIED);
//FIXME
@Test
public void testUnmodifiedAppeared() {
- NormalizedNode<?, ?> parentNode = normalizedNode("container");
- NormalizedNode<?, ?> childNode = normalizedNode("child");
+ NormalizedNode parentNode = normalizedNode("container");
+ NormalizedNode childNode = normalizedNode("child");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, null,
ModificationType.UNMODIFIED);
@Test
public void testUnmodifiedDisappearWithoutDataBefore() {
- NormalizedNode<?, ?> parentNode = normalizedNode("container");
- NormalizedNode<?, ?> childNode = normalizedNode("child");
+ NormalizedNode parentNode = normalizedNode("container");
+ NormalizedNode childNode = normalizedNode("child");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, null,
ModificationType.UNMODIFIED);
@Test
public void testUnmodifiedDisappear() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode childNode1 = normalizedNode("child1");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode1,
ModificationType.UNMODIFIED);
@Test
public void testDeleteUnmodified() {
- NormalizedNode<?, ?> parentNode = normalizedNode("container");
- NormalizedNode<?, ?> childNode = normalizedNode("child");
+ NormalizedNode parentNode = normalizedNode("container");
+ NormalizedNode childNode = normalizedNode("child");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode, null,
ModificationType.DELETE);
@Test
public void testDeleteWrite() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container2");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode parentNode2 = normalizedNode("container2");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, null,
ModificationType.DELETE);
@Test
public void testDeleteAppear() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container2");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode parentNode2 = normalizedNode("container2");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, null,
ModificationType.DELETE);
@Test
public void testWriteUnmodified() {
- NormalizedNode<?, ?> parentNode = normalizedNode("container");
- NormalizedNode<?, ?> childNode = normalizedNode("child");
+ NormalizedNode parentNode = normalizedNode("container");
+ NormalizedNode childNode = normalizedNode("child");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, parentNode,
ModificationType.WRITE);
@Test
public void testWriteDeleteWithoutChanges() {
- NormalizedNode<?, ?> parentNode = normalizedNode("container");
- NormalizedNode<?, ?> childNode = normalizedNode("child");
+ NormalizedNode parentNode = normalizedNode("container");
+ NormalizedNode childNode = normalizedNode("child");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, parentNode,
ModificationType.WRITE);
@Test
public void testWriteDelete() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container2");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode parentNode2 = normalizedNode("container2");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode2,
ModificationType.WRITE);
@Test
public void testWriteWrite() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container2");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode parentNode2 = normalizedNode("container2");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, parentNode1,
ModificationType.WRITE);
@Test
public void testWriteSubtreeModified() {
- NormalizedNode<?, ?> parentNode = normalizedNode("container");
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container1");
- NormalizedNode<?, ?> childNode = normalizedNode("child");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode = normalizedNode("container");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode parentNode2 = normalizedNode("container1");
+ NormalizedNode childNode = normalizedNode("child");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode, parentNode1,
ModificationType.WRITE);
@Test
public void testWriteAppear() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container2");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
- NormalizedNode<?, ?> childNode3 = normalizedNode("child3");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode parentNode2 = normalizedNode("container2");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
+ NormalizedNode childNode3 = normalizedNode("child3");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode2,
ModificationType.WRITE);
@Test
public void testWriteDisappearWithoutChanges() {
- NormalizedNode<?, ?> parentNode = normalizedNode("container");
- NormalizedNode<?, ?> childNode = normalizedNode("child");
+ NormalizedNode parentNode = normalizedNode("container");
+ NormalizedNode childNode = normalizedNode("child");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, parentNode,
ModificationType.WRITE);
@Test
public void testWriteDisappear() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container2");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode parentNode2 = normalizedNode("container2");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode2,
ModificationType.WRITE);
@Test
public void testSubtreeModifiedUnmodified() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container1");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode parentNode2 = normalizedNode("container1");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode2,
ModificationType.SUBTREE_MODIFIED);
@Test
public void testSubtreeModifiedDelete() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container1");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode parentNode2 = normalizedNode("container1");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode2,
ModificationType.SUBTREE_MODIFIED);
@Test
public void testSubtreeModifiedWrite() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("value2");
- NormalizedNode<?, ?> childNode = normalizedNode("childNode");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode parentNode2 = normalizedNode("value2");
+ NormalizedNode childNode = normalizedNode("childNode");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode1,
ModificationType.SUBTREE_MODIFIED);
@Test
public void testSubtreeModifiedSubtreeModified() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> childNode = normalizedNode("childNode");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode childNode = normalizedNode("childNode");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode1,
ModificationType.SUBTREE_MODIFIED);
@Test
public void testSubtreeModifiedAppear() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("value2");
- NormalizedNode<?, ?> childNode = normalizedNode("childNode");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode parentNode2 = normalizedNode("value2");
+ NormalizedNode childNode = normalizedNode("childNode");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode1,
ModificationType.SUBTREE_MODIFIED);
@Test
public void testSubtreeModifiedDisappear() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> childNode = normalizedNode("childNode");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode childNode = normalizedNode("childNode");
+ NormalizedNode childNode1 = normalizedNode("child1");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, parentNode1,
ModificationType.SUBTREE_MODIFIED);
@Test
public void testAppearedUnmodified() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode childNode1 = normalizedNode("child1");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, parentNode1,
ModificationType.APPEARED);
@Test
public void testAppearedDelete() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode childNode1 = normalizedNode("child1");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, parentNode1,
ModificationType.APPEARED);
@Test
public void testAppearedWriteWithoutChanges() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("value2");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode parentNode2 = normalizedNode("value2");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, parentNode1,
ModificationType.APPEARED);
@Test
public void testAppearedSubtreeModified() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, parentNode1,
ModificationType.APPEARED);
@Test
public void testAppearedAppeared() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode childNode1 = normalizedNode("child1");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, parentNode1,
ModificationType.APPEARED);
@Test
public void testAppearedDisappeared() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode childNode1 = normalizedNode("child1");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(null, parentNode1,
ModificationType.APPEARED);
@Test
public void testDisappearedUnmodified() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode childNode1 = normalizedNode("child1");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, null,
ModificationType.DISAPPEARED);
@Test
public void testDisappearedDelete() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode childNode1 = normalizedNode("child1");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, null,
ModificationType.DISAPPEARED);
@Test
public void testDisappearedWrite() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container1");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container2");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container1");
+ NormalizedNode parentNode2 = normalizedNode("container2");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, null,
ModificationType.DISAPPEARED);
@Test
public void testDisappearedSubtreeModified() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, null,
ModificationType.DISAPPEARED);
@Test
public void testDisappearedAppeared() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> parentNode2 = normalizedNode("container");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
- NormalizedNode<?, ?> childNode2 = normalizedNode("child2");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode parentNode2 = normalizedNode("container");
+ NormalizedNode childNode1 = normalizedNode("child1");
+ NormalizedNode childNode2 = normalizedNode("child2");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, null,
ModificationType.DISAPPEARED);
@Test
public void testDisappearedDisappear() {
- NormalizedNode<?, ?> parentNode1 = normalizedNode("container");
- NormalizedNode<?, ?> childNode1 = normalizedNode("child1");
+ NormalizedNode parentNode1 = normalizedNode("container");
+ NormalizedNode childNode1 = normalizedNode("child1");
TerminalDataTreeCandidateNode node1 = dataTreeCandidateNode(parentNode1, null,
ModificationType.DISAPPEARED);
() -> DataTreeCandidates.aggregate(Arrays.asList(candidate1, candidate2)));
}
- private static NormalizedNode<?, ?> normalizedNode(final String value) {
- NormalizedNode<?, ?> node = mock(NormalizedNode.class);
- doReturn(value).when(node).getValue();
+ private static LeafNode<String> normalizedNode(final String value) {
+ LeafNode<String> node = mock(LeafNode.class);
+ doReturn(value).when(node).body();
return node;
}
- private static TerminalDataTreeCandidateNode dataTreeCandidateNode(final NormalizedNode<?, ?> before,
- final NormalizedNode<?, ?> after,
+ private static TerminalDataTreeCandidateNode dataTreeCandidateNode(final NormalizedNode before,
+ final NormalizedNode after,
final ModificationType modification) {
TerminalDataTreeCandidateNode dataTreeCandidateNode = mock(TerminalDataTreeCandidateNode.class);
doReturn(null).when(dataTreeCandidateNode).getIdentifier();
@Test
public void testFromNormalizedNode() {
final YangInstanceIdentifier mockedRootPath = mock(YangInstanceIdentifier.class);
- final NormalizedNode<?, ?> mockedNormalizedNode = mock(NormalizedNode.class);
+ final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
final DataTreeCandidate dataTreeCandidate = DataTreeCandidates.fromNormalizedNode(mockedRootPath,
mockedNormalizedNode);
doReturn(mockedDataTreeCandidateNode).when(mockedDataTreeCandidate).getRootNode();
final YangInstanceIdentifier mockedRootPath = mock(YangInstanceIdentifier.class);
doReturn(mockedRootPath).when(mockedDataTreeCandidate).getRootPath();
- final NormalizedNode<?, ?> mockedNormalizedNode = mock(NormalizedNode.class);
+ final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
doReturn(Optional.of(mockedNormalizedNode)).when(mockedDataTreeCandidateNode).getDataAfter();
doReturn(ModificationType.WRITE).when(mockedDataTreeCandidateNode).getModificationType();
final DataTreeCandidateNode mockedChildNode2 = mock(DataTreeCandidateNode.class);
doReturn(ModificationType.WRITE).when(mockedChildNode2).getModificationType();
- final NormalizedNode<?, ?> mockedNormalizedNode = mock(NormalizedNode.class);
+ final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
doReturn(Optional.of(mockedNormalizedNode)).when(mockedChildNode2).getDataAfter();
final PathArgument mockedPathArgument2 = mock(PathArgument.class);
doReturn(mockedPathArgument2).when(mockedChildNode2).getIdentifier();
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doCallRealMethod;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import java.util.Optional;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
public class NormalizedNodeDataTreeCandidateNodeTest {
@Test
public void testNormalizedNodeDataTreeCandidateNode() {
- final NormalizedNode<?, ?> mockedNormalizedNode = mock(NormalizedNode.class);
+ final NormalizedNode mockedNormalizedNode = mock(NormalizedNode.class);
final NormalizedNodeDataTreeCandidateNode normalizedNodeDataTreeCandidateNode = new
NormalizedNodeDataTreeCandidateNode(mockedNormalizedNode);
assertEquals(Optional.of(mockedNormalizedNode), normalizedNodeDataTreeCandidateNode.getDataAfter());
assertEquals(Optional.empty(), normalizedNodeDataTreeCandidateNode.getDataBefore());
- final NormalizedNodeContainer mockedNormalizedNodeContainer = mock(NormalizedNodeContainer.class);
+ final DistinctNodeContainer mockedNormalizedNodeContainer = mock(DistinctNodeContainer.class);
final NormalizedNodeDataTreeCandidateNode normalizedNodeDataTreeCandidateNode2 = new
NormalizedNodeDataTreeCandidateNode(mockedNormalizedNodeContainer);
- final NormalizedNode<?, ?> mockedChildNormNode1 = mock(NormalizedNode.class);
- final NormalizedNode<?, ?> mockedChildNormNode2 = mock(NormalizedNode.class);
- final Collection<NormalizedNode<?, ?>> mockedChildNodes = Arrays.asList(mockedChildNormNode1,
+ final NormalizedNode mockedChildNormNode1 = mock(NormalizedNode.class);
+ final NormalizedNode mockedChildNormNode2 = mock(NormalizedNode.class);
+ final Collection<NormalizedNode> mockedChildNodes = Arrays.asList(mockedChildNormNode1,
mockedChildNormNode2, null);
- doReturn(mockedChildNodes).when(mockedNormalizedNodeContainer).getValue();
+ doReturn(mockedChildNodes).when(mockedNormalizedNodeContainer).body();
final Collection<DataTreeCandidateNode> childNodes2 = normalizedNodeDataTreeCandidateNode2.getChildNodes();
assertEquals(3, childNodes2.size());
- doReturn(Optional.empty()).when(mockedNormalizedNodeContainer).getChild(any(PathArgument.class));
+ doReturn(null).when(mockedNormalizedNodeContainer).childByArg(any(PathArgument.class));
+ doCallRealMethod().when(mockedNormalizedNodeContainer).findChildByArg(any(PathArgument.class));
assertEquals(Optional.empty(), normalizedNodeDataTreeCandidateNode2.getModifiedChild(mockedPathArgument));
- doReturn(Optional.of(mockedChildNormNode1)).when(mockedNormalizedNodeContainer).getChild(
- any(PathArgument.class));
+ doReturn(mockedChildNormNode1).when(mockedNormalizedNodeContainer).childByArg(any(PathArgument.class));
assertTrue(normalizedNodeDataTreeCandidateNode2.getModifiedChild(mockedPathArgument).isPresent());
}
}
public void testDuplicate() {
final LeafNode<?> leafNode = mock(LeafNode.class);
final ContainerNode containerNode = mock(ContainerNode.class);
- final Map<NormalizedNode<?, ?>, DuplicateEntry> normalizedNodeDuplicateEntryMapNode = NormalizedNodes
+ final Map<NormalizedNode, DuplicateEntry> normalizedNodeDuplicateEntryMapNode = NormalizedNodes
.findDuplicates(leafNode);
- final Map<NormalizedNode<?, ?>, DuplicateEntry> normalizedNodeDuplicateEntryMapContainer = NormalizedNodes
+ final Map<NormalizedNode, DuplicateEntry> normalizedNodeDuplicateEntryMapContainer = NormalizedNodes
.findDuplicates(containerNode);
assertEquals(0, normalizedNodeDuplicateEntryMapNode.size());
assertEquals(0, normalizedNodeDuplicateEntryMapContainer.size());
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
public class TreeNodeFactoryTest {
- private static void checkTreeNode(final TreeNode node, final NormalizedNode<?, ?> data, final Version version) {
+ private static void checkTreeNode(final TreeNode node, final NormalizedNode data, final Version version) {
assertSame(data, node.getData());
assertSame(version, node.getSubtreeVersion());
assertSame(version, node.getVersion());
@Test
public void testOrderedNodeContainer() {
- final OrderedMapNode data = Mockito.mock(OrderedMapNode.class);
+ final UserMapNode data = Mockito.mock(UserMapNode.class);
final Version version = Version.initial();
final TreeNode node = TreeNodeFactory.createTreeNode(data, version);
}
@Override
- public final Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public final Optional<NormalizedNode> getDataBefore() {
throw new UnsupportedOperationException("Before-image not available after serialization");
}
}
}
@Override
- public final void writeNormalizedNode(final NormalizedNode<?, ?> node) throws IOException {
+ public final void writeNormalizedNode(final NormalizedNode node) throws IOException {
ensureHeaderWritten();
if (normalizedNodeWriter == null) {
normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(this);
}
@Override
- public final Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public final Optional<NormalizedNode> getDataAfter() {
return Optional.empty();
}
}
@Override
- public final NormalizedNode<?, ?> readNormalizedNode() throws IOException {
+ public final NormalizedNode readNormalizedNode() throws IOException {
return delegate().readNormalizedNode();
}
@Override
- public final NormalizedNode<?, ?> readNormalizedNode(final ReusableStreamReceiver receiver) throws IOException {
+ public final NormalizedNode readNormalizedNode(final ReusableStreamReceiver receiver) throws IOException {
return delegate().readNormalizedNode(receiver);
}
}
@Override
- public final Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public final Optional<NormalizedNode> getDataAfter() {
throw new UnsupportedOperationException("After-image not available after serialization");
}
* @throws IOException if an error occurs
* @throws IllegalStateException if the dictionary has been detached
*/
- default NormalizedNode<?, ?> readNormalizedNode() throws IOException {
+ default NormalizedNode readNormalizedNode() throws IOException {
return readNormalizedNode(ReusableImmutableNormalizedNodeStreamWriter.create());
}
* @throws IOException if an error occurs
* @throws IllegalStateException if the dictionary has been detached
*/
- default NormalizedNode<?, ?> readNormalizedNode(final ReusableStreamReceiver receiver) throws IOException {
+ default NormalizedNode readNormalizedNode(final ReusableStreamReceiver receiver) throws IOException {
try {
streamNormalizedNode(receiver);
return receiver.getResult();
*/
NormalizedNodeStreamVersion getVersion() throws IOException;
- default Optional<NormalizedNode<?, ?>> readOptionalNormalizedNode() throws IOException {
+ default Optional<NormalizedNode> readOptionalNormalizedNode() throws IOException {
return readBoolean() ? Optional.of(readNormalizedNode()) : Optional.empty();
}
public interface NormalizedNodeDataOutput extends AutoCloseable, DataOutput {
void writeQName(QName qname) throws IOException;
- void writeNormalizedNode(NormalizedNode<?, ?> normalizedNode) throws IOException;
+ void writeNormalizedNode(NormalizedNode normalizedNode) throws IOException;
void writePathArgument(PathArgument pathArgument) throws IOException;
@Override
void close() throws IOException;
- default void writeOptionalNormalizedNode(final @Nullable NormalizedNode<?, ?> normalizedNode) throws IOException {
+ default void writeOptionalNormalizedNode(final @Nullable NormalizedNode normalizedNode) throws IOException {
if (normalizedNode != null) {
writeBoolean(true);
writeNormalizedNode(normalizedNode);
},
/**
* First shipping is Magnesium. Does not support {@link BigInteger} mirroring it being superseded by {@link Uint64}
- * in {@link ValueNode#getValue()}.
+ * in {@link ValueNode#body()}.
*/
MAGNESIUM {
@Override
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public Optional<NormalizedNode> getDataAfter() {
throw new UnsupportedOperationException("After-image not available after serialization");
}
@Parameter(0)
public NormalizedNodeStreamVersion version;
- final <T extends NormalizedNode<?, ?>> T assertEquals(final T node, final int expectedSize) {
+ final <T extends NormalizedNode> T assertEquals(final T node, final int expectedSize) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (NormalizedNodeDataOutput nnout = version.newDataOutput(ByteStreams.newDataOutput(baos))) {
nnout.writeNormalizedNode(node);
final byte[] bytes = baos.toByteArray();
Assert.assertEquals(expectedSize, bytes.length);
- final NormalizedNode<?, ?> deser;
+ final NormalizedNode deser;
try {
deser = NormalizedNodeDataInput.newDataInput(ByteStreams.newDataInput(bytes)).readNormalizedNode();
} catch (IOException e) {
}
final <T> T assertEquals(final T value, final int expectedSize) {
- return assertEquals(ImmutableNodes.leafNode(TestModel.TEST_QNAME, value), expectedSize).getValue();
+ return assertEquals(ImmutableNodes.leafNode(TestModel.TEST_QNAME, value), expectedSize).body();
}
final <T extends PathArgument> T assertEquals(final T arg, final int expectedSize) {
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
NormalizedNodeDataOutput nnout = version.newDataOutput(ByteStreams.newDataOutput(bos));
- NormalizedNode<?, ?> testContainer = createTestContainer();
+ NormalizedNode testContainer = createTestContainer();
nnout.writeNormalizedNode(testContainer);
QName toaster = QName.create("http://netconfcentral.org/ns/toaster","2009-11-20","toaster");
NormalizedNodeDataInput nnin = NormalizedNodeDataInput.newDataInput(ByteStreams.newDataInput(bytes));
- NormalizedNode<?, ?> node = nnin.readNormalizedNode();
+ NormalizedNode node = nnin.readNormalizedNode();
Assert.assertEquals(testContainer, node);
node = nnin.readNormalizedNode();
Assert.assertEquals(toasterContainer, node);
}
- private NormalizedNode<?, ?> createTestContainer() {
+ private NormalizedNode createTestContainer() {
byte[] bytes1 = {1, 2, 3};
LeafSetEntryNode<Object> entry1 = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
new NodeWithValue<>(TestModel.BINARY_LEAF_LIST_QNAME, bytes1)).withValue(bytes1).build();
NormalizedNodeDataOutput writer = version.newDataOutput(
ByteStreams.newDataOutput(bos));
- NormalizedNode<?, ?> testContainer = TestModel.createBaseTestContainerBuilder(uint64).build();
+ NormalizedNode testContainer = TestModel.createBaseTestContainerBuilder(uint64).build();
writer.writeNormalizedNode(testContainer);
YangInstanceIdentifier path = YangInstanceIdentifier.builder(TestModel.TEST_PATH)
NormalizedNodeDataInput reader = NormalizedNodeDataInput.newDataInput(ByteStreams.newDataInput(bytes));
- NormalizedNode<?,?> node = reader.readNormalizedNode();
+ NormalizedNode node = reader.readNormalizedNode();
Assert.assertEquals(testContainer, node);
YangInstanceIdentifier newPath = reader.readYangInstanceIdentifier();
@Test
public void testWithSerializable() {
- NormalizedNode<?, ?> input = TestModel.createTestContainer(uint64);
+ NormalizedNode input = TestModel.createTestContainer(uint64);
SampleNormalizedNodeSerializable serializable = new SampleNormalizedNodeSerializable(version, input);
SampleNormalizedNodeSerializable clone = clone(serializable);
Assert.assertEquals(input, clone.getInput());
assertEquals("http://www.w3.org/TR/html4/", xmlNode.getNamespaceURI());
- NormalizedNode<?, ?> anyXmlContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
+ NormalizedNode anyXmlContainer = ImmutableContainerNodeBuilder.create().withNodeIdentifier(
new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)).withChild(
Builders.anyXmlBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.ANY_XML_QNAME))
.withValue(new DOMSource(xmlNode)).build()).build();
ContainerNode deserialized = (ContainerNode)nnin.readNormalizedNode();
- Optional<DataContainerChild<? extends PathArgument, ?>> child =
- deserialized.getChild(new NodeIdentifier(TestModel.ANY_XML_QNAME));
+ Optional<DataContainerChild> child = deserialized.findChildByArg(new NodeIdentifier(TestModel.ANY_XML_QNAME));
assertEquals("AnyXml child present", true, child.isPresent());
StreamResult xmlOutput = new StreamResult(new StringWriter());
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- transformer.transform(((DOMSourceAnyxmlNode)child.get()).getValue(), xmlOutput);
+ transformer.transform(((DOMSourceAnyxmlNode)child.get()).body(), xmlOutput);
assertEquals("XML", xml, xmlOutput.getWriter().toString());
assertEquals("http://www.w3.org/TR/html4/",
- ((DOMSourceAnyxmlNode)child.get()).getValue().getNode().getNamespaceURI());
+ ((DOMSourceAnyxmlNode)child.get()).body().getNode().getNamespaceURI());
}
@Test
*/
@Test
public void testHugeEntries() throws IOException {
- final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders.mapBuilder()
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder = Builders.mapBuilder()
.withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME));
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> entryBuilder =
Builders.mapEntryBuilder().withChild(ImmutableNodes.leafNode(TestModel.DESC_QNAME, (byte) 42));
.build());
}
- final MapNode expected = mapBuilder.build();
+ final SystemMapNode expected = mapBuilder.build();
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (NormalizedNodeDataOutput nnout = version.newDataOutput(ByteStreams.newDataOutput(bos))) {
private static final long serialVersionUID = 1L;
private transient NormalizedNodeStreamVersion version;
- private NormalizedNode<?, ?> input;
+ private NormalizedNode input;
public SampleNormalizedNodeSerializable(final NormalizedNodeStreamVersion version,
- final NormalizedNode<?, ?> input) {
+ final NormalizedNode input) {
this.version = requireNonNull(version);
this.input = input;
}
- public NormalizedNode<?, ?> getInput() {
+ public NormalizedNode getInput() {
return input;
}
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
final LeafSetEntryNode<Object> puma = ImmutableLeafSetEntryNodeBuilder.create().withNodeIdentifier(
new NodeWithValue<>(SHOE_QNAME, "puma")).withValue("puma").build();
- final LeafSetNode<Object> shoes = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(
+ final SystemLeafSetNode<Object> shoes = ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(
new NodeIdentifier(SHOE_QNAME)).withChild(nike).withChild(puma).build();
// Test a leaf-list where each entry contains an identity
TEST_QNAME, "capability"), DESC_QNAME))
.withValue(DESC_QNAME).build();
- final LeafSetNode<Object> capabilities =
+ final SystemLeafSetNode<Object> capabilities =
ImmutableLeafSetNodeBuilder
.create()
.withNodeIdentifier(
.withNodeIdentifier(
new NodeWithValue<>(QName.create(
TEST_QNAME, "number"), 15)).withValue(15).build();
- final LeafSetNode<Object> numbers =
+ final SystemLeafSetNode<Object> numbers =
ImmutableLeafSetNodeBuilder
.create()
.withNodeIdentifier(
abstract String expectedUint64();
- final NormalizedNode<?, ?> fromJSON(final String input) throws IOException {
+ final NormalizedNode fromJSON(final String input) throws IOException {
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, codecFactory());
return result.getResult();
}
- private String toJSON(final NormalizedNode<?, ?> input) throws IOException {
+ private String toJSON(final NormalizedNode input) throws IOException {
final Writer writer = new StringWriter();
final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter(
codecFactory(), SchemaPath.ROOT, null, JsonWriterFactory.createJsonWriter(writer, 2));
import java.io.StringReader;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
-import java.util.Optional;
import javax.xml.transform.dom.DOMSource;
import org.junit.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, lhotkaCodecFactory);
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
// lf12-any check
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, lhotkaCodecFactory);
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
// lf12-any check
assertNotNull(result.getResult());
assertTrue(result.getResult() instanceof ContainerNode);
- final Optional<DataContainerChild<? extends PathArgument, ?>> data = ((ContainerNode) result.getResult())
- .getChild(new NodeIdentifier(QName.create("bug8927.test", "2017-01-01", "foo")));
- assertTrue(data.isPresent());
- final String jsonOutput = normalizedNodesToJsonString(data.get(), schemaContext, SchemaPath.ROOT);
+ final DataContainerChild data = ((ContainerNode) result.getResult())
+ .childByArg(new NodeIdentifier(QName.create("bug8927.test", "2017-01-01", "foo")));
+ assertNotNull(data);
+ final String jsonOutput = normalizedNodesToJsonString(data, schemaContext, SchemaPath.ROOT);
final JsonParser parser = new JsonParser();
final JsonElement expextedJson = parser.parse(new FileReader(
new File(getClass().getResource(expectedJsonFile).toURI()), StandardCharsets.UTF_8));
assertEquals(expextedJson, serializedJson);
}
- private static DOMSource getParsedAnyXmlValue(final NormalizedNode<?, ?> transformedInput, final QName anyxmlName) {
+ private static DOMSource getParsedAnyXmlValue(final NormalizedNode transformedInput, final QName anyxmlName) {
assertTrue(transformedInput instanceof ContainerNode);
final ContainerNode cont1 = (ContainerNode) transformedInput;
- final DataContainerChild<? extends PathArgument, ?> child = cont1.getChild(new NodeIdentifier(anyxmlName))
- .get();
+ final DataContainerChild child = cont1.childByArg(new NodeIdentifier(anyxmlName));
assertTrue(child instanceof DOMSourceAnyxmlNode);
final DOMSourceAnyxmlNode anyXmlNode = (DOMSourceAnyxmlNode) child;
- return anyXmlNode.getValue();
+ return anyXmlNode.body();
}
private static void verifyTransformedAnyXmlNodeValue(final DOMSource expectedValue, final DOMSource actualValue) {
import java.io.IOException;
import java.io.StringReader;
import java.net.URISyntaxException;
-import java.util.Optional;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertTrue(transformedInput instanceof UnkeyedListNode);
final UnkeyedListNode hop = (UnkeyedListNode) transformedInput;
- final Optional<DataContainerChild<? extends PathArgument, ?>> lrsBits = hop.getChild(0).getChild(
+ final DataContainerChild lrsBits = hop.getChild(0).childByArg(
NodeIdentifier.create(QName.create("foo", "lrs-bits")));
- assertEquals(ImmutableSet.of("lookup", "rloc-probe", "strict"), lrsBits.get().getValue());
+ assertEquals(ImmutableSet.of("lookup", "rloc-probe", "strict"), lrsBits.body());
}
@Test
import java.io.IOException;
import java.io.StringReader;
import java.net.URISyntaxException;
-import java.util.Optional;
import java.util.Set;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(context));
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertTrue(transformedInput instanceof ContainerNode);
ContainerNode root = (ContainerNode) transformedInput;
- final Optional<DataContainerChild<? extends PathArgument, ?>> ref1 = root.getChild(NodeIdentifier.create(
+ final DataContainerChild ref1 = root.childByArg(NodeIdentifier.create(
QName.create("foo", "2016-01-22", "ref1")));
- final Optional<DataContainerChild<? extends PathArgument, ?>> ref2 = root.getChild(NodeIdentifier.create(
+ final DataContainerChild ref2 = root.childByArg(NodeIdentifier.create(
QName.create("foo", "2016-01-22", "ref2")));
- final Optional<DataContainerChild<? extends PathArgument, ?>> ref3 = root.getChild(NodeIdentifier.create(
+ final DataContainerChild ref3 = root.childByArg(NodeIdentifier.create(
QName.create("foo", "2016-01-22", "ref3")));
- final Optional<DataContainerChild<? extends PathArgument, ?>> ref4 = root.getChild(NodeIdentifier.create(
+ final DataContainerChild ref4 = root.childByArg(NodeIdentifier.create(
QName.create("foo", "2016-01-22", "ref4")));
- assertTrue(ref1.isPresent());
- assertTrue(ref2.isPresent());
- assertTrue(ref3.isPresent());
- assertTrue(ref4.isPresent());
+ assertNotNull(ref1);
+ assertNotNull(ref2);
+ assertNotNull(ref3);
+ assertNotNull(ref4);
- final Object value1 = ref1.get().getValue();
- final Object value2 = ref2.get().getValue();
- final Object value3 = ref3.get().getValue();
- final Object value4 = ref4.get().getValue();
+ final Object value1 = ref1.body();
+ final Object value2 = ref2.body();
+ final Object value3 = ref3.body();
+ final Object value4 = ref4.body();
assertTrue(value1 instanceof Set);
assertTrue(value2 instanceof Set);
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(context));
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
}
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
@Test
public void test() throws IOException, JsonIOException, JsonSyntaxException, URISyntaxException {
- final DataContainerChild<? extends PathArgument, ?> rootNode = createRootNode();
+ final ContainerNode rootNode = createRootNode();
final Writer writer = new StringWriter();
final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, rootNode);
}
private static String normalizedNodeToJsonStreamTransformation(final Writer writer,
- final NormalizedNode<?, ?> inputStructure) throws IOException {
+ final NormalizedNode inputStructure) throws IOException {
final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter(
JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext), SchemaPath.ROOT, null,
package org.opendaylight.yangtools.yang.data.codec.gson;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadTextFile;
import java.io.IOException;
import java.io.StringReader;
import java.net.URISyntaxException;
-import java.util.Optional;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.Uint8;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
schemaContext = null;
}
- private static NormalizedNode<?, ?> readJson(final String jsonPath) throws IOException, URISyntaxException {
+ private static NormalizedNode readJson(final String jsonPath) throws IOException, URISyntaxException {
final String inputJson = loadTextFile(jsonPath);
final NormalizedNodeResult result = new NormalizedNodeResult();
@Test
public void testUnionIdentityrefInput() throws IOException, URISyntaxException {
- final NormalizedNode<?, ?> transformedInput = readJson("/bug-6112/json/data-identityref.json");
+ final NormalizedNode transformedInput = readJson("/bug-6112/json/data-identityref.json");
assertTrue(transformedInput instanceof ContainerNode);
ContainerNode root = (ContainerNode) transformedInput;
- Optional<DataContainerChild<? extends PathArgument, ?>> leafValue = root.getChild(NodeIdentifier.create(
+ DataContainerChild leafValue = root.childByArg(NodeIdentifier.create(
QName.create("union:identityref:test", "2016-07-12", "leaf-value")));
- assertTrue(leafValue.isPresent());
- Object value = leafValue.get().getValue();
+ assertNotNull(leafValue);
+ Object value = leafValue.body();
assertTrue(value instanceof QName);
QName identityref = (QName) value;
assertEquals(QName.create("union:identityref:test", "2016-07-12", "ident-one"), identityref);
@Test
public void testUnionUint8Input() throws IOException, URISyntaxException {
- final NormalizedNode<?, ?> transformedInput = readJson("/bug-6112/json/data-uint8.json");
+ final NormalizedNode transformedInput = readJson("/bug-6112/json/data-uint8.json");
assertTrue(transformedInput instanceof ContainerNode);
ContainerNode root = (ContainerNode) transformedInput;
- Optional<DataContainerChild<? extends PathArgument, ?>> leafValue = root.getChild(NodeIdentifier.create(
+ DataContainerChild leafValue = root.childByArg(NodeIdentifier.create(
QName.create("union:identityref:test", "2016-07-12", "leaf-value")));
- assertTrue(leafValue.isPresent());
- assertEquals(Uint8.valueOf(1), leafValue.get().getValue());
+ assertNotNull(leafValue);
+ assertEquals(Uint8.valueOf(1), leafValue.body());
}
}
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
.parse(new FileReader(new File(getClass().getResource("/bug7246/json/expected-output.json").toURI()),
StandardCharsets.UTF_8));
- final DataContainerChild<? extends PathArgument, ?> inputStructure = ImmutableContainerNodeBuilder.create()
+ final ContainerNode inputStructure = ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new NodeIdentifier(qN("my-name")))
.withChild(ImmutableNodes.leafNode(new NodeIdentifier(qN("my-name")), "my-value")).build();
final SchemaPath rootPath = SchemaPath.create(true, qN("my-name"), qN("input"));
}
private static String normalizedNodeToJsonStreamTransformation(final EffectiveModelContext schemaContext,
- final SchemaPath path, final Writer writer, final NormalizedNode<?, ?> inputStructure)
+ final SchemaPath path, final Writer writer, final NormalizedNode inputStructure)
throws IOException {
final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter(
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
JSONCodecFactorySupplier.RFC7951.getShared(FULL_SCHEMA_CONTEXT));
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertTrue(transformedInput instanceof ContainerNode);
final ContainerNode container = (ContainerNode) transformedInput;
- final NormalizedNode<?, ?> child = container.getChild(new NodeIdentifier(FOO_QNAME)).get();
+ final NormalizedNode child = container.childByArg(new NodeIdentifier(FOO_QNAME));
assertTrue(child instanceof LeafNode);
- assertEquals(TEST_IID, child.getValue());
+ assertEquals(TEST_IID, child.body());
}
@Test
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter,
JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final JsonParserStream jsonParser = JsonParserStream.createLenient(streamWriter,
JSONCodecFactorySupplier.DRAFT_LHOTKA_NETMOD_YANG_JSON_02.getShared(schemaContext));
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final SchemaNode parentNode = schemaContext.findDataChildByName(CONT_1).get();
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, lhotkaCodecFactory, parentNode);
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final SchemaNode parentNode = schemaContext.findDataChildByName(CONT_1).get();
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, lhotkaCodecFactory, parentNode);
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final NodeIdentifier augmentChoice2Id = new NodeIdentifier(augmentChoice2QName);
final NodeIdentifier containerId = new NodeIdentifier(containerQName);
- final NormalizedNode<?, ?> cont1Normalized =
+ final NormalizedNode cont1Normalized =
containerBuilder().withNodeIdentifier(new NodeIdentifier(parentNode.getQName()))
.withChild(augmentationBuilder().withNodeIdentifier(aug1Id)
.withChild(choiceBuilder().withNodeIdentifier(augmentChoice1Id)
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, lhotkaCodecFactory);
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
assertEquals(cont1Normalized, transformedInput);
}
private static void verifyTransformationToNormalizedNode(final String inputJson,
- final NormalizedNode<?, ?> awaitedStructure) {
+ final NormalizedNode awaitedStructure) {
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, lhotkaCodecFactory);
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertEquals("Transformation of json input to normalized node wasn't successful.", awaitedStructure,
transformedInput);
}
assertNotNull(cont2);
}
- private static String normalizedNodeToJsonStreamTransformation(final NormalizedNode<?, ?> inputStructure)
+ private static String normalizedNodeToJsonStreamTransformation(final NormalizedNode inputStructure)
throws IOException {
final Writer writer = new StringWriter();
final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter(
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.LoggingNormalizedNodeStreamWriter;
}
// Finally build the node
- final NormalizedNode<?, ?> parsedData = result.getResult();
+ final NormalizedNode parsedData = result.getResult();
LOG.debug("Parsed NormalizedNodes: {}", parsedData);
/*
* This is the serialization part.
*/
// We want to write the first child out
- final DataContainerChild<? extends PathArgument, ?> firstChild =
- (DataContainerChild<? extends PathArgument, ?>) parsedData;
+ final DataContainerChild firstChild = (DataContainerChild) parsedData;
LOG.debug("Serializing first child: {}", firstChild);
// String holder
xmlParser.parse(reader);
}
- static String normalizedNodesToJsonString(final NormalizedNode<?, ?> data,
+ static String normalizedNodesToJsonString(final NormalizedNode data,
final EffectiveModelContext schemaContext, final SchemaPath rootPath) throws IOException {
final Writer writer = new StringWriter();
final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter(
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
throw new UnsupportedOperationException();
}
- @SafeVarargs
- static ContainerNode cont1Node(final DataContainerChild<?, ?>... children) {
+ static ContainerNode cont1Node(final DataContainerChild... children) {
return Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "cont1")))
.withValue(Arrays.asList(children))
.build();
}
- @SafeVarargs
- private static ChoiceNode choc11Node(final DataContainerChild<?, ?>... children) {
+ private static ChoiceNode choc11Node(final DataContainerChild... children) {
return Builders.choiceBuilder()
.withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "choc11")))
.withValue(Arrays.asList(children))
.build();
}
- private static MapNode childLst11() {
+ private static SystemMapNode childLst11() {
return Builders.mapBuilder()
.withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lst11")))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
);
}
- private static LeafSetNode<?> childLflst11() {
+ private static SystemLeafSetNode<?> childLflst11() {
return Builders.leafSetBuilder()
.withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")))
.withChild(Builders.leafSetEntryBuilder()
.build();
}
- private static LeafSetNode<?> childLflst11Multiline() {
+ private static SystemLeafSetNode<?> childLflst11Multiline() {
return Builders.leafSetBuilder()
.withNodeIdentifier(new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")))
.withChild(Builders.leafSetEntryBuilder()
import org.junit.Test;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, lhotkaCodecFactory);
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertEquals(data, transformedInput);
}
@Test
public void normalizedNodesToJsonTest() throws IOException, URISyntaxException, SAXException {
- final DataContainerChild<? extends PathArgument, ?> baz = data;
-
final Writer writer = new StringWriter();
- final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, baz);
+ final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, data);
final JsonParser parser = new JsonParser();
final JsonElement serializedJson = parser.parse(jsonOutput);
}
private static String normalizedNodeToJsonStreamTransformation(final Writer writer,
- final NormalizedNode<?, ?> inputStructure) throws IOException {
+ final NormalizedNode inputStructure) throws IOException {
final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter(
lhotkaCodecFactory, SchemaPath.ROOT, null, JsonWriterFactory.createJsonWriter(writer, 2));
import org.opendaylight.yangtools.util.xml.UntrustedXML;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
final XmlParserStream xmlParser = XmlParserStream.create(writer, SCHEMA, SCHEMA_NODE);
xmlParser.traverse(new DOMSource(doc.getDocumentElement()));
- final NormalizedNode<?, ?> parsed = resultHolder.getResult();
-
- final DataContainerChild<? extends PathArgument, ?> editCfg = ((ContainerNode) parsed)
- .getChild(getNodeId(parsed, "edit-content")).get();
+ final NormalizedNode parsed = resultHolder.getResult();
+ final DataContainerChild editCfg = ((ContainerNode) parsed).childByArg(getNodeId(parsed, "edit-content"));
final DOMSource anyXmlParsedDom = ((DOMSourceAnyxmlNode) ((ChoiceNode) editCfg)
- .getChild(getNodeId(parsed, "config")).get())
- .getValue();
+ .childByArg(getNodeId(parsed, "config"))).body();
assertNotNull(anyXmlParsedDom);
final String anyXmlParsedDomString = toStringDom(anyXmlParsedDom);
"interface-configurations xmlns=\"http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg\""));
}
- private static NodeIdentifier getNodeId(final NormalizedNode<?, ?> parsed, final String localName) {
+ private static NodeIdentifier getNodeId(final NormalizedNode parsed, final String localName) {
return new NodeIdentifier(QName.create(parsed.getNodeType(), localName));
}
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, SCHEMA_CONTEXT, anyDataSchemaNode);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
assertTrue(transformedInput instanceof AnydataNode);
AnydataNode<?> anydataNode = (AnydataNode<?>) transformedInput;
//Normalize anydata content to specific container element
- DOMSourceAnydata domSourceAnydata = (DOMSourceAnydata) anydataNode.getValue();
+ DOMSourceAnydata domSourceAnydata = (DOMSourceAnydata) anydataNode.body();
NormalizedAnydata normalizedAnydata = domSourceAnydata.normalizeTo(SCHEMA_CONTEXT, containerSchemaNode);
assertNotNull(normalizedAnydata);
}
SCHEMA_CONTEXT.findDataChildByName(FOO_QNAME).get(), true);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> parsed = result.getResult();
+ final NormalizedNode parsed = result.getResult();
assertTrue(parsed instanceof AnydataNode);
}
}
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, SCHEMA_CONTEXT, anyDataSchemaNode);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
assertTrue(transformedInput instanceof AnydataNode);
AnydataNode<?> anydataNode = (AnydataNode<?>) transformedInput;
normalizedNodeWriter.flush();
final String serializedXml = writer.toString();
- final String deserializeXml = getXmlFromDOMSource(((DOMSourceAnydata) anydataNode.getValue()).getSource());
+ final String deserializeXml = getXmlFromDOMSource(((DOMSourceAnydata) anydataNode.body()).getSource());
assertFalse(serializedXml.isEmpty());
// Check if is Serialize Node same as Deserialize Node
xmlParser.flush();
//Get Result
- final NormalizedNode<?, ?> node = normalizedResult.getResult();
+ final NormalizedNode node = normalizedResult.getResult();
assertTrue(node instanceof AnydataNode);
final AnydataNode<?> anydataResult = (AnydataNode<?>) node;
//Get Result in formatted String
- assertTrue(anydataResult.getValue() instanceof DOMSourceAnydata);
- final String serializedXml = getXmlFromDOMSource(((DOMSourceAnydata)anydataResult.getValue()).getSource());
+ assertTrue(anydataResult.body() instanceof DOMSourceAnydata);
+ final String serializedXml = getXmlFromDOMSource(((DOMSourceAnydata)anydataResult.body()).getSource());
final String expectedXml = toString(doc.getDocumentElement());
//Looking for difference in Serialized xml and in Loaded XML
import java.io.InputStream;
import java.net.URI;
-import java.util.Optional;
import javax.xml.stream.XMLStreamReader;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
assertTrue(result.getResult() instanceof ContainerNode);
final ContainerNode rootContainer = (ContainerNode) result.getResult();
- Optional<DataContainerChild<? extends PathArgument, ?>> myLeaf = rootContainer.getChild(new NodeIdentifier(
+ DataContainerChild myLeaf = rootContainer.childByArg(new NodeIdentifier(
QName.create(fooModuleQName, "my-leaf")));
- assertTrue(myLeaf.orElse(null) instanceof LeafNode);
-
- assertEquals(expectedValue, myLeaf.get().getValue());
+ assertTrue(myLeaf instanceof LeafNode);
+ assertEquals(expectedValue, myLeaf.body());
}
}
import java.io.StringWriter;
import java.net.URI;
import java.util.Base64;
-import java.util.Optional;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.OutputKeys;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
final ContainerNode docNode = createDocNode();
- Optional<DataContainerChild<? extends PathArgument, ?>> root = docNode.getChild(new NodeIdentifier(ROOT_QNAME));
- assertTrue(root.orElse(null) instanceof ContainerNode);
+ DataContainerChild root = docNode.childByArg(new NodeIdentifier(ROOT_QNAME));
+ DataContainerChild child = ((ContainerNode) root).childByArg(new NodeIdentifier(IP_ADDRESS_QNAME));
+ LeafNode<?> ipAdress = (LeafNode<?>) child;
- Optional<DataContainerChild<? extends PathArgument, ?>> child = ((ContainerNode) root.orElse(null))
- .getChild(new NodeIdentifier(IP_ADDRESS_QNAME));
- assertTrue(child.orElse(null) instanceof LeafNode);
- LeafNode<?> ipAdress = (LeafNode<?>) child.get();
-
- Object value = ipAdress.getValue();
+ Object value = ipAdress.body();
assertTrue(value instanceof byte[]);
assertEquals("fwAAAQ==", Base64.getEncoder().encodeToString((byte[]) value));
normalizedNodeStreamWriter = XMLStreamNormalizedNodeStreamWriter.create(writer, context);
normalizedNodeWriter = NormalizedNodeWriter.forStreamWriter(normalizedNodeStreamWriter);
- for (NormalizedNode<?, ?> child : normalized.getValue()) {
+ for (NormalizedNode child : normalized.body()) {
normalizedNodeWriter.write(child);
}
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topCont);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topCont);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topCont);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
}
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topLevelContainer);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topLevelContainer);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topLevelList);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topLevelAnyXml);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topLevelLeaf);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topLevelLeafList);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
}
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, SCHEMA_CONTEXT, topContSchema);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
// serialization
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
assertTrue(result.getResult() instanceof ContainerNode);
final ContainerNode rootContainer = (ContainerNode) result.getResult();
- Optional<DataContainerChild<? extends PathArgument, ?>> myLeaf =
- rootContainer.getChild(new NodeIdentifier(OUTGOING_LABELS_QNAME));
- assertTrue(myLeaf.orElse(null) instanceof ContainerNode);
+ DataContainerChild myLeaf = rootContainer.childByArg(new NodeIdentifier(OUTGOING_LABELS_QNAME));
+ assertTrue(myLeaf instanceof ContainerNode);
- ContainerNode outgoingLabelsContainer = (ContainerNode)myLeaf.get();
- Optional<DataContainerChild<? extends PathArgument, ?>> outgoingLabelsList =
- outgoingLabelsContainer.getChild(new NodeIdentifier(OUTGOING_LABELS_QNAME));
- assertTrue(outgoingLabelsList.orElse(null) instanceof MapNode);
- MapNode outgoingLabelsMap = (MapNode) outgoingLabelsList.get();
+ ContainerNode outgoingLabelsContainer = (ContainerNode)myLeaf;
+ DataContainerChild outgoingLabelsList =
+ outgoingLabelsContainer.childByArg(new NodeIdentifier(OUTGOING_LABELS_QNAME));
+ assertTrue(outgoingLabelsList instanceof MapNode);
+ MapNode outgoingLabelsMap = (MapNode) outgoingLabelsList;
assertEquals(2, outgoingLabelsMap.size());
- Collection<MapEntryNode> labels = outgoingLabelsMap.getValue();
+ Collection<MapEntryNode> labels = outgoingLabelsMap.body();
NodeIdentifierWithPredicates firstNodeId =
NodeIdentifierWithPredicates.of(OUTGOING_LABELS_QNAME, INDEX_QNAME, 0);
NodeIdentifierWithPredicates secondNodeId =
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, SCHEMA_CONTEXT, outerContainerSchema);
xmlParser.parse(domXMLReader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
// serialization
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> b = containerBuilder();
b.withNodeIdentifier(getNodeIdentifier("container"));
- final CollectionNodeBuilder<MapEntryNode, MapNode> listBuilder = Builders.mapBuilder().withNodeIdentifier(
- getNodeIdentifier("list"));
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listBuilder =
+ Builders.mapBuilder().withNodeIdentifier(getNodeIdentifier("list"));
final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> list1Builder = Builders
.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(
booleanBuilder.withValue(Boolean.FALSE);
b.withChild(booleanBuilder.build());
- final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafListBuilder = Builders.leafSetBuilder()
+ final ListNodeBuilder<Object, SystemLeafSetNode<Object>> leafListBuilder = Builders.leafSetBuilder()
.withNodeIdentifier(getNodeIdentifier("leafList"));
final NormalizedNodeBuilder<NodeWithValue, Object, LeafSetEntryNode<Object>> leafList1Builder = Builders
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schema, containerNode);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> built = result.getResult();
+ final NormalizedNode built = result.getResult();
assertNotNull(built);
if (expectedNode != null) {
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
new XMLTestCase() {}.assertXMLEqual(diff, true);
}
- private NormalizedNode<?, ?> buildOuterContainerNode() {
+ private NormalizedNode buildOuterContainerNode() {
// my-container-1
MapNode myKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(myKeyedList))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
LeafNode<?> myLeaf1Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf1))
.withValue("value1").build();
- LeafSetNode<?> myLeafListNode = Builders.leafSetBuilder().withNodeIdentifier(new NodeIdentifier(myLeafList))
+ SystemLeafSetNode<?> myLeafListNode = Builders.leafSetBuilder()
+ .withNodeIdentifier(new NodeIdentifier(myLeafList))
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
new NodeWithValue<>(myLeafList, "lflvalue1")).withValue("lflvalue1").build())
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
import org.junit.runners.Parameterized;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
rule1Names.add(ImmutableNodes.mapEntry(createQName(FOO_NAMESPACE, RULE_NODE),
createQName(FOO_NAMESPACE, NAME_NODE), "rule4"));
- DataContainerChild<?, ?> rules1 = Builders.orderedMapBuilder()
+ UserMapNode rules1 = Builders.orderedMapBuilder()
.withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, RULE_NODE))
.withValue(rule1Names)
.build();
- DataContainerChild<?, ?> rules2 = Builders.orderedMapBuilder()
+ UserMapNode rules2 = Builders.orderedMapBuilder()
.withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, RULE_NODE))
.withValue(rule2Names)
.build();
policyNodes.add(pn1);
policyNodes.add(pn2);
- DataContainerChild<?, ?> policy = Builders.orderedMapBuilder()
+ UserMapNode policy = Builders.orderedMapBuilder()
.withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, POLICY_NODE))
.withValue(policyNodes)
.build();
- NormalizedNode<?, ?> root = Builders.containerBuilder()
+ ContainerNode root = Builders.containerBuilder()
.withNodeIdentifier(getNodeIdentifier(FOO_NAMESPACE, "root"))
.withChild(policy).build();
nnw.write(root);
try (NormalizedNodeWriter nnw = new SchemaOrderedNormalizedNodeWriter(writer, schemaContext, SchemaPath.ROOT)) {
- DataContainerChild<?, ?> cont = Builders.containerBuilder()
+ ContainerNode cont = Builders.containerBuilder()
.withNodeIdentifier(getNodeIdentifier(ORDER_NAMESPACE, "cont"))
.withChild(ImmutableNodes.leafNode(createQName(ORDER_NAMESPACE, "content"), "content1"))
.build();
- NormalizedNode<?, ?> root = Builders.containerBuilder()
+ ContainerNode root = Builders.containerBuilder()
.withNodeIdentifier(getNodeIdentifier(ORDER_NAMESPACE, "root"))
.withChild(cont)
.withChild(ImmutableNodes.leafNode(createQName(ORDER_NAMESPACE, "id"), "id1"))
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
XMLAssert.assertXMLEqual(diff, true);
}
- private NormalizedNode<?, ?> buildOuterContainerNode() {
+ private NormalizedNode buildOuterContainerNode() {
// my-container-1
MapNode myKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(myKeyedList))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
.withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList2))
.withValue("listleafvalue22").build()).build()).build();
- OrderedMapNode myOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
+ UserMapNode myOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
new NodeIdentifier(myOrderedList)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(
NodeIdentifierWithPredicates.of(myOrderedList, myKeyLeafInOrderedList, "olistkeyvalue1"))
.withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInOrderedList1))
LeafNode<?> myLeaf1Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf1))
.withValue("value1").build();
- LeafSetNode<?> myLeafListNode = Builders.leafSetBuilder().withNodeIdentifier(new NodeIdentifier(myLeafList))
+ SystemLeafSetNode<?> myLeafListNode = Builders.leafSetBuilder()
+ .withNodeIdentifier(new NodeIdentifier(myLeafList))
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
new NodeWithValue<>(myLeafList, "lflvalue1")).withValue("lflvalue1").build())
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
new NodeWithValue<>(myLeafList, "lflvalue2")).withValue("lflvalue2").build()).build();
- LeafSetNode<?> myOrderedLeafListNode = Builders.orderedLeafSetBuilder().withNodeIdentifier(
+ UserLeafSetNode<?> myOrderedLeafListNode = Builders.orderedLeafSetBuilder()
+ .withNodeIdentifier(
new NodeIdentifier(myOrderedLeafList))
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
new NodeWithValue<>(myOrderedLeafList, "olflvalue1")).withValue("olflvalue1").build())
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topLevelContainer, false);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
xmlParser.flush();
xmlParser.close();
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
- final NormalizedNode<?, ?> expectedNormalizedNode = buildOuterContainerNode();
+ final NormalizedNode expectedNormalizedNode = buildOuterContainerNode();
assertNotNull(expectedNormalizedNode);
assertEquals(expectedNormalizedNode, transformedInput);
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, parentContainerSchema);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
}
}
}
- private static NormalizedNode<?, ?> buildOuterContainerNode() {
+ private static NormalizedNode buildOuterContainerNode() {
// my-container-1
MapNode myKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_KEYED_LIST))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
LeafNode<?> myLeaf1Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(MY_LEAF_1))
.withValue("value1").build();
- LeafSetNode<?> myLeafListNode = Builders.leafSetBuilder().withNodeIdentifier(new NodeIdentifier(MY_LEAFLIST))
+ SystemLeafSetNode<?> myLeafListNode = Builders.leafSetBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MY_LEAFLIST))
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
new NodeWithValue<>(MY_LEAFLIST, "lflvalue1")).withValue("lflvalue1").build())
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
new XMLTestCase() {}.assertXMLEqual(diff, true);
}
- private DOMResult convertNormalizedNodeToXml(NormalizedNode<?, ?> normalizedNode)
+ private DOMResult convertNormalizedNodeToXml(NormalizedNode normalizedNode)
throws XMLStreamException, IOException {
final DOMResult domResult = new DOMResult(UntrustedXML.newDocumentBuilder().newDocument());
return domResult;
}
- private NormalizedNode<?, ?> buildLeafContainerNodeWithIdentityRefLeaf() {
+ private NormalizedNode buildLeafContainerNodeWithIdentityRefLeaf() {
return Builders.containerBuilder()
.withNodeIdentifier(NodeIdentifier.create(fooLeafContainer))
.withChild(Builders.leafBuilder()
.build();
}
- private NormalizedNode<?, ?> buildLeafContainerNodeWithUnionIdentityRefLeaf() {
+ private NormalizedNode buildLeafContainerNodeWithUnionIdentityRefLeaf() {
return Builders.containerBuilder()
.withNodeIdentifier(NodeIdentifier.create(fooLeafContainer))
.withChild(Builders.leafBuilder()
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, yangModeledAnyXML);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> output = result.getResult();
+ final NormalizedNode output = result.getResult();
assertTrue(output instanceof YangModeledAnyXmlNode);
final YangModeledAnyXmlNode yangModeledAnyXmlNode = (YangModeledAnyXmlNode) output;
- Collection<DataContainerChild<? extends PathArgument, ?>> value = yangModeledAnyXmlNode.getValue();
+ Collection<DataContainerChild> value = yangModeledAnyXmlNode.body();
assertEquals(2, value.size());
- Optional<DataContainerChild<? extends PathArgument, ?>> child = yangModeledAnyXmlNode
- .getChild(new NodeIdentifier(myContainer1));
- assertTrue(child.orElse(null) instanceof ContainerNode);
- ContainerNode myContainerNode1 = (ContainerNode) child.get();
+ DataContainerChild child = yangModeledAnyXmlNode.childByArg(new NodeIdentifier(myContainer1));
+ assertTrue(child instanceof ContainerNode);
+ ContainerNode myContainerNode1 = (ContainerNode) child;
- Optional<DataContainerChild<? extends PathArgument, ?>> child2 = myContainerNode1.getChild(new NodeIdentifier(
- myLeaf1));
- assertTrue(child2.orElse(null) instanceof LeafNode);
- LeafNode<?> leafNode1 = (LeafNode<?>) child2.get();
+ DataContainerChild child2 = myContainerNode1.childByArg(new NodeIdentifier(myLeaf1));
+ assertTrue(child2 instanceof LeafNode);
+ LeafNode<?> leafNode1 = (LeafNode<?>) child2;
- Object leafNode1Value = leafNode1.getValue();
+ Object leafNode1Value = leafNode1.body();
assertEquals("value1", leafNode1Value);
}
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, myAnyXmlData);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> output = result.getResult();
+ final NormalizedNode output = result.getResult();
assertTrue(output instanceof YangModeledAnyXmlNode);
final YangModeledAnyXmlNode yangModeledAnyXmlNode = (YangModeledAnyXmlNode) output;
DataSchemaNode expectedSchemaOfAnyXmlData = schemaContext.findDataChildByName(myContainer2).get();
assertEquals(expectedSchemaOfAnyXmlData, schemaOfAnyXmlData);
- Collection<DataContainerChild<? extends PathArgument, ?>> value = yangModeledAnyXmlNode.getValue();
+ Collection<DataContainerChild> value = yangModeledAnyXmlNode.body();
assertEquals(2, value.size());
- Optional<DataContainerChild<? extends PathArgument, ?>> child2 = yangModeledAnyXmlNode
- .getChild(new NodeIdentifier(innerContainer));
- assertTrue(child2.orElse(null) instanceof ContainerNode);
- ContainerNode innerContainerNode = (ContainerNode) child2.get();
+ DataContainerChild child2 = yangModeledAnyXmlNode.childByArg(new NodeIdentifier(innerContainer));
+ assertTrue(child2 instanceof ContainerNode);
+ ContainerNode innerContainerNode = (ContainerNode) child2;
- Optional<DataContainerChild<? extends PathArgument, ?>> child3 = innerContainerNode
- .getChild(new NodeIdentifier(myLeaf2));
- assertTrue(child3.orElse(null) instanceof LeafNode);
- LeafNode<?> leafNode2 = (LeafNode<?>) child3.get();
+ DataContainerChild child3 = innerContainerNode.childByArg(new NodeIdentifier(myLeaf2));
+ assertTrue(child3 instanceof LeafNode);
+ LeafNode<?> leafNode2 = (LeafNode<?>) child3;
- Object leafNode2Value = leafNode2.getValue();
+ Object leafNode2Value = leafNode2.body();
assertEquals("any-xml-leaf-2-value", leafNode2Value);
- Optional<DataContainerChild<? extends PathArgument, ?>> child4 = yangModeledAnyXmlNode
- .getChild(new NodeIdentifier(myLeaf3));
- assertTrue(child4.orElse(null) instanceof LeafNode);
- LeafNode<?> leafNode3 = (LeafNode<?>) child4.get();
+ DataContainerChild child4 = yangModeledAnyXmlNode.childByArg(new NodeIdentifier(myLeaf3));
+ assertTrue(child4 instanceof LeafNode);
+ LeafNode<?> leafNode3 = (LeafNode<?>) child4;
- Object leafNode3Value = leafNode3.getValue();
+ Object leafNode3Value = leafNode3.body();
assertEquals("any-xml-leaf-3-value", leafNode3Value);
}
import java.io.StringWriter;
import java.net.URI;
import java.util.Collection;
-import java.util.Optional;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, SCHEMA_CONTEXT, bazCont);
xmlParser.parse(reader);
- final NormalizedNode<?, ?> transformedInput = result.getResult();
+ final NormalizedNode transformedInput = result.getResult();
assertNotNull(transformedInput);
assertTrue(transformedInput instanceof ContainerNode);
ContainerNode bazContainer = (ContainerNode) transformedInput;
assertEquals(bazContainer.getNodeType(), bazQName);
- Optional<DataContainerChild<? extends PathArgument, ?>> bazContainerChild = bazContainer.getChild(
- new NodeIdentifier(myAnyXMLDataBaz));
- assertTrue(bazContainerChild.orElse(null) instanceof YangModeledAnyXmlNode);
- YangModeledAnyXmlNode yangModeledAnyXmlNode = (YangModeledAnyXmlNode) bazContainerChild.get();
+ DataContainerChild bazContainerChild = bazContainer.childByArg(new NodeIdentifier(myAnyXMLDataBaz));
+ assertTrue(bazContainerChild instanceof YangModeledAnyXmlNode);
+ YangModeledAnyXmlNode yangModeledAnyXmlNode = (YangModeledAnyXmlNode) bazContainerChild;
DataSchemaNode schemaOfAnyXmlData = yangModeledAnyXmlNode.getSchemaOfAnyXmlData();
SchemaNode myContainer2SchemaNode = SchemaContextUtil.findDataSchemaNode(SCHEMA_CONTEXT,
private final Set<LeafRefContext> validatedLeafRefCtx = new HashSet<>();
private final List<String> errorsMessages = new ArrayList<>();
- private final NormalizedNode<?, ?> root;
+ private final NormalizedNode root;
- private LeafRefValidation(final NormalizedNode<?, ?> root) {
+ private LeafRefValidation(final NormalizedNode root) {
this.root = root;
}
public static void validate(final DataTreeCandidate tree, final LeafRefContext rootLeafRefCtx)
throws LeafRefDataValidationFailedException {
- final Optional<NormalizedNode<?, ?>> root = tree.getRootNode().getDataAfter();
+ final Optional<NormalizedNode> root = tree.getRootNode().getDataAfter();
if (root.isPresent()) {
new LeafRefValidation(root.get()).validateChildren(rootLeafRefCtx, tree.getRootNode().getChildNodes());
}
final QName childQName = childNode.getIdentifier().getNodeType();
LeafRefContext childReferencingCtx = referencingCtx.getReferencingChildByName(childQName);
if (childReferencingCtx == null) {
- final NormalizedNode<?, ?> data = childNode.getDataAfter().get();
+ final NormalizedNode data = childNode.getDataAfter().get();
if (data instanceof MapEntryNode || data instanceof UnkeyedListEntryNode) {
childReferencingCtx = referencingCtx;
}
final QName childQName = childNode.getIdentifier().getNodeType();
LeafRefContext childReferencedByCtx = referencedByCtx.getReferencedChildByName(childQName);
if (childReferencedByCtx == null) {
- final NormalizedNode<?, ?> data = childNode.getDataAfter().get();
+ final NormalizedNode data = childNode.getDataAfter().get();
if (data instanceof MapEntryNode || data instanceof UnkeyedListEntryNode) {
childReferencedByCtx = referencedByCtx;
}
return childReferencedByCtx;
}
- private void validateNodeData(final NormalizedNode<?, ?> node, final LeafRefContext referencedByCtx,
+ private void validateNodeData(final NormalizedNode node, final LeafRefContext referencedByCtx,
final LeafRefContext referencingCtx, final ModificationType modificationType,
final YangInstanceIdentifier current) {
if (node instanceof LeafNode) {
final LeafRefContext referencingCtx, final ModificationType modificationType,
final YangInstanceIdentifier current) {
if (referencedByCtx != null || referencingCtx != null) {
- for (final NormalizedNode<?, ?> leafSetEntry : node.getValue()) {
+ for (final NormalizedNode leafSetEntry : node.body()) {
if (referencedByCtx != null && referencedByCtx.isReferenced()) {
validateLeafRefTargetNodeData(leafSetEntry, referencedByCtx, modificationType);
}
private void validateChoiceNodeData(final ChoiceNode node, final LeafRefContext referencedByCtx,
final LeafRefContext referencingCtx, final ModificationType modificationType,
final YangInstanceIdentifier current) {
- for (final DataContainerChild<?, ?> child : node.getValue()) {
+ for (final DataContainerChild child : node.body()) {
final QName qname = child.getNodeType();
final LeafRefContext childReferencedByCtx = referencedByCtx == null ? null
: findReferencedByCtxUnderChoice(referencedByCtx, qname);
private void validateDataContainerNodeData(final DataContainerNode<?> node, final LeafRefContext referencedByCtx,
final LeafRefContext referencingCtx, final ModificationType modificationType,
final YangInstanceIdentifier current) {
- for (final DataContainerChild<?, ?> child : node.getValue()) {
+ for (final DataContainerChild child : node.body()) {
if (child instanceof AugmentationNode) {
validateNodeData(child, referencedByCtx, referencingCtx, modificationType, current.node(
child.getIdentifier()));
private void validateMapNodeData(final MapNode node, final LeafRefContext referencedByCtx,
final LeafRefContext referencingCtx, final ModificationType modificationType,
final YangInstanceIdentifier current) {
- for (final MapEntryNode mapEntry : node.getValue()) {
+ for (final MapEntryNode mapEntry : node.asMap().values()) {
final YangInstanceIdentifier mapEntryIdentifier = current.node(mapEntry.getIdentifier());
- for (final DataContainerChild<?, ?> child : mapEntry.getValue()) {
+ for (final DataContainerChild child : mapEntry.body()) {
if (child instanceof AugmentationNode) {
validateNodeData(child, referencedByCtx, referencingCtx, modificationType, current.node(
child.getIdentifier()));
}
}
- private void validateChildNodeData(final DataContainerChild<?, ?> child, final LeafRefContext referencedByCtx,
+ private void validateChildNodeData(final DataContainerChild child, final LeafRefContext referencedByCtx,
final LeafRefContext referencingCtx, final ModificationType modificationType,
final YangInstanceIdentifier current) {
final QName qname = child.getNodeType();
return null;
}
- private void validateLeafRefTargetNodeData(final NormalizedNode<?, ?> leaf, final LeafRefContext
+ private void validateLeafRefTargetNodeData(final NormalizedNode leaf, final LeafRefContext
referencedByCtx, final ModificationType modificationType) {
if (!validatedLeafRefCtx.add(referencedByCtx)) {
LOG.trace("Operation [{}] validate data of leafref TARGET node: name[{}] = value[{}] -> SKIP: Already "
- + "validated", modificationType, referencedByCtx.getNodeName(), leaf.getValue());
+ + "validated", modificationType, referencedByCtx.getNodeName(), leaf.body());
return;
}
LOG.trace("Operation [{}] validate data of leafref TARGET node: name[{}] = value[{}]", modificationType,
- referencedByCtx.getNodeName(), leaf.getValue());
+ referencedByCtx.getNodeName(), leaf.body());
final Set<LeafRefContext> leafRefs = referencedByCtx.getAllReferencedByLeafRefCtxs().values().stream()
.filter(LeafRefContext::isReferencing).collect(Collectors.toSet());
if (leafRefs.isEmpty()) {
return computeValues(root, createPath(context.getLeafRefNodePath()), null);
}
- private void validateLeafRefNodeData(final NormalizedNode<?, ?> leaf, final LeafRefContext referencingCtx,
+ private void validateLeafRefNodeData(final NormalizedNode leaf, final LeafRefContext referencingCtx,
final ModificationType modificationType, final YangInstanceIdentifier current) {
final Set<Object> values = computeValues(root, createPath(referencingCtx.getAbsoluteLeafRefTargetPath()),
current);
- if (values.contains(leaf.getValue())) {
+ if (values.contains(leaf.body())) {
LOG.debug("Operation [{}] validate data of LEAFREF node: name[{}] = value[{}] {}", modificationType,
- referencingCtx.getNodeName(), leaf.getValue(), SUCCESS);
+ referencingCtx.getNodeName(), leaf.body(), SUCCESS);
return;
}
LOG.debug("Operation [{}] validate data of LEAFREF node: name[{}] = value[{}] {}", modificationType,
- referencingCtx.getNodeName(), leaf.getValue(), FAILED);
+ referencingCtx.getNodeName(), leaf.body(), FAILED);
LOG.debug("Invalid leafref value [{}] allowed values {} of LEAFREF node: {} leafRef target path: {}",
- leaf.getValue(), values, leaf.getNodeType(), referencingCtx.getAbsoluteLeafRefTargetPath());
+ leaf.body(), values, leaf.getNodeType(), referencingCtx.getAbsoluteLeafRefTargetPath());
errorsMessages.add(String.format("Invalid leafref value [%s] allowed values %s of LEAFREF node: %s leafRef "
- + "target path: %s", leaf.getValue(), values, leaf.getNodeType(),
+ + "target path: %s", leaf.body(), values, leaf.getNodeType(),
referencingCtx.getAbsoluteLeafRefTargetPath()));
}
- private Set<Object> computeValues(final NormalizedNode<?, ?> node, final Deque<QNameWithPredicate> path,
+ private Set<Object> computeValues(final NormalizedNode node, final Deque<QNameWithPredicate> path,
final YangInstanceIdentifier current) {
final HashSet<Object> values = new HashSet<>();
addValues(values, node, ImmutableList.of(), path, current);
return values;
}
- private void addValues(final Set<Object> values, final NormalizedNode<?, ?> node,
+ private void addValues(final Set<Object> values, final NormalizedNode node,
final List<QNamePredicate> nodePredicates, final Deque<QNameWithPredicate> path,
final YangInstanceIdentifier current) {
if (node instanceof ValueNode) {
- values.add(node.getValue());
+ values.add(node.body());
return;
}
if (node instanceof LeafSetNode<?>) {
- for (final NormalizedNode<?, ?> entry : ((LeafSetNode<?>) node).getValue()) {
- values.add(entry.getValue());
+ for (final NormalizedNode entry : ((LeafSetNode<?>) node).body()) {
+ values.add(entry.body());
}
return;
}
processChildNode(values, (DataContainerNode<?>) node, pathArgument, next.getQNamePredicates(), path,
current);
} else if (node instanceof MapNode) {
- Stream<MapEntryNode> entries = ((MapNode) node).getValue().stream();
+ Stream<MapEntryNode> entries = ((MapNode) node).body().stream();
if (!nodePredicates.isEmpty() && current != null) {
entries = entries.filter(createMapEntryPredicate(nodePredicates, current));
}
private void processChildNode(final Set<Object> values, final DataContainerNode<?> parent,
final PathArgument arg, final List<QNamePredicate> nodePredicates, final Deque<QNameWithPredicate> path,
final YangInstanceIdentifier current) {
- final Optional<DataContainerChild<?, ?>> child = parent.getChild(arg);
- if (!child.isPresent()) {
+ final DataContainerChild child = parent.childByArg(arg);
+ if (child == null) {
// FIXME: YANGTOOLS-901. We have SchemaContext nearby, hence we should be able to cache how to get
// to the leaf with with specified QName, without having to iterate through Choices/Augmentations.
// That perhaps means we should not have QNameWithPredicates, but NodeIdentifierWithPredicates as
// the path specification.
- for (final DataContainerChild<?, ?> mixin : parent.getValue()) {
+ for (final DataContainerChild mixin : parent.body()) {
if (mixin instanceof AugmentationNode || mixin instanceof ChoiceNode) {
addValues(values, mixin, nodePredicates, path, current);
}
}
} else {
- addNextValues(values, child.get(), nodePredicates, path, current);
+ addNextValues(values, child, nodePredicates, path, current);
}
}
};
}
- private void addNextValues(final Set<Object> values, final NormalizedNode<?, ?> node,
+ private void addNextValues(final Set<Object> values, final NormalizedNode node,
final List<QNamePredicate> nodePredicates, final Deque<QNameWithPredicate> path,
final YangInstanceIdentifier current) {
final QNameWithPredicate element = path.pop();
}).orElse(ImmutableSet.of());
}
- private static Optional<NormalizedNode<?, ?>> findParentNode(
- final Optional<NormalizedNode<?, ?>> root, final YangInstanceIdentifier path) {
- Optional<NormalizedNode<?, ?>> currentNode = root;
+ private static Optional<NormalizedNode> findParentNode(
+ final Optional<NormalizedNode> root, final YangInstanceIdentifier path) {
+ Optional<NormalizedNode> currentNode = root;
final Iterator<PathArgument> pathIterator = path.getPathArguments().iterator();
while (pathIterator.hasNext()) {
final PathArgument childPathArgument = pathIterator.next();
@Beta
public abstract class AbstractMountPointChild implements MountPointChild {
@Override
- public final NormalizedNode<?, ?> normalizeTo(final EffectiveModelContext schemaContext) throws IOException {
+ public final NormalizedNode normalizeTo(final EffectiveModelContext schemaContext) throws IOException {
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
writeTo(streamWriter, new EmptyMountPointContext(schemaContext));
import org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.YangModeledAnyXmlNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeSchemaAwareBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeSchemaAwareBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeSchemaAwareBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableYangModeledAnyXmlNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
return ImmutableLeafNodeSchemaAwareBuilder.create(schema);
}
+ // FIXME: 7.0.0: add generic arguments
public static <T> NormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> leafSetEntryBuilder() {
return ImmutableLeafSetEntryNodeBuilder.create();
}
+ // FIXME: 7.0.0: add generic arguments
public static <T> NormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> leafSetEntryBuilder(
final LeafListSchemaNode schema) {
return ImmutableLeafSetEntryNodeSchemaAwareBuilder.create(schema);
return ImmutableAnydataNodeBuilder.create(objectModel);
}
- public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> orderedLeafSetBuilder() {
- return ImmutableOrderedLeafSetNodeBuilder.create();
+ public static <T> ListNodeBuilder<T, UserLeafSetNode<T>> orderedLeafSetBuilder() {
+ return ImmutableUserLeafSetNodeBuilder.create();
}
- public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> orderedLeafSetBuilder(final LeafListSchemaNode schema) {
- return ImmutableOrderedLeafSetNodeSchemaAwareBuilder.create(schema);
+ public static <T> ListNodeBuilder<T, UserLeafSetNode<T>> orderedLeafSetBuilder(final LeafListSchemaNode schema) {
+ return ImmutableUserLeafSetNodeSchemaAwareBuilder.create(schema);
}
- public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> leafSetBuilder() {
+ public static <T> ListNodeBuilder<T, UserLeafSetNode<T>> orderedLeafSetBuilder(final LeafListSchemaNode schema,
+ final UserLeafSetNode<T> node) {
+ return ImmutableUserLeafSetNodeSchemaAwareBuilder.create(schema, node);
+ }
+
+ public static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> leafSetBuilder() {
return ImmutableLeafSetNodeBuilder.create();
}
- public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> leafSetBuilder(final LeafSetNode<T> node) {
+ public static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> leafSetBuilder(final SystemLeafSetNode<T> node) {
return ImmutableLeafSetNodeBuilder.create(node);
}
- public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> leafSetBuilder(final LeafListSchemaNode schema) {
+ public static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> leafSetBuilder(final LeafListSchemaNode schema) {
return ImmutableLeafSetNodeSchemaAwareBuilder.create(schema);
}
- public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> leafSetBuilder(final LeafListSchemaNode schema,
- final LeafSetNode<T> node) {
+ public static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> leafSetBuilder(final LeafListSchemaNode schema,
+ final SystemLeafSetNode<T> node) {
return ImmutableLeafSetNodeSchemaAwareBuilder.create(schema, node);
}
return ImmutableMapEntryNodeSchemaAwareBuilder.create(schema);
}
- public static CollectionNodeBuilder<MapEntryNode, OrderedMapNode> orderedMapBuilder() {
- return ImmutableOrderedMapNodeBuilder.create();
+ public static CollectionNodeBuilder<MapEntryNode, UserMapNode> orderedMapBuilder() {
+ return ImmutableUserMapNodeBuilder.create();
}
- public static CollectionNodeBuilder<MapEntryNode, OrderedMapNode> orderedMapBuilder(final ListSchemaNode schema) {
- return ImmutableOrderedMapNodeSchemaAwareBuilder.create(schema);
+ public static CollectionNodeBuilder<MapEntryNode, UserMapNode> orderedMapBuilder(final ListSchemaNode schema) {
+ return ImmutableUserMapNodeSchemaAwareBuilder.create(schema);
}
public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> unkeyedListBuilder() {
return ImmutableUnkeyedListNodeBuilder.create();
}
- public static CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder() {
+ public static CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder() {
return ImmutableMapNodeBuilder.create();
}
- public static CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder(final MapNode node) {
+ public static CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder(final SystemMapNode node) {
return ImmutableMapNodeBuilder.create(node);
}
- public static CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder(final ListSchemaNode schema) {
+ public static CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder(final ListSchemaNode schema) {
return ImmutableMapNodeSchemaAwareBuilder.create(schema);
}
- public static CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder(final ListSchemaNode schema,
- final MapNode node) {
+ public static CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder(final ListSchemaNode schema,
+ final SystemMapNode node) {
return ImmutableMapNodeSchemaAwareBuilder.create(schema, node);
}
public void close() throws IOException {
super.close();
- final NormalizedNode<?, ?> data = mountResult.getResult();
+ final NormalizedNode data = mountResult.getResult();
if (!(data instanceof ContainerNode)) {
throw new IOException("Unhandled mount data " + data);
}
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
// Hidden on purpose
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, MapNode> mapNodeBuilder() {
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapNodeBuilder() {
return ImmutableMapNodeBuilder.create();
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, MapNode> mapNodeBuilder(final QName name) {
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapNodeBuilder(final QName name) {
return mapNodeBuilder(NodeIdentifier.create(name));
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, MapNode> mapNodeBuilder(final NodeIdentifier name) {
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapNodeBuilder(
+ final NodeIdentifier name) {
return ImmutableMapNodeBuilder.create().withNodeIdentifier(name);
}
* @param name QName which will be used as node identifier
* @return An unordered Map node
*/
- public static @NonNull MapNode mapNode(final QName name) {
+ public static @NonNull SystemMapNode mapNode(final QName name) {
return mapNode(NodeIdentifier.create(name));
}
* @param name QName which will be used as node identifier
* @return An unordered Map node
*/
- public static @NonNull MapNode mapNode(final NodeIdentifier name) {
+ public static @NonNull SystemMapNode mapNode(final NodeIdentifier name) {
return mapNodeBuilder(name).build();
}
* @param name QName which will be used as node identifier
* @return An ordered Map node
*/
- public static @NonNull OrderedMapNode orderedMapNode(final QName name) {
+ public static @NonNull UserMapNode orderedMapNode(final QName name) {
return orderedMapNode(NodeIdentifier.create(name));
}
* @param name Node identifier
* @return An ordered Map node
*/
- public static @NonNull OrderedMapNode orderedMapNode(final NodeIdentifier name) {
- return ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(name).build();
+ public static @NonNull UserMapNode orderedMapNode(final NodeIdentifier name) {
+ return ImmutableUserMapNodeBuilder.create().withNodeIdentifier(name).build();
}
/**
* @param id instance identifier to convert to node structure starting from root
* @return serialized normalized node for provided instance Id
*/
- public static @NonNull NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx,
- final YangInstanceIdentifier id) {
+ public static @NonNull NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id) {
return fromInstanceId(ctx, id, Optional.empty());
}
* instance identifier
* @return serialized normalized node for provided instance Id with overridden last child.
*/
- public static @NonNull NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id,
- final NormalizedNode<?, ?> deepestElement) {
+ public static @NonNull NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id,
+ final NormalizedNode deepestElement) {
return fromInstanceId(ctx, id, Optional.of(deepestElement));
}
* @return serialized normalized node for provided instance Id with (optionally) overridden last child
* and (optionally) marked with specific operation attribute.
*/
- public static @NonNull NormalizedNode<?, ?> fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id,
- final Optional<NormalizedNode<?, ?>> deepestElement) {
+ public static @NonNull NormalizedNode fromInstanceId(final SchemaContext ctx, final YangInstanceIdentifier id,
+ final Optional<NormalizedNode> deepestElement) {
final PathArgument topLevelElement;
final InstanceIdToNodes<?> instanceIdToNodes;
final Iterator<PathArgument> it = id.getPathArguments().iterator();
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableYangModeledAnyXmlNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
public void startLeafSetEntryNode(final NodeWithValue<?> name) {
final NormalizedNodeBuilder<?, ?, ?> current = current();
checkArgument(current instanceof ImmutableLeafSetNodeBuilder
- || current instanceof ImmutableOrderedLeafSetNodeBuilder || current instanceof NormalizedNodeResultBuilder,
+ || current instanceof ImmutableUserLeafSetNodeBuilder || current instanceof NormalizedNodeResultBuilder,
"LeafSetEntryNode is not valid for parent %s", current);
enter(name, leafsetEntryNodeBuilder());
nextSchema = null;
@Override
public void startMapEntryNode(final NodeIdentifierWithPredicates identifier, final int childSizeHint) {
final NormalizedNodeBuilder<?, ?, ?> current = current();
- checkArgument(current instanceof ImmutableMapNodeBuilder || current instanceof ImmutableOrderedMapNodeBuilder
+ checkArgument(current instanceof ImmutableMapNodeBuilder || current instanceof ImmutableUserMapNodeBuilder
|| current instanceof NormalizedNodeResultBuilder);
enter(identifier, UNKNOWN_SIZE == childSizeHint ? ImmutableMapEntryNodeBuilder.create()
@Override
public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) {
checkDataNodeContainer();
- enter(name, UNKNOWN_SIZE == childSizeHint ? ImmutableOrderedMapNodeBuilder.create()
- : ImmutableOrderedMapNodeBuilder.create(childSizeHint));
+ enter(name, UNKNOWN_SIZE == childSizeHint ? ImmutableUserMapNodeBuilder.create()
+ : ImmutableUserMapNodeBuilder.create(childSizeHint));
}
@Override
public void endNode() {
final NormalizedNodeBuilder finishedBuilder = builders.poll();
checkState(finishedBuilder != null, "Node which should be closed does not exists.");
- final NormalizedNode<PathArgument, ?> product = finishedBuilder.build();
+ final NormalizedNode product = finishedBuilder.build();
nextSchema = null;
writeChild(product);
* @throws IllegalStateException if there is no open builder
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
- protected final void writeChild(final NormalizedNode<?, ?> child) {
+ protected final void writeChild(final NormalizedNode child) {
final NormalizedNodeContainerBuilder current = currentContainer();
checkState(current != null, "Reached top level node, which could not be closed in this writer.");
current.addChild(requireNonNull(child));
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
@Override
@SuppressWarnings("unchecked")
- final NormalizedNode<?, ?> create(final PathArgument first, final Iterator<PathArgument> others,
- final Optional<NormalizedNode<?, ?>> lastChild) {
+ final NormalizedNode create(final PathArgument first, final Iterator<PathArgument> others,
+ final Optional<NormalizedNode> lastChild) {
if (!isMixin()) {
final QName type = getIdentifier().getNodeType();
if (type != null) {
final InstanceIdToNodes<?> childOp = getChildOperation(childPath);
builder.addChild(childOp.create(childPath, others, lastChild));
} else if (lastChild.isPresent()) {
- builder.withValue(ImmutableList.copyOf((Collection<?>) lastChild.get().getValue()));
+ builder.withValue(ImmutableList.copyOf((Collection<?>) lastChild.get().body()));
}
return builder.build();
}
}
- static final class OrderedLeafListMixinNormalization extends UnorderedLeafListMixinNormalization {
+ private abstract static class LeafListMixinNormalization extends InstanceIdToCompositeNodes<NodeIdentifier> {
+ private final InstanceIdToNodes<?> innerOp;
+
+ LeafListMixinNormalization(final LeafListSchemaNode potential) {
+ super(NodeIdentifier.create(potential.getQName()));
+ innerOp = new InstanceIdToSimpleNodes.LeafListEntryNormalization(potential);
+ }
+
+ @Override
+ final InstanceIdToNodes<?> getChild(final PathArgument child) {
+ return child instanceof NodeWithValue ? innerOp : null;
+ }
+
+ @Override
+ final boolean isMixin() {
+ return true;
+ }
+ }
+
+ static final class OrderedLeafListMixinNormalization extends LeafListMixinNormalization {
OrderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
super(potential);
}
}
}
- static class UnorderedLeafListMixinNormalization extends InstanceIdToCompositeNodes<NodeIdentifier> {
- private final InstanceIdToNodes<?> innerOp;
-
+ static class UnorderedLeafListMixinNormalization extends LeafListMixinNormalization {
UnorderedLeafListMixinNormalization(final LeafListSchemaNode potential) {
- super(NodeIdentifier.create(potential.getQName()));
- innerOp = new InstanceIdToSimpleNodes.LeafListEntryNormalization(potential);
+ super(potential);
}
@Override
ListNodeBuilder<?, ?> createBuilder(final PathArgument compositeNode) {
return Builders.leafSetBuilder().withNodeIdentifier(getIdentifier());
}
-
- @Override
- final InstanceIdToNodes<?> getChild(final PathArgument child) {
- return child instanceof NodeWithValue ? innerOp : null;
- }
-
- @Override
- final boolean isMixin() {
- return true;
- }
}
static final class AugmentationNormalization
}
@Override
- CollectionNodeBuilder<MapEntryNode, OrderedMapNode> createBuilder(final PathArgument compositeNode) {
+ CollectionNodeBuilder<MapEntryNode, UserMapNode> createBuilder(final PathArgument compositeNode) {
return Builders.orderedMapBuilder().withNodeIdentifier(getIdentifier());
}
}
import java.util.Optional;
import javax.xml.transform.dom.DOMSource;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
* @param child child identifier
* @return transformation strategy for a specific child
*/
- abstract InstanceIdToNodes<?> getChild(PathArgument child);
+ abstract @Nullable InstanceIdToNodes<?> getChild(PathArgument child);
/**
* Convert instance identifier into a NormalizedNode structure.
* @param operation Optional modify operation to be set on the last child
* @return NormalizedNode structure corresponding to submitted instance ID
*/
- abstract @NonNull NormalizedNode<?, ?> create(PathArgument first, Iterator<PathArgument> others,
- Optional<NormalizedNode<?, ?>> deepestChild);
+ abstract @NonNull NormalizedNode create(PathArgument first, Iterator<PathArgument> others,
+ Optional<NormalizedNode> deepestChild);
abstract boolean isMixin();
}
@Override
- NormalizedNode<?, ?> create(final PathArgument first, final Iterator<PathArgument> others,
- final Optional<NormalizedNode<?, ?>> deepestChild) {
+ NormalizedNode create(final PathArgument first, final Iterator<PathArgument> others,
+ final Optional<NormalizedNode> deepestChild) {
checkState(deepestChild.isPresent(), "Cannot instantiate anydata node without a value");
- final NormalizedNode<?, ?> child = deepestChild.get();
+ final NormalizedNode child = deepestChild.get();
checkState(child instanceof AnydataNode, "Invalid child %s", child);
return createAnydata((AnydataNode<?>) child);
}
private <T> AnydataNode<T> createAnydata(final AnydataNode<T> child) {
- return Builders.anydataBuilder(child.getValueObjectModel()).withValue(child.getValue())
+ return Builders.anydataBuilder(child.bodyObjectModel()).withValue(child.body())
.withNodeIdentifier(getIdentifier()).build();
}
}
}
@Override
- NormalizedNode<?, ?> create(final PathArgument first, final Iterator<PathArgument> others,
- final Optional<NormalizedNode<?, ?>> deepestChild) {
+ NormalizedNode create(final PathArgument first, final Iterator<PathArgument> others,
+ final Optional<NormalizedNode> deepestChild) {
final NormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode> builder =
Builders.anyXmlBuilder()
.withNodeIdentifier(getIdentifier());
if (deepestChild.isPresent()) {
- final NormalizedNode<?, ?> child = deepestChild.get();
+ final NormalizedNode child = deepestChild.get();
checkState(child instanceof DOMSourceAnyxmlNode, "Invalid child %s", child);
- builder.withValue(((DOMSourceAnyxmlNode) child).getValue());
+ builder.withValue(((DOMSourceAnyxmlNode) child).body());
}
return builder.build();
findChoice(Iterables.filter(parent.getChildNodes(), ChoiceSchemaNode.class), child));
}
- static InstanceIdToNodes<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) {
+ static @Nullable InstanceIdToNodes<?> fromSchemaAndQNameChecked(final DataNodeContainer schema, final QName child) {
final Optional<DataSchemaNode> potential = findChildSchemaNode(schema, child);
checkArgument(potential.isPresent(),
"Supplied QName %s is not valid according to schema %s, potential children nodes: %s", child, schema,
return fromDataSchemaNode(result);
}
- private static ChoiceSchemaNode findChoice(final Iterable<ChoiceSchemaNode> choices, final QName child) {
+ private static @Nullable ChoiceSchemaNode findChoice(final Iterable<ChoiceSchemaNode> choices, final QName child) {
for (final ChoiceSchemaNode choice : choices) {
for (final CaseSchemaNode caze : choice.getCases()) {
if (findChildSchemaNode(caze, child).isPresent()) {
* otherwise returns a SchemaPathUtil for child as
* call for {@link #fromDataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode)}.
*/
- private static InstanceIdToNodes<?> fromAugmentation(final DataNodeContainer parent,
+ private static @Nullable InstanceIdToNodes<?> fromAugmentation(final DataNodeContainer parent,
final AugmentationTarget parentAug, final DataSchemaNode child) {
for (final AugmentationSchemaNode aug : parentAug.getAvailableAugmentations()) {
final Optional<DataSchemaNode> potential = aug.findDataChildByName(child.getQName());
return fromDataSchemaNode(child);
}
- static InstanceIdToNodes<?> fromDataSchemaNode(final DataSchemaNode potential) {
+ static @Nullable InstanceIdToNodes<?> fromDataSchemaNode(final DataSchemaNode potential) {
if (potential instanceof ContainerLike) {
return new InstanceIdToCompositeNodes.ContainerTransformation((ContainerLike) potential);
} else if (potential instanceof ListSchemaNode) {
}
@Override
- final NormalizedNode<?, ?> create(final PathArgument first, final Iterator<PathArgument> others,
- final Optional<NormalizedNode<?, ?>> deepestChild) {
- final NormalizedNodeBuilder<? extends PathArgument, Object,
- ? extends NormalizedNode<? extends PathArgument, Object>> builder = getBuilder(first);
+ final NormalizedNode create(final PathArgument first, final Iterator<PathArgument> others,
+ final Optional<NormalizedNode> deepestChild) {
+ final NormalizedNodeBuilder<? extends PathArgument, Object, ? extends NormalizedNode> builder =
+ getBuilder(first);
if (deepestChild.isPresent()) {
- builder.withValue(deepestChild.get().getValue());
+ builder.withValue(deepestChild.orElseThrow().body());
}
return builder.build();
return false;
}
- abstract NormalizedNodeBuilder<? extends PathArgument, Object,
- ? extends NormalizedNode<? extends PathArgument, Object>> getBuilder(PathArgument node);
+ abstract NormalizedNodeBuilder<? extends PathArgument, Object, ? extends NormalizedNode> getBuilder(
+ PathArgument node);
static final class LeafNormalization extends InstanceIdToSimpleNodes<NodeIdentifier> {
LeafNormalization(final LeafSchemaNode potential) {
import static java.util.Objects.requireNonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
import org.opendaylight.yangtools.yang.data.util.LeafsetEntryInterner;
this.interner = requireNonNull(interner);
}
- private static LeafsetEntryInterner getInterner(final DataSchemaNode schema) {
+ private static @Nullable LeafsetEntryInterner getInterner(final @Nullable DataSchemaNode schema) {
return schema instanceof LeafListSchemaNode ? LeafsetEntryInterner.forSchema((LeafListSchemaNode) schema)
: null;
}
- static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> create(final DataSchemaNode schema) {
+ static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> create(final @Nullable DataSchemaNode schema) {
final LeafsetEntryInterner interner = getInterner(schema);
if (interner != null) {
return new InterningLeafSetNodeBuilder<>(interner);
return ImmutableLeafSetNodeBuilder.create();
}
- static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> create(final DataSchemaNode schema, final int sizeHint) {
+ static <T> ListNodeBuilder<T, SystemLeafSetNode<T>> create(final @Nullable DataSchemaNode schema,
+ final int sizeHint) {
final LeafsetEntryInterner interner = getInterner(schema);
if (interner != null) {
return new InterningLeafSetNodeBuilder<>(interner, sizeHint);
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withChild(final LeafSetEntryNode<T> child) {
+ public ImmutableLeafSetNodeBuilder<T> withChild(final LeafSetEntryNode<T> child) {
return super.withChild(interner.intern(child));
}
}
*/
public class NormalizedNodeResult {
private boolean finished = false;
- private NormalizedNode<?,?> result;
+ private NormalizedNode result;
- public NormalizedNode<?, ?> getResult() {
+ public NormalizedNode getResult() {
return result;
}
return finished;
}
- void setResult(final NormalizedNode<?, ?> result) {
+ void setResult(final NormalizedNode result) {
if (finished) {
throw new ResultAlreadySetException("Normalized Node result was already set.", this.result);
}
public class ResultAlreadySetException extends IllegalStateException {
private static final long serialVersionUID = 1L;
- private final transient NormalizedNode<?, ?> resultData;
+ private final transient NormalizedNode resultData;
- public ResultAlreadySetException(final String message, final NormalizedNode<?, ?> resultData) {
+ public ResultAlreadySetException(final String message, final NormalizedNode resultData) {
this(message, resultData, null);
}
- public ResultAlreadySetException(final String message, final NormalizedNode<?, ?> resultData,
+ public ResultAlreadySetException(final String message, final NormalizedNode resultData,
final Throwable cause) {
super(message, cause);
this.resultData = resultData;
}
- public NormalizedNode<?, ?> getResultData() {
+ public NormalizedNode getResultData() {
return resultData;
}
}
}
@Override
- public NormalizedNode<?, ?> getResult() {
+ public NormalizedNode getResult() {
return builder.result().getResult();
}
}
@Override
- public SchemaOrderedNormalizedNodeWriter write(final NormalizedNode<?, ?> node) throws IOException {
+ public SchemaOrderedNormalizedNodeWriter write(final NormalizedNode node) throws IOException {
if (Objects.equals(root, schemaContext)) {
currentSchemaNode = schemaContext.getDataChildByName(node.getNodeType());
} else {
* @return NormalizedNodeWriter this
* @throws IOException when thrown from the backing writer.
*/
- public SchemaOrderedNormalizedNodeWriter write(final Collection<DataContainerChild<?,?>> nodes) throws IOException {
+ public SchemaOrderedNormalizedNodeWriter write(final Collection<DataContainerChild> nodes) throws IOException {
currentSchemaNode = root;
if (writeChildren(nodes, currentSchemaNode, false)) {
return this;
throw new IllegalStateException("It wasn't possible to serialize nodes " + nodes);
}
- private SchemaOrderedNormalizedNodeWriter write(final NormalizedNode<?, ?> node, final SchemaNode dataSchemaNode)
+ private SchemaOrderedNormalizedNodeWriter write(final NormalizedNode node, final SchemaNode dataSchemaNode)
throws IOException {
//Set current schemaNode
throw new IllegalStateException("It wasn't possible to serialize node " + node);
}
- private void write(final List<NormalizedNode<?, ?>> nodes, final SchemaNode dataSchemaNode) throws IOException {
- for (final NormalizedNode<?, ?> node : nodes) {
+ private void write(final List<NormalizedNode> nodes, final SchemaNode dataSchemaNode) throws IOException {
+ for (final NormalizedNode node : nodes) {
write(node, dataSchemaNode);
}
}
@Override
- protected boolean writeChildren(final Iterable<? extends NormalizedNode<?, ?>> children) throws IOException {
+ protected boolean writeChildren(final Iterable<? extends NormalizedNode> children) throws IOException {
return writeChildren(children, currentSchemaNode, true);
}
- private boolean writeChildren(final Iterable<? extends NormalizedNode<?, ?>> children,
- final SchemaNode parentSchemaNode, final boolean endParent) throws IOException {
+ private boolean writeChildren(final Iterable<? extends NormalizedNode> children, final SchemaNode parentSchemaNode,
+ final boolean endParent) throws IOException {
//Augmentations cannot be gotten with node.getChild so create our own structure with augmentations resolved
- final ArrayListMultimap<QName, NormalizedNode<?, ?>> qNameToNodes = ArrayListMultimap.create();
- for (final NormalizedNode<?, ?> child : children) {
+ final ArrayListMultimap<QName, NormalizedNode> qNameToNodes = ArrayListMultimap.create();
+ for (final NormalizedNode child : children) {
if (child instanceof AugmentationNode) {
qNameToNodes.putAll(resolveAugmentations(child));
} else {
}
}
} else {
- for (final NormalizedNode<?, ?> child : children) {
+ for (final NormalizedNode child : children) {
writeLeaf(child);
}
}
return true;
}
- private SchemaOrderedNormalizedNodeWriter writeLeaf(final NormalizedNode<?, ?> node) throws IOException {
+ private SchemaOrderedNormalizedNodeWriter writeLeaf(final NormalizedNode node) throws IOException {
if (wasProcessAsSimpleNode(node)) {
return this;
}
throw new IllegalStateException("It wasn't possible to serialize node " + node);
}
- private ArrayListMultimap<QName, NormalizedNode<?, ?>> resolveAugmentations(final NormalizedNode<?, ?> child) {
- final ArrayListMultimap<QName, NormalizedNode<?, ?>> resolvedAugs = ArrayListMultimap.create();
- for (final NormalizedNode<?, ?> node : ((AugmentationNode) child).getValue()) {
+ private ArrayListMultimap<QName, NormalizedNode> resolveAugmentations(final NormalizedNode child) {
+ final ArrayListMultimap<QName, NormalizedNode> resolvedAugs = ArrayListMultimap.create();
+ for (final NormalizedNode node : ((AugmentationNode) child).body()) {
if (node instanceof AugmentationNode) {
resolvedAugs.putAll(resolveAugmentations(node));
} else {
return realChildNodes;
}
- public static Optional<CaseSchemaNode> detectCase(final ChoiceSchemaNode schema,
- final DataContainerChild<?, ?> child) {
+ public static Optional<CaseSchemaNode> detectCase(final ChoiceSchemaNode schema, final DataContainerChild child) {
for (final CaseSchemaNode choiceCaseNode : schema.getCases()) {
if (child instanceof AugmentationNode
- && belongsToCaseAugment(choiceCaseNode, (AugmentationIdentifier) child.getIdentifier())) {
- return Optional.of(choiceCaseNode);
- } else if (choiceCaseNode.findDataChildByName(child.getNodeType()).isPresent()) {
+ && belongsToCaseAugment(choiceCaseNode, (AugmentationIdentifier) child.getIdentifier())
+ || choiceCaseNode.findDataChildByName(child.getNodeType()).isPresent()) {
return Optional.of(choiceCaseNode);
}
}
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-public interface CollectionNodeBuilder<V extends NormalizedNode<?, ?>, R extends NormalizedNode<NodeIdentifier, ?>>
+public interface CollectionNodeBuilder<V extends NormalizedNode, R extends NormalizedNode>
extends NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, V, R> {
@Override
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
public interface DataContainerNodeBuilder<I extends PathArgument, R extends DataContainerNode<I>>
- extends NormalizedNodeContainerBuilder<I, PathArgument, DataContainerChild<? extends PathArgument, ?>, R> {
-
+ extends NormalizedNodeContainerBuilder<I, PathArgument, DataContainerChild, R> {
@Override
- DataContainerNodeBuilder<I, R> withValue(Collection<DataContainerChild<? extends PathArgument, ?>> value);
+ DataContainerNodeBuilder<I, R> withValue(Collection<DataContainerChild> value);
@Override
DataContainerNodeBuilder<I, R> withNodeIdentifier(I nodeIdentifier);
- @NonNull DataContainerNodeBuilder<I, R> withChild(DataContainerChild<?, ?> child);
+ @NonNull DataContainerNodeBuilder<I, R> withChild(DataContainerChild child);
@NonNull DataContainerNodeBuilder<I, R> withoutChild(PathArgument key);
}
\ No newline at end of file
package org.opendaylight.yangtools.yang.data.impl.schema.builder.api;
import java.util.Collection;
-import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
-public interface ListNodeBuilder<T, V>
- extends CollectionNodeBuilder<LeafSetEntryNode<T>, LeafSetNode<T>> {
-
+public interface ListNodeBuilder<T, V extends LeafSetNode<T>> extends CollectionNodeBuilder<LeafSetEntryNode<T>, V> {
@Override
ListNodeBuilder<T, V> withNodeIdentifier(NodeIdentifier nodeIdentifier);
@Override
ListNodeBuilder<T, V> withoutChild(PathArgument key);
- @NonNull ListNodeBuilder<T, V> withChildValue(T child);
+ ListNodeBuilder<T, V> withChildValue(T child);
}
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-public interface NormalizedNodeBuilder<I extends PathArgument, V, R extends NormalizedNode<I, ?>> extends Builder<R> {
+public interface NormalizedNodeBuilder<I extends PathArgument, V, R extends NormalizedNode> extends Builder<R> {
@NonNull NormalizedNodeBuilder<I, V, R> withValue(V value);
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
public interface NormalizedNodeContainerBuilder<K extends PathArgument, CK extends PathArgument,
- CV extends NormalizedNode<? extends CK, ?>, P extends NormalizedNode<K, ?>>
- extends NormalizedNodeBuilder<K, Collection<CV>, P> {
+ CV extends NormalizedNode, P extends NormalizedNode> extends NormalizedNodeBuilder<K, Collection<CV>, P> {
@Override
NormalizedNodeContainerBuilder<K, CK, CV, P> withNodeIdentifier(K nodeIdentifier);
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.util.ModifiableMapPhase;
import org.opendaylight.yangtools.util.UnmodifiableMapPhase;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
this.dirty = false;
}
- protected AbstractImmutableDataContainerNodeBuilder(final AbstractImmutableDataContainerNode<I> node) {
+ protected AbstractImmutableDataContainerNodeBuilder(final AbstractImmutableDataContainerNode<I, R> node) {
this.nodeIdentifier = node.getIdentifier();
/*
return nodeIdentifier;
}
- protected final DataContainerChild<? extends PathArgument, ?> getChild(final PathArgument child) {
+ protected final @Nullable DataContainerChild getChild(final PathArgument child) {
return LazyLeafOperations.getChild(value, child);
}
}
@Override
- public DataContainerNodeBuilder<I, R> withValue(
- final Collection<DataContainerChild<? extends PathArgument, ?>> withValue) {
+ public DataContainerNodeBuilder<I, R> withValue(final Collection<DataContainerChild> withValue) {
// TODO Replace or putAll ?
- for (final DataContainerChild<? extends PathArgument, ?> dataContainerChild : withValue) {
+ for (final DataContainerChild dataContainerChild : withValue) {
withChild(dataContainerChild);
}
return this;
}
@Override
- public DataContainerNodeBuilder<I, R> withChild(final DataContainerChild<?, ?> child) {
+ public DataContainerNodeBuilder<I, R> withChild(final DataContainerChild child) {
checkDirty();
LazyLeafOperations.putChild(value, child);
return this;
}
@Override
- public DataContainerNodeBuilder<I, R> addChild(
- final DataContainerChild<? extends PathArgument, ?> child) {
+ public DataContainerNodeBuilder<I, R> addChild(final DataContainerChild child) {
return withChild(child);
}
@Override
- public NormalizedNodeContainerBuilder<I, PathArgument, DataContainerChild<? extends PathArgument, ?>, R>
- removeChild(final PathArgument key) {
+ public NormalizedNodeContainerBuilder<I, PathArgument, DataContainerChild, R> removeChild(final PathArgument key) {
return withoutChild(key);
}
import static com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
-abstract class AbstractImmutableNormalizedNodeBuilder<I extends PathArgument, V, R extends NormalizedNode<I, ?>>
+abstract class AbstractImmutableNormalizedNodeBuilder<I extends PathArgument, V, R extends NormalizedNode>
implements NormalizedNodeBuilder<I, V, R> {
- private I nodeIdentifier;
- private V value;
+ private @Nullable I nodeIdentifier = null;
+ private @Nullable V value = null;
protected final I getNodeIdentifier() {
checkState(nodeIdentifier != null, "Identifier has not been set");
return new ImmutableAnyXmlNodeBuilder();
}
+ @Override
+ public ImmutableAnyXmlNodeBuilder withValue(final DOMSource withValue) {
+ super.withValue(withValue);
+ return this;
+ }
+
@Override
public DOMSourceAnyxmlNode build() {
return new ImmutableXmlNode(getNodeIdentifier(), getValue());
}
private static final class ImmutableXmlNode
- extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, DOMSource>
+ extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, DOMSourceAnyxmlNode, DOMSource>
implements DOMSourceAnyxmlNode {
ImmutableXmlNode(final NodeIdentifier nodeIdentifier, final DOMSource value) {
super(nodeIdentifier, value);
}
+
+ @Override
+ protected Class<DOMSourceAnyxmlNode> implementedType() {
+ return DOMSourceAnyxmlNode.class;
+ }
}
}
import org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode;
public final class ImmutableAnyXmlNodeSchemaAwareBuilder extends ImmutableAnyXmlNodeBuilder {
-
private ImmutableAnyXmlNodeSchemaAwareBuilder(final AnyxmlSchemaNode schema) {
super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
}
}
@Override
- public NormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode> withValue(final DOMSource withValue) {
+ public ImmutableAnyXmlNodeBuilder withValue(final DOMSource withValue) {
return super.withValue(withValue);
}
@Override
- public NormalizedNodeBuilder<NodeIdentifier, DOMSource, DOMSourceAnyxmlNode> withNodeIdentifier(
- final NodeIdentifier withNodeIdentifier) {
+ public ImmutableAnyXmlNodeBuilder withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
}
@Beta
public class ImmutableAnydataNodeBuilder<V>
extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, V, AnydataNode<V>> {
- private final Class<V> objectModel;
+ private final @NonNull Class<V> objectModel;
ImmutableAnydataNodeBuilder(final Class<V> objectModel) {
this.objectModel = requireNonNull(objectModel);
}
- public static <V> @NonNull NormalizedNodeBuilder<NodeIdentifier, V, AnydataNode<V>> create(
- final Class<V> objectModel) {
+ public static <V> NormalizedNodeBuilder<NodeIdentifier, V, AnydataNode<V>> create(final Class<V> objectModel) {
return new ImmutableAnydataNodeBuilder<>(objectModel);
}
}
private static final class ImmutableAnydataNode<V>
- extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, V> implements AnydataNode<V> {
- private final @NonNull Class<V> objectModel;
+ extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, AnydataNode<?>, V>
+ implements AnydataNode<V> {
+ private final Class<V> objectModel;
protected ImmutableAnydataNode(final NodeIdentifier nodeIdentifier, final V value, final Class<V> objectModel) {
super(nodeIdentifier, value);
}
@Override
- public Class<V> getValueObjectModel() {
+ public Class<V> bodyObjectModel() {
return objectModel;
}
+
+ @Override
+ protected Class<AnydataNode<?>> implementedType() {
+ return (Class) AnydataNode.class;
+ }
}
}
@Override
public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withChild(
- final DataContainerChild<?, ?> child) {
+ final DataContainerChild child) {
// Check nested augments
DataValidationException.checkLegalData(!(child instanceof AugmentationNode),
"Unable to add: %s, as a child for: %s, Nested augmentations are not permitted", child.getNodeType(),
}
private static final class ImmutableAugmentationNode
- extends AbstractImmutableDataContainerNode<AugmentationIdentifier> implements AugmentationNode {
+ extends AbstractImmutableDataContainerNode<AugmentationIdentifier, AugmentationNode>
+ implements AugmentationNode {
ImmutableAugmentationNode(final AugmentationIdentifier nodeIdentifier,
final Map<PathArgument, Object> children) {
super(children, nodeIdentifier);
}
+
+ @Override
+ protected Class<AugmentationNode> implementedType() {
+ return AugmentationNode.class;
+ }
}
}
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
public class ImmutableAugmentationNodeSchemaAwareBuilder extends ImmutableAugmentationNodeBuilder {
-
private final DataNodeContainerValidator validator;
protected ImmutableAugmentationNodeSchemaAwareBuilder(final AugmentationSchemaNode schema) {
@Override
public DataContainerNodeBuilder<AugmentationIdentifier, AugmentationNode> withChild(
- final DataContainerChild<?, ?> child) {
+ final DataContainerChild child) {
return super.withChild(validator.validateChild(child));
}
return new ImmutableChoiceNode(getNodeIdentifier(), buildValue());
}
- private static final class ImmutableChoiceNode extends AbstractImmutableDataContainerNode<NodeIdentifier>
- implements ChoiceNode {
-
+ private static final class ImmutableChoiceNode
+ extends AbstractImmutableDataContainerNode<NodeIdentifier, ChoiceNode> implements ChoiceNode {
ImmutableChoiceNode(final NodeIdentifier nodeIdentifier, final Map<PathArgument, Object> children) {
super(children, nodeIdentifier);
}
+
+ @Override
+ protected Class<ChoiceNode> implementedType() {
+ return ChoiceNode.class;
+ }
}
}
import static java.util.Objects.requireNonNull;
import java.util.Optional;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
public class ImmutableChoiceNodeSchemaAwareBuilder extends ImmutableChoiceNodeBuilder {
-
private final ChoiceSchemaNode schema;
- private DataNodeContainerValidator validator;
+
+ private @Nullable DataNodeContainerValidator validator = null;
protected ImmutableChoiceNodeSchemaAwareBuilder(final ChoiceSchemaNode schema) {
this.schema = requireNonNull(schema, "Schema was null");
}
@Override
- public DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> withChild(final DataContainerChild<?, ?> child) {
+ public DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> withChild(final DataContainerChild child) {
if (validator == null) {
Optional<CaseSchemaNode> detectedCaseOpt = SchemaUtils.detectCase(schema, child);
DataValidationException.checkLegalChild(detectedCaseOpt.isPresent(), child.getIdentifier(), schema);
return super.build();
}
- public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> create(final ChoiceSchemaNode schema) {
+ public static DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> create(final ChoiceSchemaNode schema) {
return new ImmutableChoiceNodeSchemaAwareBuilder(schema);
}
}
public class ImmutableContainerNodeBuilder
extends AbstractImmutableDataContainerNodeBuilder<NodeIdentifier, ContainerNode> {
-
protected ImmutableContainerNodeBuilder() {
}
return new ImmutableContainerNodeBuilder(sizeHint);
}
- public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(
- final ContainerNode node) {
+ public static @NonNull DataContainerNodeBuilder<NodeIdentifier, ContainerNode> create(final ContainerNode node) {
if (!(node instanceof ImmutableContainerNode)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
return new ImmutableContainerNode(getNodeIdentifier(), buildValue());
}
- protected static final class ImmutableContainerNode extends AbstractImmutableDataContainerNode<NodeIdentifier>
- implements ContainerNode {
-
+ protected static final class ImmutableContainerNode
+ extends AbstractImmutableDataContainerNode<NodeIdentifier, ContainerNode> implements ContainerNode {
ImmutableContainerNode(final NodeIdentifier nodeIdentifier, final Map<PathArgument, Object> children) {
super(children, nodeIdentifier);
}
+
+ @Override
+ protected Class<ContainerNode> implementedType() {
+ return ContainerNode.class;
+ }
}
}
}
@Override
- public DataContainerNodeBuilder<NodeIdentifier, ContainerNode> withChild(final DataContainerChild<?, ?> child) {
+ public DataContainerNodeBuilder<NodeIdentifier, ContainerNode> withChild(final DataContainerChild child) {
validator.validateChild(child.getIdentifier());
return super.withChild(child);
}
return createNode(getNodeIdentifier(), getValue());
}
- private static final class ImmutableLeafNode<T>
- extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, T> implements LeafNode<T> {
+ private static class ImmutableLeafNode<T>
+ extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, LeafNode<?>, T> implements LeafNode<T> {
ImmutableLeafNode(final NodeIdentifier nodeIdentifier, final T value) {
super(nodeIdentifier, value);
}
+
+ @Override
+ protected final Class<LeafNode<?>> implementedType() {
+ return (Class) LeafNode.class;
+ }
}
- private static final class ImmutableBinaryLeafNode
- extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, byte[]> implements LeafNode<byte[]> {
+ private static final class ImmutableBinaryLeafNode extends ImmutableLeafNode<byte[]> {
ImmutableBinaryLeafNode(final NodeIdentifier nodeIdentifier, final byte[] value) {
super(nodeIdentifier, value);
}
}
private static final class ImmutableLeafSetEntryNode<T>
- extends AbstractImmutableNormalizedSimpleValueNode<NodeWithValue, T> implements LeafSetEntryNode<T> {
+ extends AbstractImmutableNormalizedSimpleValueNode<NodeWithValue, LeafSetEntryNode<?>, T>
+ implements LeafSetEntryNode<T> {
ImmutableLeafSetEntryNode(final NodeWithValue nodeIdentifier, final T value) {
super(nodeIdentifier, value);
checkArgument(Objects.deepEquals(nodeIdentifier.getValue(), value),
"Node identifier contains different value: %s than value itself: %s", nodeIdentifier, value);
}
+
+ @Override
+ protected Class<LeafSetEntryNode<?>> implementedType() {
+ return (Class) LeafSetEntryNode.class;
+ }
}
}
}
@Override
- public NormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> withValue(final T withValue) {
+ public ImmutableLeafSetEntryNodeBuilder<T> withValue(final T withValue) {
super.withNodeIdentifier(new NodeWithValue<>(schema.getQName(), withValue));
// TODO check value type using TypeProvider ?
- return super.withValue(withValue);
+ super.withValue(withValue);
+ return this;
}
@Override
- public NormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> withNodeIdentifier(
- final NodeWithValue withNodeIdentifier) {
+ public ImmutableLeafSetEntryNodeBuilder<T> withNodeIdentifier(final NodeWithValue withNodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
}
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.util.MapAdaptor;
import org.opendaylight.yangtools.util.UnmodifiableCollection;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueNode;
-public class ImmutableLeafSetNodeBuilder<T> implements ListNodeBuilder<T, LeafSetEntryNode<T>> {
+public class ImmutableLeafSetNodeBuilder<T> implements ListNodeBuilder<T, SystemLeafSetNode<T>> {
private static final int DEFAULT_CAPACITY = 4;
- private final Map<NodeWithValue, LeafSetEntryNode<T>> value;
+ private final Map<NodeWithValue<?>, LeafSetEntryNode<T>> value;
+
private NodeIdentifier nodeIdentifier;
protected ImmutableLeafSetNodeBuilder() {
value = MapAdaptor.getDefaultInstance().takeSnapshot(node.children);
}
- public static <T> @NonNull ListNodeBuilder<T, LeafSetEntryNode<T>> create() {
+ public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create() {
return new ImmutableLeafSetNodeBuilder<>();
}
- public static <T> @NonNull ListNodeBuilder<T, LeafSetEntryNode<T>> create(final int sizeHint) {
+ public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create(final int sizeHint) {
return new ImmutableLeafSetNodeBuilder<>(sizeHint);
}
- public static <T> @NonNull ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafSetNode<T> node) {
+ public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create(final SystemLeafSetNode<T> node) {
if (!(node instanceof ImmutableLeafSetNode<?>)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withChild(final LeafSetEntryNode<T> child) {
+ public ImmutableLeafSetNodeBuilder<T> withChild(final LeafSetEntryNode<T> child) {
this.value.put(child.getIdentifier(), child);
return this;
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withoutChild(final PathArgument key) {
+ public ImmutableLeafSetNodeBuilder<T> withoutChild(final PathArgument key) {
this.value.remove(key);
return this;
}
@Override
- public LeafSetNode<T> build() {
+ public SystemLeafSetNode<T> build() {
return new ImmutableLeafSetNode<>(nodeIdentifier, MapAdaptor.getDefaultInstance().optimize(value));
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
+ public ImmutableLeafSetNodeBuilder<T> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
this.nodeIdentifier = withNodeIdentifier;
return this;
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withValue(final Collection<LeafSetEntryNode<T>> withValue) {
+ public ImmutableLeafSetNodeBuilder<T> withValue(final Collection<LeafSetEntryNode<T>> withValue) {
for (final LeafSetEntryNode<T> leafSetEntry : withValue) {
withChild(leafSetEntry);
}
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withChildValue(final T childValue) {
+ public ImmutableLeafSetNodeBuilder<T> withChildValue(final T childValue) {
return withChild(ImmutableLeafSetEntryNodeBuilder.<T>create()
.withNodeIdentifier(new NodeWithValue<>(nodeIdentifier.getNodeType(), childValue))
.withValue(childValue).build());
}
- protected static final class ImmutableLeafSetNode<T> extends
- AbstractImmutableNormalizedValueNode<NodeIdentifier, Collection<LeafSetEntryNode<T>>> implements
- LeafSetNode<T> {
- private final Map<NodeWithValue, LeafSetEntryNode<T>> children;
+ @Override
+ public ImmutableLeafSetNodeBuilder<T> addChild(final LeafSetEntryNode<T> child) {
+ return withChild(child);
+ }
+
+ @Override
+ public ImmutableLeafSetNodeBuilder<T> removeChild(final PathArgument key) {
+ return withoutChild(key);
+ }
+
+ protected static final class ImmutableLeafSetNode<T>
+ extends AbstractImmutableNormalizedValueNode<NodeIdentifier, SystemLeafSetNode<?>,
+ Collection<@NonNull LeafSetEntryNode<T>>>
+ implements SystemLeafSetNode<T> {
+
+ private final Map<NodeWithValue<?>, LeafSetEntryNode<T>> children;
ImmutableLeafSetNode(final NodeIdentifier nodeIdentifier,
- final Map<NodeWithValue, LeafSetEntryNode<T>> children) {
+ final Map<NodeWithValue<?>, LeafSetEntryNode<T>> children) {
super(nodeIdentifier, UnmodifiableCollection.create(children.values()));
this.children = children;
}
@Override
- public Optional<LeafSetEntryNode<T>> getChild(final NodeWithValue child) {
- return Optional.ofNullable(children.get(child));
+ public LeafSetEntryNode<T> childByArg(final NodeWithValue<?> child) {
+ return children.get(child);
}
@Override
return children.size();
}
+ @Override
+ protected Class<SystemLeafSetNode<?>> implementedType() {
+ return (Class) SystemLeafSetNode.class;
+ }
+
@Override
protected int valueHashCode() {
return children.hashCode();
}
@Override
- protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
+ protected boolean valueEquals(final SystemLeafSetNode<?> other) {
return children.equals(((ImmutableLeafSetNode<?>) other).children);
}
}
-
- @Override
- public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, LeafSetNode<T>> addChild(
- final LeafSetEntryNode<T> child) {
- return withChild(child);
- }
-
- @Override
- public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, LeafSetNode<T>>
- removeChild(final PathArgument key) {
- return withoutChild(key);
- }
-
}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
public final class ImmutableLeafSetNodeSchemaAwareBuilder<T> extends ImmutableLeafSetNodeBuilder<T> {
-
private final LeafListSchemaNode schema;
private ImmutableLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema) {
super.withNodeIdentifier(new NodeIdentifier(schema.getQName()));
}
- public static <T> @NonNull ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafListSchemaNode schema) {
+ public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create(final LeafListSchemaNode schema) {
return new ImmutableLeafSetNodeSchemaAwareBuilder<>(schema);
}
- public static <T> @NonNull ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafListSchemaNode schema,
- final LeafSetNode<T> node) {
+ public static <T> @NonNull ListNodeBuilder<T, SystemLeafSetNode<T>> create(final LeafListSchemaNode schema,
+ final SystemLeafSetNode<T> node) {
if (!(node instanceof ImmutableLeafSetNode<?>)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withChildValue(final T childValue) {
+ public ImmutableLeafSetNodeBuilder<T> withChildValue(final T childValue) {
// TODO check value type
return super.withChildValue(childValue);
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withChild(final LeafSetEntryNode<T> child) {
+ public ImmutableLeafSetNodeBuilder<T> withChild(final LeafSetEntryNode<T> child) {
checkArgument(schema.getQName().equals(child.getNodeType()),
"Incompatible node type, should be: %s, is: %s", schema.getQName(), child.getNodeType());
// TODO check value type using TypeProvider ?
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
+ public ImmutableLeafSetNodeBuilder<T> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
}
protected ImmutableMapEntryNodeBuilder(final ImmutableMapEntryNode node) {
super(node);
this.childrenQNamesToPaths = new LinkedHashMap<>();
- fillQnames(node.getValue(), childrenQNamesToPaths);
+ fillQnames(node.body(), childrenQNamesToPaths);
}
public static @NonNull DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> create() {
return new ImmutableMapEntryNodeBuilder((ImmutableMapEntryNode)node);
}
- private static void fillQnames(final Iterable<DataContainerChild<? extends PathArgument, ?>> iterable,
- final Map<QName, PathArgument> out) {
- for (final DataContainerChild<? extends PathArgument, ?> childId : iterable) {
+ private static void fillQnames(final Iterable<DataContainerChild> iterable, final Map<QName, PathArgument> out) {
+ for (final DataContainerChild childId : iterable) {
final PathArgument identifier = childId.getIdentifier();
// Augmentation nodes cannot be keys, and do not have to be present in childrenQNamesToPaths map
@Override
public DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> withValue(
- final Collection<DataContainerChild<? extends PathArgument, ?>> withValue) {
+ final Collection<DataContainerChild> withValue) {
fillQnames(withValue, childrenQNamesToPaths);
return super.withValue(withValue);
}
@Override
public DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> withChild(
- final DataContainerChild<?, ?> child) {
+ final DataContainerChild child) {
// Augmentation nodes cannot be keys, and do not have to be present in childrenQNamesToPaths map
if (!isAugment(child.getIdentifier())) {
childrenQNamesToPaths.put(child.getNodeType(), child.getIdentifier());
@Override
public MapEntryNode build() {
for (final Entry<QName, Object> key : getNodeIdentifier().entrySet()) {
- final DataContainerChild<?, ?> childNode = getChild(childrenQNamesToPaths.get(key.getKey()));
+ final DataContainerChild childNode = getChild(childrenQNamesToPaths.get(key.getKey()));
// We have enough information to fill-in missing leaf nodes, so let's do that
if (childNode == null) {
withChild(leaf);
} else {
DataValidationException.checkListKey(getNodeIdentifier(), key.getKey(), key.getValue(),
- childNode.getValue());
+ childNode.body());
}
}
}
private static final class ImmutableMapEntryNode
- extends AbstractImmutableDataContainerNode<NodeIdentifierWithPredicates> implements MapEntryNode {
+ extends AbstractImmutableDataContainerNode<NodeIdentifierWithPredicates, MapEntryNode>
+ implements MapEntryNode {
ImmutableMapEntryNode(final NodeIdentifierWithPredicates nodeIdentifier,
final Map<PathArgument, Object> children) {
super(children, nodeIdentifier);
}
+
+ @Override
+ protected Class<MapEntryNode> implementedType() {
+ return MapEntryNode.class;
+ }
}
}
import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.util.ImmutableMapTemplate;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
@Override
public DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> withChild(
- final DataContainerChild<?, ?> child) {
+ final DataContainerChild child) {
validator.validateChild(child.getIdentifier());
return super.withChild(child);
}
final Object[] values = new Object[childrenQNamesToPaths.size()];
int offset = 0;
for (Entry<QName, PathArgument> entry : childrenQNamesToPaths.entrySet()) {
- values[offset++] = nonnullKeyValue(entry.getKey(), getChild(entry.getValue())).getValue();
+ values[offset++] = nonnullKeyValue(entry.getKey(), getChild(entry.getValue())).body();
}
return ImmutableMapTemplate.ordered(childrenQNamesToPaths.keySet()).instantiateWithValues(values);
}
final Object[] values = new Object[keys.size()];
int offset = 0;
for (QName key : keys) {
- values[offset++] = nonnullKeyValue(key, getChild(childrenQNamesToPaths.get(key))).getValue();
+ values[offset++] = nonnullKeyValue(key, getChild(childrenQNamesToPaths.get(key))).body();
}
return ImmutableMapTemplate.ordered(keys).instantiateWithValues(values);
}
- private DataContainerChild<?, ?> nonnullKeyValue(final QName key, final DataContainerChild<?, ?> value) {
+ private DataContainerChild nonnullKeyValue(final QName key, final @Nullable DataContainerChild value) {
if (value != null) {
return value;
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.collect.Maps;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.util.MapAdaptor;
-import org.opendaylight.yangtools.util.UnmodifiableCollection;
+import org.opendaylight.yangtools.util.UnmodifiableMap;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedNode;
-public class ImmutableMapNodeBuilder implements CollectionNodeBuilder<MapEntryNode, MapNode> {
+public class ImmutableMapNodeBuilder implements CollectionNodeBuilder<MapEntryNode, SystemMapNode> {
private static final int DEFAULT_CAPACITY = 4;
private final Map<NodeIdentifierWithPredicates, MapEntryNode> value;
- private NodeIdentifier nodeIdentifier;
+
+ private @Nullable NodeIdentifier nodeIdentifier = null;
protected ImmutableMapNodeBuilder() {
this.value = new HashMap<>(DEFAULT_CAPACITY);
}
}
- protected ImmutableMapNodeBuilder(final ImmutableMapNode node) {
+ protected ImmutableMapNodeBuilder(final SystemMapNode node) {
this.nodeIdentifier = node.getIdentifier();
- this.value = MapAdaptor.getDefaultInstance().takeSnapshot(node.children);
+ this.value = MapAdaptor.getDefaultInstance().takeSnapshot(
+ node instanceof ImmutableMapNode ? ((ImmutableMapNode) node).children : node.asMap());
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, MapNode> create() {
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> create() {
return new ImmutableMapNodeBuilder();
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, MapNode> create(final int sizeHint) {
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> create(final int sizeHint) {
return new ImmutableMapNodeBuilder(sizeHint);
}
- public static CollectionNodeBuilder<MapEntryNode, MapNode> create(final MapNode node) {
- if (!(node instanceof ImmutableMapNode)) {
- throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
- }
-
- return new ImmutableMapNodeBuilder((ImmutableMapNode) node);
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> create(final SystemMapNode node) {
+ return new ImmutableMapNodeBuilder(node);
}
@Override
- public CollectionNodeBuilder<MapEntryNode, MapNode> withChild(final MapEntryNode child) {
+ public ImmutableMapNodeBuilder withChild(final MapEntryNode child) {
this.value.put(child.getIdentifier(), child);
return this;
}
@Override
- public CollectionNodeBuilder<MapEntryNode, MapNode> withoutChild(final PathArgument key) {
+ public ImmutableMapNodeBuilder withoutChild(final PathArgument key) {
this.value.remove(key);
return this;
}
@Override
- public CollectionNodeBuilder<MapEntryNode, MapNode> withValue(final Collection<MapEntryNode> withValue) {
+ public ImmutableMapNodeBuilder withValue(final Collection<MapEntryNode> withValue) {
// TODO replace or putAll ?
for (final MapEntryNode mapEntryNode : withValue) {
withChild(mapEntryNode);
}
@Override
- public CollectionNodeBuilder<MapEntryNode, MapNode> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
+ public ImmutableMapNodeBuilder withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
this.nodeIdentifier = withNodeIdentifier;
return this;
}
@Override
- public MapNode build() {
+ public SystemMapNode build() {
return new ImmutableMapNode(nodeIdentifier, MapAdaptor.getDefaultInstance().optimize(value));
}
@Override
- public CollectionNodeBuilder<MapEntryNode, MapNode> addChild(
- final MapEntryNode child) {
+ public ImmutableMapNodeBuilder addChild(final MapEntryNode child) {
return withChild(child);
}
@Override
- public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, MapEntryNode, MapNode> removeChild(
- final PathArgument key) {
+ public ImmutableMapNodeBuilder removeChild(final PathArgument key) {
return withoutChild(key);
}
- protected static final class ImmutableMapNode
- extends AbstractImmutableNormalizedNode<NodeIdentifier, Collection<MapEntryNode>> implements MapNode {
+ protected static final class ImmutableMapNode extends AbstractImmutableNormalizedNode<NodeIdentifier, SystemMapNode>
+ implements SystemMapNode {
- private final Map<NodeIdentifierWithPredicates, MapEntryNode> children;
+ private final @NonNull Map<NodeIdentifierWithPredicates, MapEntryNode> children;
ImmutableMapNode(final NodeIdentifier nodeIdentifier,
final Map<NodeIdentifierWithPredicates, MapEntryNode> children) {
super(nodeIdentifier);
- this.children = children;
+ this.children = requireNonNull(children);
}
@Override
- public Optional<MapEntryNode> getChild(final NodeIdentifierWithPredicates child) {
- return Optional.ofNullable(children.get(child));
+ public MapEntryNode childByArg(final NodeIdentifierWithPredicates child) {
+ return children.get(child);
}
@Override
- public Collection<MapEntryNode> getValue() {
- return UnmodifiableCollection.create(children.values());
+ public Map<NodeIdentifierWithPredicates, MapEntryNode> asMap() {
+ return UnmodifiableMap.of(children);
}
@Override
return children.size();
}
+ @Override
+ protected Class<SystemMapNode> implementedType() {
+ return SystemMapNode.class;
+ }
+
@Override
protected int valueHashCode() {
return children.hashCode();
}
@Override
- protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
- return children.equals(((ImmutableMapNode) other).children);
+ protected boolean valueEquals(final SystemMapNode other) {
+ final Map<NodeIdentifierWithPredicates, MapEntryNode> otherChildren =
+ other instanceof ImmutableMapNode ? ((ImmutableMapNode) other).children : other.asMap();
+ return children.equals(otherChildren);
}
}
}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, MapNode> create(final ListSchemaNode schema) {
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> create(final ListSchemaNode schema) {
return new ImmutableMapNodeSchemaAwareBuilder(schema);
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, MapNode> create(final ListSchemaNode schema,
- final MapNode node) {
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, SystemMapNode> create(final ListSchemaNode schema,
+ final SystemMapNode node) {
if (!(node instanceof ImmutableMapNode)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
}
@Override
- public CollectionNodeBuilder<MapEntryNode, MapNode> withChild(final MapEntryNode child) {
+ public ImmutableMapNodeBuilder withChild(final MapEntryNode child) {
DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
schema, Collections.singleton(schema.getQName()));
return super.withChild(child);
}
@Override
- public CollectionNodeBuilder<MapEntryNode, MapNode> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
+ public ImmutableMapNodeBuilder withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
}
}
protected static final class ImmutableUnkeyedListEntryNode
- extends AbstractImmutableDataContainerNode<NodeIdentifier> implements UnkeyedListEntryNode {
-
+ extends AbstractImmutableDataContainerNode<NodeIdentifier, UnkeyedListEntryNode>
+ implements UnkeyedListEntryNode {
ImmutableUnkeyedListEntryNode(final NodeIdentifier nodeIdentifier, final Map<PathArgument, Object> children) {
super(children, nodeIdentifier);
}
+
+ @Override
+ protected Class<UnkeyedListEntryNode> implementedType() {
+ return UnkeyedListEntryNode.class;
+ }
}
}
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
this.nodeIdentifier = node.getIdentifier();
// FIXME: clean this up, notably reuse unmodified lists
this.value = new LinkedList<>();
- Iterables.addAll(value, node.getValue());
+ Iterables.addAll(value, node.body());
this.dirty = true;
}
- public static @NonNull CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> create() {
+ public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> create() {
return new ImmutableUnkeyedListNodeBuilder();
}
- public static @NonNull CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> create(final int sizeHint) {
+ public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> create(final int sizeHint) {
return new ImmutableUnkeyedListNodeBuilder();
}
- public static @NonNull CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> create(
+ public static CollectionNodeBuilder<UnkeyedListEntryNode, UnkeyedListNode> create(
final UnkeyedListNode node) {
if (!(node instanceof ImmutableUnkeyedListNode)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
return withoutChild(key);
}
- protected static final class EmptyImmutableUnkeyedListNode extends
- AbstractImmutableNormalizedNode<NodeIdentifier, Collection<UnkeyedListEntryNode>> implements
- UnkeyedListNode {
+ protected static final class EmptyImmutableUnkeyedListNode
+ extends AbstractImmutableNormalizedNode<NodeIdentifier, UnkeyedListNode> implements UnkeyedListNode {
protected EmptyImmutableUnkeyedListNode(final NodeIdentifier nodeIdentifier) {
super(nodeIdentifier);
}
@Override
- public ImmutableList<UnkeyedListEntryNode> getValue() {
+ public ImmutableList<UnkeyedListEntryNode> body() {
return ImmutableList.of();
}
}
@Override
- public int getSize() {
+ public int size() {
return 0;
}
@Override
- protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
- return Collections.emptyList().equals(other.getValue());
+ protected Class<UnkeyedListNode> implementedType() {
+ return UnkeyedListNode.class;
}
@Override
protected int valueHashCode() {
return 1;
}
+
+ @Override
+ protected boolean valueEquals(final UnkeyedListNode other) {
+ return other.isEmpty();
+ }
}
- protected static final class ImmutableUnkeyedListNode extends
- AbstractImmutableNormalizedValueNode<NodeIdentifier, Collection<UnkeyedListEntryNode>>
+ protected static final class ImmutableUnkeyedListNode
+ extends AbstractImmutableNormalizedValueNode<NodeIdentifier, UnkeyedListNode,
+ Collection<@NonNull UnkeyedListEntryNode>>
implements UnkeyedListNode {
private final ImmutableList<UnkeyedListEntryNode> children;
}
@Override
- protected int valueHashCode() {
- return children.hashCode();
+ public UnkeyedListEntryNode getChild(final int position) {
+ return children.get(position);
+ }
+
+ @Override
+ public int size() {
+ return children.size();
}
@Override
- protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
- return children.equals(((ImmutableUnkeyedListNode) other).children);
+ protected Class<UnkeyedListNode> implementedType() {
+ return UnkeyedListNode.class;
}
@Override
- public UnkeyedListEntryNode getChild(final int position) {
- return children.get(position);
+ protected int valueHashCode() {
+ return children.hashCode();
}
@Override
- public int getSize() {
- return children.size();
+ protected boolean valueEquals(final UnkeyedListNode other) {
+ final Collection<UnkeyedListEntryNode> otherChildren;
+ if (other instanceof ImmutableUnkeyedListNode) {
+ otherChildren = ((ImmutableUnkeyedListNode) other).children;
+ } else {
+ otherChildren = other.body();
+ }
+ return otherChildren instanceof List ? children.equals(otherChildren)
+ : Iterables.elementsEqual(children, otherChildren);
}
}
}
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.util.UnmodifiableCollection;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedNode;
-public class ImmutableOrderedLeafSetNodeBuilder<T> implements ListNodeBuilder<T, LeafSetEntryNode<T>> {
+public class ImmutableUserLeafSetNodeBuilder<T> implements ListNodeBuilder<T, UserLeafSetNode<T>> {
private Map<NodeWithValue, LeafSetEntryNode<T>> value;
private NodeIdentifier nodeIdentifier;
private boolean dirty;
- protected ImmutableOrderedLeafSetNodeBuilder() {
+ protected ImmutableUserLeafSetNodeBuilder() {
value = new LinkedHashMap<>();
dirty = false;
}
- protected ImmutableOrderedLeafSetNodeBuilder(final ImmutableOrderedLeafSetNode<T> node) {
+ protected ImmutableUserLeafSetNodeBuilder(final ImmutableUserLeafSetNode<T> node) {
nodeIdentifier = node.getIdentifier();
value = node.getChildren();
dirty = true;
}
- public static <T> @NonNull ListNodeBuilder<T, LeafSetEntryNode<T>> create() {
- return new ImmutableOrderedLeafSetNodeBuilder<>();
+ public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create() {
+ return new ImmutableUserLeafSetNodeBuilder<>();
}
- public static <T> @NonNull ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafSetNode<T> node) {
- if (!(node instanceof ImmutableOrderedLeafSetNode<?>)) {
+ public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create(
+ final UserLeafSetNode<T> node) {
+ if (!(node instanceof ImmutableUserLeafSetNode<?>)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
- return new ImmutableOrderedLeafSetNodeBuilder<>((ImmutableOrderedLeafSetNode<T>) node);
+ return new ImmutableUserLeafSetNodeBuilder<>((ImmutableUserLeafSetNode<T>) node);
}
private void checkDirty() {
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withChild(final LeafSetEntryNode<T> child) {
+ public ImmutableUserLeafSetNodeBuilder<T> withChild(final LeafSetEntryNode<T> child) {
checkDirty();
this.value.put(child.getIdentifier(), child);
return this;
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withoutChild(final PathArgument key) {
+ public ImmutableUserLeafSetNodeBuilder<T> withoutChild(final PathArgument key) {
checkDirty();
this.value.remove(key);
return this;
}
@Override
- public OrderedLeafSetNode<T> build() {
+ public UserLeafSetNode<T> build() {
dirty = true;
- return new ImmutableOrderedLeafSetNode<>(nodeIdentifier, value);
+ return new ImmutableUserLeafSetNode<>(nodeIdentifier, value);
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
+ public ImmutableUserLeafSetNodeBuilder<T> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
this.nodeIdentifier = withNodeIdentifier;
return this;
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withValue(final Collection<LeafSetEntryNode<T>> withValue) {
+ public ImmutableUserLeafSetNodeBuilder<T> withValue(final Collection<LeafSetEntryNode<T>> withValue) {
checkDirty();
for (final LeafSetEntryNode<T> leafSetEntry : withValue) {
withChild(leafSetEntry);
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withChildValue(final T childValue) {
+ public ImmutableUserLeafSetNodeBuilder<T> withChildValue(final T childValue) {
return withChild(ImmutableLeafSetEntryNodeBuilder.<T>create()
.withNodeIdentifier(new NodeWithValue<>(nodeIdentifier.getNodeType(), childValue))
.withValue(childValue).build());
}
- protected static final class ImmutableOrderedLeafSetNode<T> extends
- AbstractImmutableNormalizedNode<NodeIdentifier, Collection<LeafSetEntryNode<T>>> implements
- OrderedLeafSetNode<T> {
-
+ protected static final class ImmutableUserLeafSetNode<T>
+ extends AbstractImmutableNormalizedNode<NodeIdentifier, UserLeafSetNode<?>>
+ implements UserLeafSetNode<T> {
private final Map<NodeWithValue, LeafSetEntryNode<T>> children;
- ImmutableOrderedLeafSetNode(final NodeIdentifier nodeIdentifier,
+ ImmutableUserLeafSetNode(final NodeIdentifier nodeIdentifier,
final Map<NodeWithValue, LeafSetEntryNode<T>> children) {
super(nodeIdentifier);
this.children = children;
}
@Override
- public Optional<LeafSetEntryNode<T>> getChild(final NodeWithValue child) {
- return Optional.ofNullable(children.get(child));
+ public LeafSetEntryNode<T> childByArg(final NodeWithValue child) {
+ return children.get(child);
}
@Override
}
@Override
- protected int valueHashCode() {
- return children.hashCode();
+ public int size() {
+ return children.size();
}
- @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
- justification = "https://github.com/spotbugs/spotbugs/issues/811")
- private Map<NodeWithValue, LeafSetEntryNode<T>> getChildren() {
- return Collections.unmodifiableMap(children);
+ @Override
+ public Collection<LeafSetEntryNode<T>> body() {
+ return UnmodifiableCollection.create(children.values());
}
@Override
- protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
- return children.equals(((ImmutableOrderedLeafSetNode<?>) other).children);
+ protected Class<UserLeafSetNode<?>> implementedType() {
+ return (Class) UserLeafSetNode.class;
}
@Override
- public int getSize() {
- return children.size();
+ protected int valueHashCode() {
+ return children.hashCode();
}
@Override
- public Collection<LeafSetEntryNode<T>> getValue() {
- return UnmodifiableCollection.create(children.values());
+ protected boolean valueEquals(final UserLeafSetNode<?> other) {
+ return children.equals(((ImmutableUserLeafSetNode<?>) other).children);
+ }
+
+ @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
+ justification = "https://github.com/spotbugs/spotbugs/issues/811")
+ private Map<NodeWithValue, LeafSetEntryNode<T>> getChildren() {
+ return Collections.unmodifiableMap(children);
}
}
@Override
- public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, LeafSetNode<T>> addChild(
- final LeafSetEntryNode<T> child) {
+ public ImmutableUserLeafSetNodeBuilder<T> addChild(final LeafSetEntryNode<T> child) {
return withChild(child);
}
@Override
- public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, LeafSetEntryNode<T>, LeafSetNode<T>>
- removeChild(final PathArgument key) {
+ public ImmutableUserLeafSetNodeBuilder<T> removeChild(final PathArgument key) {
return withoutChild(key);
}
}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
-public final class ImmutableOrderedLeafSetNodeSchemaAwareBuilder<T> extends ImmutableOrderedLeafSetNodeBuilder<T> {
-
+public final class ImmutableUserLeafSetNodeSchemaAwareBuilder<T> extends ImmutableUserLeafSetNodeBuilder<T> {
private final LeafListSchemaNode schema;
- private ImmutableOrderedLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema) {
+ private ImmutableUserLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema) {
this.schema = requireNonNull(schema);
super.withNodeIdentifier(new NodeIdentifier(schema.getQName()));
}
- public ImmutableOrderedLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema,
- final ImmutableOrderedLeafSetNode<T> node) {
+ public ImmutableUserLeafSetNodeSchemaAwareBuilder(final LeafListSchemaNode schema,
+ final ImmutableUserLeafSetNode<T> node) {
super(node);
this.schema = requireNonNull(schema);
// FIXME: Preconditions.checkArgument(schema.getQName().equals(node.getIdentifier()));
super.withNodeIdentifier(new NodeIdentifier(schema.getQName()));
}
- public static <T> @NonNull ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafListSchemaNode schema) {
- return new ImmutableOrderedLeafSetNodeSchemaAwareBuilder<>(schema);
+ public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create(final LeafListSchemaNode schema) {
+ return new ImmutableUserLeafSetNodeSchemaAwareBuilder<>(schema);
}
- public static <T> @NonNull ListNodeBuilder<T, LeafSetEntryNode<T>> create(final LeafListSchemaNode schema,
- final LeafSetNode<T> node) {
- if (!(node instanceof ImmutableOrderedLeafSetNode<?>)) {
+ public static <T> @NonNull ListNodeBuilder<T, UserLeafSetNode<T>> create(final LeafListSchemaNode schema,
+ final UserLeafSetNode<T> node) {
+ if (!(node instanceof ImmutableUserLeafSetNode<?>)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
- return new ImmutableOrderedLeafSetNodeSchemaAwareBuilder<>(schema, (ImmutableOrderedLeafSetNode<T>) node);
+ return new ImmutableUserLeafSetNodeSchemaAwareBuilder<>(schema, (ImmutableUserLeafSetNode<T>) node);
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withChildValue(final T childValue) {
+ public ImmutableUserLeafSetNodeBuilder<T> withChildValue(final T childValue) {
// TODO check value type
return super.withChildValue(childValue);
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withChild(final LeafSetEntryNode<T> child) {
+ public ImmutableUserLeafSetNodeBuilder<T> withChild(final LeafSetEntryNode<T> child) {
checkArgument(schema.getQName().equals(child.getNodeType()), "Incompatible node type, should be: %s, is: %s",
schema.getQName(), child.getNodeType());
// TODO check value type using TypeProvider ?
}
@Override
- public ListNodeBuilder<T, LeafSetEntryNode<T>> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
+ public ImmutableUserLeafSetNodeBuilder<T> withNodeIdentifier(final NodeIdentifier withNodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
}
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.util.UnmodifiableCollection;
+import org.opendaylight.yangtools.util.UnmodifiableMap;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedNode;
-public class ImmutableOrderedMapNodeBuilder implements CollectionNodeBuilder<MapEntryNode, OrderedMapNode> {
+public class ImmutableUserMapNodeBuilder implements CollectionNodeBuilder<MapEntryNode, UserMapNode> {
private static final int DEFAULT_CAPACITY = 4;
private Map<NodeIdentifierWithPredicates, MapEntryNode> value;
private NodeIdentifier nodeIdentifier;
private boolean dirty;
- protected ImmutableOrderedMapNodeBuilder() {
+ protected ImmutableUserMapNodeBuilder() {
this.value = new LinkedHashMap<>(DEFAULT_CAPACITY);
this.dirty = false;
}
- protected ImmutableOrderedMapNodeBuilder(final int sizeHint) {
+ protected ImmutableUserMapNodeBuilder(final int sizeHint) {
if (sizeHint >= 0) {
this.value = new LinkedHashMap<>(sizeHint + sizeHint / 3);
} else {
this.dirty = false;
}
- protected ImmutableOrderedMapNodeBuilder(final ImmutableOrderedMapNode node) {
+ protected ImmutableUserMapNodeBuilder(final ImmutableUserMapNode node) {
this.nodeIdentifier = node.getIdentifier();
this.value = node.children;
this.dirty = true;
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, OrderedMapNode> create() {
- return new ImmutableOrderedMapNodeBuilder();
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create() {
+ return new ImmutableUserMapNodeBuilder();
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, OrderedMapNode> create(final int sizeHint) {
- return new ImmutableOrderedMapNodeBuilder(sizeHint);
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create(final int sizeHint) {
+ return new ImmutableUserMapNodeBuilder(sizeHint);
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, OrderedMapNode> create(final MapNode node) {
- if (!(node instanceof ImmutableOrderedMapNode)) {
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create(final UserMapNode node) {
+ if (!(node instanceof ImmutableUserMapNode)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
- return new ImmutableOrderedMapNodeBuilder((ImmutableOrderedMapNode) node);
+ return new ImmutableUserMapNodeBuilder((ImmutableUserMapNode) node);
}
private void checkDirty() {
}
@Override
- public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withChild(final MapEntryNode child) {
+ public CollectionNodeBuilder<MapEntryNode, UserMapNode> withChild(final MapEntryNode child) {
checkDirty();
this.value.put(child.getIdentifier(), child);
return this;
}
@Override
- public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withoutChild(final PathArgument key) {
+ public CollectionNodeBuilder<MapEntryNode, UserMapNode> withoutChild(final PathArgument key) {
checkDirty();
this.value.remove(key);
return this;
}
@Override
- public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withValue(final Collection<MapEntryNode> withValue) {
+ public CollectionNodeBuilder<MapEntryNode, UserMapNode> withValue(final Collection<MapEntryNode> withValue) {
// TODO replace or putAll ?
for (final MapEntryNode mapEntryNode : withValue) {
withChild(mapEntryNode);
}
@Override
- public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withNodeIdentifier(
+ public CollectionNodeBuilder<MapEntryNode, UserMapNode> withNodeIdentifier(
final NodeIdentifier withNodeIdentifier) {
this.nodeIdentifier = withNodeIdentifier;
return this;
}
@Override
- public OrderedMapNode build() {
+ public UserMapNode build() {
dirty = true;
- return new ImmutableOrderedMapNode(nodeIdentifier, value);
+ return new ImmutableUserMapNode(nodeIdentifier, value);
}
@Override
- public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> addChild(
+ public CollectionNodeBuilder<MapEntryNode, UserMapNode> addChild(
final MapEntryNode child) {
return withChild(child);
}
@Override
- public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, MapEntryNode, OrderedMapNode> removeChild(
+ public NormalizedNodeContainerBuilder<NodeIdentifier, PathArgument, MapEntryNode, UserMapNode> removeChild(
final PathArgument key) {
return withoutChild(key);
}
- protected static final class ImmutableOrderedMapNode
- extends AbstractImmutableNormalizedNode<NodeIdentifier, Collection<MapEntryNode>>
- implements OrderedMapNode {
-
+ protected static final class ImmutableUserMapNode
+ extends AbstractImmutableNormalizedNode<NodeIdentifier, UserMapNode> implements UserMapNode {
private final Map<NodeIdentifierWithPredicates, MapEntryNode> children;
- ImmutableOrderedMapNode(final NodeIdentifier nodeIdentifier,
+ ImmutableUserMapNode(final NodeIdentifier nodeIdentifier,
final Map<NodeIdentifierWithPredicates, MapEntryNode> children) {
super(nodeIdentifier);
this.children = children;
}
@Override
- public Optional<MapEntryNode> getChild(final NodeIdentifierWithPredicates child) {
- return Optional.ofNullable(children.get(child));
+ public MapEntryNode childByArg(final NodeIdentifierWithPredicates child) {
+ return children.get(child);
}
@Override
}
@Override
- protected int valueHashCode() {
- return children.hashCode();
+ public Collection<MapEntryNode> body() {
+ return UnmodifiableCollection.create(children.values());
}
@Override
- protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
- return children.equals(((ImmutableOrderedMapNode) other).children);
+ public Map<NodeIdentifierWithPredicates, MapEntryNode> asMap() {
+ return UnmodifiableMap.of(children);
}
@Override
- public int getSize() {
- return children.size();
+ protected Class<UserMapNode> implementedType() {
+ return UserMapNode.class;
}
@Override
- public Collection<MapEntryNode> getValue() {
- return UnmodifiableCollection.create(children.values());
+ protected int valueHashCode() {
+ // Order is important
+ int hashCode = 1;
+ for (MapEntryNode child : children.values()) {
+ hashCode = 31 * hashCode + child.hashCode();
+ }
+ return hashCode;
+ }
+
+ @Override
+ protected boolean valueEquals(final UserMapNode other) {
+ final Map<NodeIdentifierWithPredicates, MapEntryNode> otherChildren;
+ if (other instanceof ImmutableUserMapNode) {
+ otherChildren = ((ImmutableUserMapNode) other).children;
+ } else {
+ otherChildren = other.asMap();
+ }
+ return Iterables.elementsEqual(children.values(), otherChildren.values());
}
}
}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid.DataValidationException;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-public class ImmutableOrderedMapNodeSchemaAwareBuilder extends ImmutableOrderedMapNodeBuilder {
+public class ImmutableUserMapNodeSchemaAwareBuilder extends ImmutableUserMapNodeBuilder {
private final ListSchemaNode schema;
- protected ImmutableOrderedMapNodeSchemaAwareBuilder(final ListSchemaNode schema) {
+ protected ImmutableUserMapNodeSchemaAwareBuilder(final ListSchemaNode schema) {
this.schema = requireNonNull(schema);
super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
}
- protected ImmutableOrderedMapNodeSchemaAwareBuilder(final ListSchemaNode schema,
- final ImmutableOrderedMapNode node) {
+ protected ImmutableUserMapNodeSchemaAwareBuilder(final ListSchemaNode schema,
+ final ImmutableUserMapNode node) {
super(node);
this.schema = requireNonNull(schema);
super.withNodeIdentifier(NodeIdentifier.create(schema.getQName()));
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, OrderedMapNode> create(final ListSchemaNode schema) {
- return new ImmutableOrderedMapNodeSchemaAwareBuilder(schema);
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create(final ListSchemaNode schema) {
+ return new ImmutableUserMapNodeSchemaAwareBuilder(schema);
}
- public static @NonNull CollectionNodeBuilder<MapEntryNode, OrderedMapNode> create(final ListSchemaNode schema,
- final MapNode node) {
- if (!(node instanceof ImmutableOrderedMapNode)) {
+ public static @NonNull CollectionNodeBuilder<MapEntryNode, UserMapNode> create(final ListSchemaNode schema,
+ final UserMapNode node) {
+ if (!(node instanceof ImmutableUserMapNode)) {
throw new UnsupportedOperationException(String.format("Cannot initialize from class %s", node.getClass()));
}
- return new ImmutableOrderedMapNodeSchemaAwareBuilder(schema, (ImmutableOrderedMapNode) node);
+ return new ImmutableUserMapNodeSchemaAwareBuilder(schema, (ImmutableUserMapNode) node);
}
@Override
- public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withChild(final MapEntryNode child) {
+ public CollectionNodeBuilder<MapEntryNode, UserMapNode> withChild(final MapEntryNode child) {
DataValidationException.checkLegalChild(schema.getQName().equals(child.getNodeType()), child.getIdentifier(),
schema, Collections.singleton(schema.getQName()));
return super.withChild(child);
}
@Override
- public CollectionNodeBuilder<MapEntryNode, OrderedMapNode> withNodeIdentifier(
+ public CollectionNodeBuilder<MapEntryNode, UserMapNode> withNodeIdentifier(
final NodeIdentifier withNodeIdentifier) {
throw new UnsupportedOperationException("Node identifier created from schema");
}
}
private static final class ImmutableYangModeledAnyXmlNode extends
- AbstractImmutableDataContainerNode<NodeIdentifier> implements YangModeledAnyXmlNode {
-
+ AbstractImmutableDataContainerNode<NodeIdentifier, YangModeledAnyXmlNode> implements YangModeledAnyXmlNode {
private final @NonNull ContainerSchemaNode contentSchema;
ImmutableYangModeledAnyXmlNode(final NodeIdentifier nodeIdentifier, final Map<PathArgument, Object> value,
}
@Override
+ @Deprecated
public ContainerSchemaNode getSchemaOfAnyXmlData() {
return contentSchema;
}
+
+ @Override
+ protected Class<YangModeledAnyXmlNode> implementedType() {
+ return YangModeledAnyXmlNode.class;
+ }
}
}
DataValidationException.checkLegalChild(isKnownChild(child), child, schema, childNodes, augments);
}
- public DataContainerChild<?, ?> validateChild(final DataContainerChild<?, ?> child) {
+ public DataContainerChild validateChild(final DataContainerChild child) {
validateChild(child.getIdentifier());
return child;
}
}
}
- public static void checkListKey(final DataContainerChild<?, ?> childNode, final Map<QName, Object> keyValues,
+ public static void checkListKey(final DataContainerChild childNode, final Map<QName, Object> keyValues,
final QName keyQName, final NodeIdentifierWithPredicates nodeId) {
checkListKey(childNode, keyQName, nodeId);
final Object expected = keyValues.get(keyQName);
- final Object actual = childNode.getValue();
+ final Object actual = childNode.body();
checkListKey(nodeId, keyQName, expected, actual);
}
- public static void checkListKey(final DataContainerChild<?, ?> childNode, final QName keyQName,
+ public static void checkListKey(final DataContainerChild childNode, final QName keyQName,
final NodeIdentifierWithPredicates nodeId) {
if (childNode == null) {
throw new IllegalListKeyException(keyQName, nodeId);
import java.util.Collection;
import java.util.Map;
-import java.util.Optional;
import org.opendaylight.yangtools.util.ImmutableOffsetMap;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
-public abstract class AbstractImmutableDataContainerNode<K extends PathArgument>
- extends AbstractImmutableNormalizedNode<K, Collection<DataContainerChild<? extends PathArgument, ?>>>
- implements DataContainerNode<K> {
+public abstract class AbstractImmutableDataContainerNode<K extends PathArgument, N extends DataContainerNode<K>>
+ extends AbstractImmutableNormalizedNode<K, N> implements DataContainerNode<K> {
private final Map<PathArgument, Object> children;
protected AbstractImmutableDataContainerNode(final Map<PathArgument, Object> children, final K nodeIdentifier) {
super(nodeIdentifier);
-
this.children = ImmutableOffsetMap.unorderedCopyOf(children);
}
@Override
- public final Optional<DataContainerChild<? extends PathArgument, ?>> getChild(final PathArgument child) {
- return Optional.ofNullable(LazyLeafOperations.getChild(children, child));
+ public final DataContainerChild childByArg(final PathArgument child) {
+ return LazyLeafOperations.getChild(children, child);
}
@Override
- public final Collection<DataContainerChild<? extends PathArgument, ?>> getValue() {
+ public final Collection<DataContainerChild> body() {
return new LazyValues(children);
}
return children.size();
}
- @Override
- protected int valueHashCode() {
- return children.hashCode();
- }
-
/**
* DO NOT USE THIS METHOD.
*
}
@Override
- protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
- return other instanceof AbstractImmutableDataContainerNode<?> && children.equals(
- ((AbstractImmutableDataContainerNode<?>) other).children);
+ protected int valueHashCode() {
+ return children.hashCode();
+ }
+
+ @Override
+ protected boolean valueEquals(final N other) {
+ return other instanceof AbstractImmutableDataContainerNode<?, ?> && children.equals(
+ ((AbstractImmutableDataContainerNode<?, ?>) other).children);
}
}
package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
import com.google.common.base.MoreObjects.ToStringHelper;
-import org.opendaylight.yangtools.concepts.AbstractSimpleIdentifiable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.concepts.AbstractIdentifiable;
import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-public abstract class AbstractImmutableNormalizedNode<K extends PathArgument, V> extends AbstractSimpleIdentifiable<K>
- implements NormalizedNode<K, V>, Immutable {
+public abstract class AbstractImmutableNormalizedNode<K extends PathArgument, N extends NormalizedNode>
+ extends AbstractIdentifiable<PathArgument, K> implements NormalizedNode, Immutable {
protected AbstractImmutableNormalizedNode(final K nodeIdentifier) {
super(nodeIdentifier);
}
- @Override
- public final QName getNodeType() {
- return getIdentifier().getNodeType();
- }
-
- @Override
- protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
- return super.addToStringAttributes(toStringHelper).add("value", getValue());
- }
-
- protected abstract boolean valueEquals(AbstractImmutableNormalizedNode<?, ?> other);
-
- protected abstract int valueHashCode();
-
@Override
public final boolean equals(final Object obj) {
if (this == obj) {
return true;
}
- if (obj == null || this.getClass() != obj.getClass()) {
+ final Class<N> clazz = implementedType();
+ if (!clazz.isInstance(obj)) {
return false;
}
-
- final AbstractImmutableNormalizedNode<?, ?> other = (AbstractImmutableNormalizedNode<?, ?>)obj;
+ final N other = clazz.cast(obj);
return getIdentifier().equals(other.getIdentifier()) && valueEquals(other);
}
public final int hashCode() {
return 31 * getIdentifier().hashCode() + valueHashCode();
}
+
+ @Override
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ return super.addToStringAttributes(toStringHelper).add("body", body());
+ }
+
+ protected abstract @NonNull Class<N> implementedType();
+
+ protected abstract int valueHashCode();
+
+ protected abstract boolean valueEquals(@NonNull N other);
}
import java.util.Objects;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-public abstract class AbstractImmutableNormalizedSimpleValueNode<K extends PathArgument,V>
- extends AbstractImmutableNormalizedValueNode<K, V> {
+public abstract class AbstractImmutableNormalizedSimpleValueNode<K extends PathArgument, N extends NormalizedNode, V>
+ extends AbstractImmutableNormalizedValueNode<K, N, V> {
protected AbstractImmutableNormalizedSimpleValueNode(final K nodeIdentifier, final V value) {
super(nodeIdentifier, value);
}
@Override
- protected int valueHashCode() {
- final V local = value();
- final int result = local != null ? local.hashCode() : 1;
- // FIXME: are attributes part of hashCode/equals?
- return result;
+ protected final int valueHashCode() {
+ return value().hashCode();
}
@Override
- protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
- // We can not call directly getValue.equals because of Empty Type
+ protected final boolean valueEquals(final N other) {
+ // We can not call directly body().equals because of Empty Type
// RequireInstanceStatementSupport leaves which always have NULL value
-
- // FIXME: are attributes part of hashCode/equals?
- return Objects.deepEquals(value(), other.getValue());
+ return Objects.deepEquals(value(), other.body());
}
}
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-public abstract class AbstractImmutableNormalizedValueNode<K extends PathArgument, V> extends
- AbstractImmutableNormalizedNode<K, V> {
-
+public abstract class AbstractImmutableNormalizedValueNode<K extends PathArgument, N extends NormalizedNode, V>
+ extends AbstractImmutableNormalizedNode<K, N> {
private final @NonNull V value;
protected AbstractImmutableNormalizedValueNode(final K nodeIdentifier, final @NonNull V value) {
}
@Override
- public final V getValue() {
+ public final V body() {
return wrapValue(value);
}
// Hidden on purpose
}
- public static @Nullable DataContainerChild<?, ?> getChild(final Map<PathArgument, Object> map,
- final PathArgument key) {
+ public static @Nullable DataContainerChild getChild(final Map<PathArgument, Object> map, final PathArgument key) {
final Object value = map.get(key);
return value == null ? null : decodeChild(key, value);
}
- public static void putChild(final Map<PathArgument, Object> map, final DataContainerChild<?, ?> child) {
- final DataContainerChild<?, ?> node = requireNonNull(child);
+ public static void putChild(final Map<PathArgument, Object> map, final DataContainerChild child) {
+ final DataContainerChild node = requireNonNull(child);
map.put(node.getIdentifier(), encodeExpendableChild(node));
}
return ImmutableNodes.leafNode((NodeIdentifier) key, value);
}
- private static @Nullable DataContainerChild<?, ?> decodeChild(final PathArgument key, final @NonNull Object value) {
+ private static @Nullable DataContainerChild decodeChild(final PathArgument key, final @NonNull Object value) {
return decodeExpendableChild(key, value);
}
- private static @NonNull DataContainerChild<?, ?> decodeExpendableChild(final PathArgument key,
- @NonNull final Object value) {
- return value instanceof DataContainerChild ? (DataContainerChild<?, ?>) value : coerceLeaf(key, value);
+ private static @NonNull DataContainerChild decodeExpendableChild(final PathArgument key,
+ final @NonNull Object value) {
+ return value instanceof DataContainerChild ? (DataContainerChild) value : coerceLeaf(key, value);
}
- private static @NonNull Object encodeExpendableChild(final @NonNull DataContainerChild<?, ?> node) {
- return node instanceof LeafNode ? verifyEncode(((LeafNode<?>) node).getValue()) : node;
+ private static @NonNull Object encodeExpendableChild(final @NonNull DataContainerChild node) {
+ return node instanceof LeafNode ? verifyEncode(((LeafNode<?>) node).body()) : node;
}
private static @NonNull Object verifyEncode(final @NonNull Object value) {
// NormalizedNode.getValue() does not compare as equal. When invoked twice and lazy leaves are in effect. Note that
// Collection.equals() is undefined, but the expectation from users is that we will return the same view object, which
// equals on identity.
-final class LazyValues extends AbstractCollection<DataContainerChild<?, ?>> {
+final class LazyValues extends AbstractCollection<DataContainerChild> {
private final Map<PathArgument, Object> map;
LazyValues(final Map<PathArgument, Object> map) {
}
@Override
- public Iterator<DataContainerChild<?, ?>> iterator() {
+ public Iterator<DataContainerChild> iterator() {
return new Iter(map.entrySet().iterator());
}
return this == obj || obj instanceof LazyValues && map.equals(((LazyValues)obj).map);
}
- private static final class Iter implements Iterator<DataContainerChild<?, ?>> {
+ private static final class Iter implements Iterator<DataContainerChild> {
private final Iterator<Entry<PathArgument, Object>> iterator;
Iter(final Iterator<Entry<PathArgument, Object>> iterator) {
}
@Override
- public DataContainerChild<?, ?> next() {
+ public DataContainerChild next() {
final Entry<PathArgument, Object> entry = iterator.next();
final Object value = entry.getValue();
- return value instanceof DataContainerChild ? (DataContainerChild<?, ?>) value
+ return value instanceof DataContainerChild ? (DataContainerChild) value
: LazyLeafOperations.coerceLeaf(entry.getKey(), value);
}
}
* Internal equivalent of {@link Collections}' unmodifiable Map. It does not retain
* keySet/entrySet references, thus lowering the memory overhead.
*/
-final class UnmodifiableChildrenMap
- implements CloneableMap<PathArgument, DataContainerChild<? extends PathArgument, ?>>, Serializable {
+final class UnmodifiableChildrenMap implements CloneableMap<PathArgument, DataContainerChild>, Serializable {
private static final long serialVersionUID = 1L;
/*
private static final int WRAP_THRESHOLD = 9;
@SuppressFBWarnings(value = "SE_BAD_FIELD", justification = "Delegate is expected to be Serializable")
- private final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> delegate;
+ private final Map<PathArgument, DataContainerChild> delegate;
- private transient Collection<DataContainerChild<? extends PathArgument, ?>> values = null;
+ private transient Collection<DataContainerChild> values = null;
- private UnmodifiableChildrenMap(final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> delegate) {
+ private UnmodifiableChildrenMap(final Map<PathArgument, DataContainerChild> delegate) {
this.delegate = requireNonNull(delegate);
}
* @param map Backing map
* @return Unmodifiable view
*/
- static Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> create(
- final Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> map) {
+ static Map<PathArgument, DataContainerChild> create(final Map<PathArgument, DataContainerChild> map) {
if (map instanceof UnmodifiableChildrenMap) {
return map;
}
}
@Override
- public DataContainerChild<? extends PathArgument, ?> get(final Object key) {
+ public DataContainerChild get(final Object key) {
return delegate.get(key);
}
@Override
- public DataContainerChild<? extends PathArgument, ?> put(final PathArgument key,
- final DataContainerChild<? extends PathArgument, ?> value) {
+ public DataContainerChild put(final PathArgument key, final DataContainerChild value) {
throw new UnsupportedOperationException();
}
@Override
- public DataContainerChild<? extends PathArgument, ?> remove(final Object key) {
+ public DataContainerChild remove(final Object key) {
throw new UnsupportedOperationException();
}
@Override
@SuppressWarnings("checkstyle:parameterName")
- public void putAll(final Map<? extends PathArgument, ? extends DataContainerChild<? extends PathArgument, ?>> m) {
+ public void putAll(final Map<? extends PathArgument, ? extends DataContainerChild> m) {
throw new UnsupportedOperationException();
}
}
@Override
- public Collection<DataContainerChild<? extends PathArgument, ?>> values() {
+ public Collection<DataContainerChild> values() {
if (values == null) {
values = Collections.unmodifiableCollection(delegate.values());
}
}
@Override
- public Set<Entry<PathArgument, DataContainerChild<? extends PathArgument, ?>>> entrySet() {
+ public Set<Entry<PathArgument, DataContainerChild>> entrySet() {
/*
* Okay, this is not as efficient as it could be -- we could save ourselves the
* map instantiation. The cost of that would be re-implementation of a read-only
@Override
@SuppressWarnings("unchecked")
- public Map<PathArgument, DataContainerChild<? extends PathArgument, ?>> createMutableClone() {
+ public Map<PathArgument, DataContainerChild> createMutableClone() {
if (delegate instanceof HashMap) {
- return (Map<PathArgument, DataContainerChild<? extends PathArgument, ?>>)
- ((HashMap<?, ?>) delegate).clone();
+ return (Map<PathArgument, DataContainerChild>) ((HashMap<?, ?>) delegate).clone();
}
-
return new HashMap<>(delegate);
}
}
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
}
@SuppressWarnings("unchecked")
- private static NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>> getContainer(
+ private static DistinctNodeContainer<?, PathArgument, NormalizedNode> getContainer(
final @Nullable TreeNode meta) {
- return meta == null ? null : (NormalizedNodeContainer<?, PathArgument, NormalizedNode<?, ?>>)meta.getData();
+ return meta == null ? null : (DistinctNodeContainer<?, PathArgument, NormalizedNode>)meta.getData();
}
private ChildNode childNode(final ModifiedNode childMod) {
return ImmutableList.of();
}
- return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).getValue(),
+ return Collections2.transform(getContainer(newMeta != null ? newMeta : oldMeta).body(),
DataTreeCandidateNodes::unmodified);
case DELETE:
case WRITE:
return verifyNotNull(mod.getModificationType(), "Node %s does not have resolved modification type", mod);
}
- private static @NonNull Optional<NormalizedNode<?, ?>> optionalData(final TreeNode meta) {
+ private static @NonNull Optional<NormalizedNode> optionalData(final TreeNode meta) {
return meta == null ? Optional.empty() : Optional.of(meta.getData());
}
@Override
- public final Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public final Optional<NormalizedNode> getDataAfter() {
return optionalData(newMeta);
}
@Override
- public final Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public final Optional<NormalizedNode> getDataBefore() {
return optionalData(oldMeta);
}
if (!canHaveChildren(oldMeta, newMeta)) {
return Optional.empty();
}
- return getContainer(newMeta != null ? newMeta : oldMeta).getChild(identifier)
+ return getContainer(newMeta != null ? newMeta : oldMeta).findChildByArg(identifier)
.map(DataTreeCandidateNodes::unmodified);
case DELETE:
case WRITE:
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException;
}
@Override
- final void verifyValue(final NormalizedNode<?, ?> writtenValue) {
+ final void verifyValue(final NormalizedNode writtenValue) {
final Class<?> nodeClass = support.requiredClass;
checkArgument(nodeClass.isInstance(writtenValue), "Node %s is not of type %s", writtenValue, nodeClass);
checkArgument(writtenValue instanceof NormalizedNodeContainer);
}
@Override
- final void verifyValueChildren(final NormalizedNode<?, ?> writtenValue) {
+ final void verifyValueChildren(final NormalizedNode writtenValue) {
if (verifyChildrenStructure) {
- final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) writtenValue;
- for (final NormalizedNode<?, ?> child : container.getValue()) {
+ final DistinctNodeContainer<?, ?, ?> container = (DistinctNodeContainer<?, ?, ?>) writtenValue;
+ for (final NormalizedNode child : container.body()) {
final ModificationApplyOperation childOp = childByArg(child.getIdentifier());
if (childOp == null) {
throw new SchemaValidationFailedException(String.format(
*
* @param writtenValue Effective written value
*/
- void optionalVerifyValueChildren(final NormalizedNode<?, ?> writtenValue) {
+ void optionalVerifyValueChildren(final NormalizedNode writtenValue) {
// Defaults to no-op
}
*
* @param writtenValue Effective written value
*/
- void mandatoryVerifyValueChildren(final NormalizedNode<?, ?> writtenValue) {
+ void mandatoryVerifyValueChildren(final NormalizedNode writtenValue) {
// Defaults to no-op
}
@Override
- protected final void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
- final NormalizedNodeContainer<?, ?, ?> container = (NormalizedNodeContainer<?, ?, ?>) value;
- for (final NormalizedNode<?, ?> child : container.getValue()) {
+ protected final void recursivelyVerifyStructure(final NormalizedNode value) {
+ final NormalizedNodeContainer<?, ?> container = (NormalizedNodeContainer<?, ?>) value;
+ for (final NormalizedNode child : container.body()) {
final ModificationApplyOperation childOp = childByArg(child.getIdentifier());
if (childOp == null) {
throw new SchemaValidationFailedException(
}
@Override
- protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode<?, ?> newValue,
+ protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode newValue,
final Optional<? extends TreeNode> currentMeta, final Version version) {
final TreeNode newValueMeta = TreeNodeFactory.createTreeNode(newValue, version);
* we do that, ModifiedNode children will look like this node were a TOUCH and we will let applyTouch() do the
* heavy lifting of applying the children recursively (either through here or through applyWrite().
*/
- final NormalizedNode<?, ?> value = modification.getWrittenValue();
+ final NormalizedNode value = modification.getWrittenValue();
- Verify.verify(value instanceof NormalizedNodeContainer, "Attempted to merge non-container %s", value);
- for (final NormalizedNode<?, ?> c : ((NormalizedNodeContainer<?, ?, ?>) value).getValue()) {
+ Verify.verify(value instanceof DistinctNodeContainer, "Attempted to merge non-container %s", value);
+ for (final NormalizedNode c : ((DistinctNodeContainer<?, ?, ?>) value).body()) {
final PathArgument id = c.getIdentifier();
modification.modifyChild(id, resolveChildOperation(id), version);
}
}
private void mergeChildrenIntoModification(final ModifiedNode modification,
- final Collection<? extends NormalizedNode<?, ?>> children, final Version version) {
- for (final NormalizedNode<?, ?> c : children) {
+ final Collection<? extends NormalizedNode> children, final Version version) {
+ for (final NormalizedNode c : children) {
final ModificationApplyOperation childOp = resolveChildOperation(c.getIdentifier());
final ModifiedNode childNode = modification.modifyChild(c.getIdentifier(), childOp, version);
childOp.mergeIntoModifiedNode(childNode, c, version);
}
@Override
- final void mergeIntoModifiedNode(final ModifiedNode modification, final NormalizedNode<?, ?> value,
+ final void mergeIntoModifiedNode(final ModifiedNode modification, final NormalizedNode value,
final Version version) {
- final Collection<? extends NormalizedNode<?, ?>> children =
- ((NormalizedNodeContainer<?, ?, ?>)value).getValue();
-
+ final Collection<? extends NormalizedNode> children = ((DistinctNodeContainer<?, ?, ?>)value).body();
switch (modification.getOperation()) {
case NONE:
// Fresh node, just record a MERGE with a value
return null;
}
- static final TreeNode defaultTreeNode(final NormalizedNode<?, ?> emptyNode) {
+ static final TreeNode defaultTreeNode(final NormalizedNode emptyNode) {
return TreeNodeFactory.createTreeNode(emptyNode, FAKE_VERSION);
}
}
@Override
- final void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode<?, ?> value, final Version version) {
+ final void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode value, final Version version) {
delegate.mergeIntoModifiedNode(node, value, version);
}
@Override
- final void quickVerifyStructure(final NormalizedNode<?, ?> modification) {
+ final void quickVerifyStructure(final NormalizedNode modification) {
delegate.quickVerifyStructure(modification);
}
@Override
- final void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
+ final void recursivelyVerifyStructure(final NormalizedNode value) {
delegate.recursivelyVerifyStructure(value);
}
}
@Override
- void fullVerifyStructure(final NormalizedNode<?, ?> modification) {
+ void fullVerifyStructure(final NormalizedNode modification) {
delegate.fullVerifyStructure(modification);
enforceOnData(modification);
}
return delegate;
}
- abstract void enforceOnData(ModificationPath path, NormalizedNode<?, ?> value)
- throws DataValidationFailedException;
+ abstract void enforceOnData(ModificationPath path, NormalizedNode value) throws DataValidationFailedException;
- abstract void enforceOnData(@NonNull NormalizedNode<?, ?> data);
+ abstract void enforceOnData(@NonNull NormalizedNode data);
@Override
ToStringHelper addToStringAttributes(final ToStringHelper helper) {
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+import static com.google.common.base.Preconditions.checkState;
+
import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNodeFactory;
*/
@FunctionalInterface
interface ApplyWrite {
- TreeNode applyWrite(ModifiedNode modification, NormalizedNode<?, ?> newValue,
+ TreeNode applyWrite(ModifiedNode modification, NormalizedNode newValue,
Optional<? extends TreeNode> storeMeta, Version version);
}
}
static Optional<? extends TreeNode> apply(final Apply delegate, final ApplyWrite writeDelegate,
- final NormalizedNode<?, ?> emptyNode, final ModifiedNode modification,
+ final NormalizedNode emptyNode, final ModifiedNode modification,
final Optional<? extends TreeNode> storeMeta, final Version version) {
final Optional<? extends TreeNode> ret;
if (modification.getOperation() == LogicalOperation.DELETE) {
return ret.isPresent() ? disappearResult(modification, ret.get(), storeMeta) : ret;
}
- private static Optional<? extends TreeNode> applyTouch(final Apply delegate, final NormalizedNode<?, ?> emptyNode,
+ private static Optional<? extends TreeNode> applyTouch(final Apply delegate, final NormalizedNode emptyNode,
final ModifiedNode modification, final Optional<? extends TreeNode> storeMeta, final Version version) {
// Container is not present, let's take care of the 'magically appear' part of our job
final Optional<? extends TreeNode> ret = delegate.apply(modification, fakeMeta(emptyNode, version), version);
return Optional.empty();
}
- private static Optional<TreeNode> fakeMeta(final NormalizedNode<?, ?> emptyNode, final Version version) {
+ private static Optional<TreeNode> fakeMeta(final NormalizedNode emptyNode, final Version version) {
return Optional.of(TreeNodeFactory.createTreeNode(emptyNode, version));
}
private static boolean isEmpty(final TreeNode treeNode) {
- final NormalizedNode<?, ?> data = treeNode.getData();
- if (data instanceof NormalizedNodeContainer) {
- return ((NormalizedNodeContainer<?, ?, ?>) data).getValue().isEmpty();
- }
- if (data instanceof OrderedNodeContainer) {
- return ((OrderedNodeContainer<?>) data).getSize() == 0;
- }
- throw new IllegalStateException("Unhandled data " + data);
+ final NormalizedNode data = treeNode.getData();
+ checkState(data instanceof NormalizedNodeContainer, "Unhandled data %s", data);
+ return ((NormalizedNodeContainer<?, ?>) data).size() == 0;
}
}
}
@Override
- void enforceOnTreeNode(final NormalizedNode<?, ?> normalizedNode) {
+ void enforceOnTreeNode(final NormalizedNode normalizedNode) {
enforcer.enforceOnData(normalizedNode);
}
}
return Sets.union(children.keySet(), augmentations.keySet());
}
- void enforceOnTreeNode(final NormalizedNode<?, ?> normalizedNode) {
+ void enforceOnTreeNode(final NormalizedNode normalizedNode) {
// Default is no-op
}
}
}
@Override
- void optionalVerifyValueChildren(final NormalizedNode<?, ?> writtenValue) {
+ void optionalVerifyValueChildren(final NormalizedNode writtenValue) {
enforceCases(writtenValue);
}
enforceCases(tree.getData());
}
- private void enforceCases(final NormalizedNode<?, ?> normalizedNode) {
+ private void enforceCases(final NormalizedNode normalizedNode) {
Verify.verify(normalizedNode instanceof ChoiceNode);
- final Collection<DataContainerChild<?, ?>> children = ((ChoiceNode) normalizedNode).getValue();
+ final Collection<DataContainerChild> children = ((ChoiceNode) normalizedNode).body();
if (!children.isEmpty()) {
- final DataContainerChild<?, ?> firstChild = children.iterator().next();
+ final DataContainerChild firstChild = children.iterator().next();
final CaseEnforcer enforcer = Verify.verifyNotNull(caseEnforcers.get(firstChild.getIdentifier()),
"Case enforcer cannot be null. Most probably, child node %s of choice node %s does not belong "
+ "in current tree type.", firstChild.getIdentifier(), normalizedNode.getIdentifier());
// Make sure no leaves from other cases are present
for (final CaseEnforcer other : exclusions.get(enforcer)) {
for (final PathArgument id : other.getAllChildIdentifiers()) {
- final Optional<NormalizedNode<?, ?>> maybeChild = NormalizedNodes.getDirectChild(normalizedNode,
+ final Optional<NormalizedNode> maybeChild = NormalizedNodes.getDirectChild(normalizedNode,
id);
Preconditions.checkArgument(!maybeChild.isPresent(),
"Child %s (from case %s) implies non-presence of child %s (from case %s), which is %s",
}
@Override
- protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode<?, ?> newValue,
+ protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode newValue,
final Optional<? extends TreeNode> currentMeta, final Version version) {
final TreeNode ret = super.applyWrite(modification, newValue, currentMeta, version);
enforceCases(ret);
}
@Override
- void mandatoryVerifyValueChildren(final NormalizedNode<?, ?> writtenValue) {
+ void mandatoryVerifyValueChildren(final NormalizedNode writtenValue) {
enforcer.enforceOnData(writtenValue);
}
}
@Override
- protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode<?, ?> newValue,
+ protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode newValue,
final Optional<? extends TreeNode> currentMeta, final Version version) {
final TreeNode ret = super.applyWrite(modification, newValue, currentMeta, version);
enforcer.enforceOnTreeNode(ret);
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
public final class InMemoryDataTreeFactory implements DataTreeFactory {
private static final Logger LOG = LoggerFactory.getLogger(InMemoryDataTreeFactory.class);
// FIXME: YANGTOOLS-1074: we do not want this name
- private static final @NonNull NormalizedNode<?, ?> ROOT_CONTAINER =
+ private static final @NonNull NormalizedNode ROOT_CONTAINER =
ImmutableNodes.containerNode(SchemaContext.NAME);
@Inject
@Override
public DataTree create(final DataTreeConfiguration treeConfig, final EffectiveModelContext initialSchemaContext,
- final NormalizedNodeContainer<?, ?, ?> initialRoot) throws DataValidationFailedException {
+ final DistinctNodeContainer<?, ?, ?> initialRoot) throws DataValidationFailedException {
final DataTree ret = createDataTree(treeConfig, initialSchemaContext, false);
final DataTreeModification mod = ret.takeSnapshot().newModification();
private static @NonNull DataTree createDataTree(final DataTreeConfiguration treeConfig,
final EffectiveModelContext initialSchemaContext, final boolean maskMandatory) {
final DataSchemaNode rootSchemaNode = getRootSchemaNode(initialSchemaContext, treeConfig.getRootPath());
- final NormalizedNode<?, ?> rootDataNode = createRoot((DataNodeContainer)rootSchemaNode,
+ final NormalizedNode rootDataNode = createRoot((DataNodeContainer)rootSchemaNode,
treeConfig.getRootPath());
return new InMemoryDataTree(TreeNodeFactory.createTreeNode(rootDataNode, Version.initial()), treeConfig,
initialSchemaContext, rootSchemaNode, maskMandatory);
}
- private static @NonNull NormalizedNode<?, ?> createRoot(final DataNodeContainer schemaNode,
+ private static @NonNull NormalizedNode createRoot(final DataNodeContainer schemaNode,
final YangInstanceIdentifier path) {
if (path.isEmpty()) {
checkArgument(schemaNode instanceof ContainerLike,
}
}
- private static @NonNull NormalizedNode<?, ?> createRoot(final YangInstanceIdentifier path) {
+ private static @NonNull NormalizedNode createRoot(final YangInstanceIdentifier path) {
if (path.isEmpty()) {
return ROOT_CONTAINER;
}
}
@Override
- public void write(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+ public void write(final YangInstanceIdentifier path, final NormalizedNode data) {
checkSealed();
checkIdentifierReferencesData(path, data);
resolveModificationFor(path).write(data);
}
@Override
- public void merge(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data) {
+ public void merge(final YangInstanceIdentifier path, final NormalizedNode data) {
checkSealed();
checkIdentifierReferencesData(path, data);
resolveModificationFor(path).merge(data, version);
}
@Override
- public Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier path) {
+ public Optional<NormalizedNode> readNode(final YangInstanceIdentifier path) {
/*
* Walk the tree from the top, looking for the first node between root and
* the requested path which has been modified. If no such node exists,
final Optional<? extends TreeNode> result = resolveSnapshot(key, mod);
if (result.isPresent()) {
- final NormalizedNode<?, ?> data = result.get().getData();
+ final NormalizedNode data = result.get().getData();
return NormalizedNodes.findNode(key, data, path);
}
}
}
- static void checkIdentifierReferencesData(final PathArgument arg, final NormalizedNode<?, ?> data) {
+ static void checkIdentifierReferencesData(final PathArgument arg, final NormalizedNode data) {
checkArgument(arg.equals(data.getIdentifier()),
"Instance identifier references %s but data identifier is %s", arg, data.getIdentifier());
}
private void checkIdentifierReferencesData(final YangInstanceIdentifier path,
- final NormalizedNode<?, ?> data) {
+ final NormalizedNode data) {
final PathArgument arg;
if (!path.isEmpty()) {
}
@Override
- public Optional<NormalizedNode<?, ?>> readNode(final PathArgument child) {
+ public Optional<NormalizedNode> readNode(final PathArgument child) {
return stack.peek().read(child, getParent().getVersion());
}
}
@Override
- public void merge(final PathArgument child, final NormalizedNode<?, ?> data) {
+ public void merge(final PathArgument child, final NormalizedNode data) {
ensureNotClosed();
InMemoryDataTreeModification.checkIdentifierReferencesData(child, data);
resolveChildModification(child).merge(data, getParent().getVersion());
}
@Override
- public void write(final PathArgument child, final NormalizedNode<?, ?> data) {
+ public void write(final PathArgument child, final NormalizedNode data) {
ensureNotClosed();
InMemoryDataTreeModification.checkIdentifierReferencesData(child, data);
resolveChildModification(child).write(data);
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
import org.opendaylight.yangtools.yang.data.api.schema.tree.CursorAwareDataTreeSnapshot;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshotCursor;
}
@Override
- public Optional<NormalizedNode<?, ?>> readNode(final YangInstanceIdentifier path) {
+ public Optional<NormalizedNode> readNode(final YangInstanceIdentifier path) {
return NormalizedNodes.findNode(rootNode.getData(), path);
}
@Override
public Optional<DataTreeSnapshotCursor> openCursor(final YangInstanceIdentifier path) {
return NormalizedNodes.findNode(rootNode.getData(), path).map(root -> {
- checkArgument(root instanceof NormalizedNodeContainer, "Child %s is not a container", path);
- return openCursor(new InMemoryDataTreeSnapshotCursor(this, path, (NormalizedNodeContainer<?, ?, ?>)root));
+ checkArgument(root instanceof DistinctNodeContainer, "Child %s is not a container", path);
+ return openCursor(new InMemoryDataTreeSnapshotCursor(this, path, (DistinctNodeContainer<?, ?, ?>)root));
});
}
import java.util.Optional;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodes;
final class InMemoryDataTreeSnapshotCursor extends AbstractCursor<InMemoryDataTreeSnapshot> {
- private final Deque<NormalizedNodeContainer<?, ?, ?>> stack = new ArrayDeque<>();
+ private final Deque<DistinctNodeContainer<?, ?, ?>> stack = new ArrayDeque<>();
InMemoryDataTreeSnapshotCursor(final InMemoryDataTreeSnapshot parent, final YangInstanceIdentifier rootPath,
- final NormalizedNodeContainer<?, ?, ?> normalizedNode) {
+ final DistinctNodeContainer<?, ?, ?> normalizedNode) {
super(parent, rootPath);
stack.push(normalizedNode);
}
@Override
public void enter(final PathArgument child) {
- final Optional<NormalizedNode<?, ?>> maybeChildNode = NormalizedNodes.getDirectChild(stack.peek(), child);
+ final Optional<NormalizedNode> maybeChildNode = NormalizedNodes.getDirectChild(stack.peek(), child);
checkArgument(maybeChildNode.isPresent(), "Child %s not found", child);
- final NormalizedNode<?, ?> childNode = maybeChildNode.get();
+ final NormalizedNode childNode = maybeChildNode.get();
checkArgument(childNode instanceof NormalizedNodeContainer, "Child %s is not a container", child);
- stack.push((NormalizedNodeContainer<?, ?, ?>) childNode);
+ stack.push((DistinctNodeContainer<?, ?, ?>) childNode);
}
@Override
@SuppressWarnings("checkstyle:illegalCatch")
public void enter(final Iterable<PathArgument> path) {
- final Optional<NormalizedNode<?, ?>> maybeChildNode = NormalizedNodes.findNode(stack.peek(), path);
+ final Optional<NormalizedNode> maybeChildNode = NormalizedNodes.findNode(stack.peek(), path);
checkArgument(maybeChildNode.isPresent(), "Child %s not found", path);
- final NormalizedNode<?, ?> childNode = maybeChildNode.get();
+ final NormalizedNode childNode = maybeChildNode.get();
checkArgument(childNode instanceof NormalizedNodeContainer, "Child %s is not a container", path);
int depth = 0;
}
@Override
- public Optional<NormalizedNode<?, ?>> readNode(final PathArgument child) {
+ public Optional<NormalizedNode> readNode(final PathArgument child) {
return NormalizedNodes.findNode(stack.peek(), child);
}
}
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractNodeContainerModificationStrategy.Invisible;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
final class LeafSetModificationStrategy extends Invisible<LeafListSchemaNode> {
@SuppressWarnings({ "unchecked", "rawtypes" })
- private static final NormalizedNodeContainerSupport<NodeIdentifier, OrderedLeafSetNode<?>> ORDERED_SUPPORT =
- new NormalizedNodeContainerSupport(OrderedLeafSetNode.class, ChildTrackingPolicy.ORDERED,
- foo -> ImmutableOrderedLeafSetNodeBuilder.create((OrderedLeafSetNode<?>)foo),
- ImmutableOrderedLeafSetNodeBuilder::create);
+ private static final NormalizedNodeContainerSupport<NodeIdentifier, UserLeafSetNode<?>> ORDERED_SUPPORT =
+ new NormalizedNodeContainerSupport(UserLeafSetNode.class, ChildTrackingPolicy.ORDERED,
+ foo -> ImmutableUserLeafSetNodeBuilder.create((UserLeafSetNode<?>)foo),
+ ImmutableUserLeafSetNodeBuilder::create);
@SuppressWarnings({ "unchecked", "rawtypes" })
- private static final NormalizedNodeContainerSupport<NodeIdentifier, LeafSetNode<?>> UNORDERED_SUPPORT =
- new NormalizedNodeContainerSupport(LeafSetNode.class,
- foo -> ImmutableLeafSetNodeBuilder.create((LeafSetNode<?>)foo),
+ private static final NormalizedNodeContainerSupport<NodeIdentifier, SystemLeafSetNode<?>> UNORDERED_SUPPORT =
+ new NormalizedNodeContainerSupport(SystemLeafSetNode.class,
+ foo -> ImmutableLeafSetNodeBuilder.create((SystemLeafSetNode<?>)foo),
ImmutableLeafSetNodeBuilder::create);
LeafSetModificationStrategy(final LeafListSchemaNode schema, final DataTreeConfiguration treeConfig) {
}
@Override
- protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode<?, ?> newValue,
+ protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode newValue,
final Optional<? extends TreeNode> currentMeta, final Version version) {
final TreeNode newValueMeta = TreeNodeFactory.createTreeNode(newValue, version);
if (modification.getChildren().isEmpty()) {
}
@Override
- void verifyValue(final NormalizedNode<?, ?> value) {
+ void verifyValue(final NormalizedNode value) {
// NOOP
}
@Override
- void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
+ void recursivelyVerifyStructure(final NormalizedNode value) {
// NOOP
}
}
@Override
- void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode<?, ?> value, final Version version) {
+ void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode value, final Version version) {
// Unkeyed lists are always replaced
node.write(value);
}
return mandatoryNodes.isEmpty() ? Optional.empty() : Optional.of(new MandatoryLeafEnforcer(mandatoryNodes));
}
- void enforceOnData(final NormalizedNode<?, ?> data) {
+ void enforceOnData(final NormalizedNode data) {
for (final YangInstanceIdentifier id : mandatoryNodes) {
checkArgument(NormalizedNodes.findNode(data, id).isPresent(),
"Node %s is missing mandatory descendant %s", data.getIdentifier(), id);
}
@Override
- void mandatoryVerifyValueChildren(final NormalizedNode<?, ?> writtenValue) {
+ void mandatoryVerifyValueChildren(final NormalizedNode writtenValue) {
enforcer.enforceOnData(writtenValue);
}
}
@Override
- protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode<?, ?> newValue,
+ protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode newValue,
final Optional<? extends TreeNode> currentMeta, final Version version) {
final TreeNode ret = super.applyWrite(modification, newValue, currentMeta, version);
enforcer.enforceOnTreeNode(ret);
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractNodeContainerModificationStrategy.Invisible;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
final class MapModificationStrategy extends Invisible<ListSchemaNode> {
- private static final NormalizedNodeContainerSupport<NodeIdentifier, OrderedMapNode> ORDERED_SUPPORT =
- new NormalizedNodeContainerSupport<>(OrderedMapNode.class, ChildTrackingPolicy.ORDERED,
- ImmutableOrderedMapNodeBuilder::create, ImmutableOrderedMapNodeBuilder::create);
- private static final NormalizedNodeContainerSupport<NodeIdentifier, MapNode> UNORDERED_SUPPORT =
- new NormalizedNodeContainerSupport<>(MapNode.class, ImmutableMapNodeBuilder::create,
+ private static final NormalizedNodeContainerSupport<NodeIdentifier, UserMapNode> ORDERED_SUPPORT =
+ new NormalizedNodeContainerSupport<>(UserMapNode.class, ChildTrackingPolicy.ORDERED,
+ ImmutableUserMapNodeBuilder::create, ImmutableUserMapNodeBuilder::create);
+ private static final NormalizedNodeContainerSupport<NodeIdentifier, SystemMapNode> UNORDERED_SUPPORT =
+ new NormalizedNodeContainerSupport<>(SystemMapNode.class, ImmutableMapNodeBuilder::create,
ImmutableMapNodeBuilder::create);
private final @NonNull MapNode emptyNode;
*/
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
+import static com.google.common.base.Preconditions.checkArgument;
+
import com.google.common.base.MoreObjects.ToStringHelper;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
-import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.RequiredElementCountException;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ElementCountConstraint;
}
@Override
- void enforceOnData(final NormalizedNode<?, ?> data) {
+ void enforceOnData(final NormalizedNode data) {
enforceOnData(data, (actual, message) -> new MinMaxElementsValidationFailedException(message));
}
@Override
- void enforceOnData(final ModificationPath path, final NormalizedNode<?, ?> data)
- throws RequiredElementCountException {
+ void enforceOnData(final ModificationPath path, final NormalizedNode data) throws RequiredElementCountException {
enforceOnData(data, (actual, message) -> new RequiredElementCountException(path.toInstanceIdentifier(),
minElements, maxElements, actual, message));
}
T get(int actual, String message);
}
- private <X extends @NonNull Exception> void enforceOnData(final NormalizedNode<?, ?> value,
+ private <X extends @NonNull Exception> void enforceOnData(final NormalizedNode value,
final ExceptionSupplier<X> exceptionSupplier) throws X {
- final int children = numOfChildrenFromValue(value);
+ checkArgument(value instanceof NormalizedNodeContainer, "Value %s is not a NormalizedNodeContainer", value);
+ final int children = ((NormalizedNodeContainer) value).size();
if (minElements > children) {
throw exceptionSupplier.get(children, value.getIdentifier()
+ " does not have enough elements (" + children + "), needs at least " + minElements);
ToStringHelper addToStringAttributes(final ToStringHelper helper) {
return super.addToStringAttributes(helper.add("min", minElements).add("max", maxElements));
}
-
- private static int numOfChildrenFromValue(final NormalizedNode<?, ?> value) {
- if (value instanceof NormalizedNodeContainer) {
- return ((NormalizedNodeContainer<?, ?, ?>) value).size();
- } else if (value instanceof UnkeyedListNode) {
- return ((UnkeyedListNode) value).getSize();
- }
-
- throw new IllegalArgumentException(String.format(
- "Unexpected type '%s', expected types are NormalizedNodeContainer and UnkeyedListNode",
- value.getClass()));
- }
}
* @throws IllegalArgumentException If provided NodeModification does not adhere to the
* structure.
*/
- abstract void quickVerifyStructure(NormalizedNode<?, ?> modification);
+ abstract void quickVerifyStructure(NormalizedNode modification);
/**
* Performs a full structural verification of NodeModification, such as written values / types uses right
* @throws IllegalArgumentException If provided NodeModification does not adhere to the
* structure.
*/
- abstract void fullVerifyStructure(NormalizedNode<?, ?> modification);
+ abstract void fullVerifyStructure(NormalizedNode modification);
/**
* Return the tracking policy for this node's children.
* @param value Value which should be merge into the modification
* @param version Data version as carried in the containing {@link InMemoryDataTreeModification}
*/
- abstract void mergeIntoModifiedNode(ModifiedNode modification, NormalizedNode<?, ?> value, Version version);
+ abstract void mergeIntoModifiedNode(ModifiedNode modification, NormalizedNode value, Version version);
/**
* {@inheritDoc}
@Override
public abstract ModificationApplyOperation childByArg(PathArgument arg);
- abstract void recursivelyVerifyStructure(NormalizedNode<?, ?> value);
+ abstract void recursivelyVerifyStructure(NormalizedNode value);
abstract ToStringHelper addToStringAttributes(ToStringHelper helper);
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
import org.opendaylight.yangtools.yang.data.api.schema.tree.StoreTreeNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.TreeNode;
private final PathArgument identifier;
private LogicalOperation operation = LogicalOperation.NONE;
private Optional<TreeNode> snapshotCache;
- private NormalizedNode<?, ?> value;
+ private NormalizedNode value;
private ModificationType modType;
// Alternative history introduced in WRITE nodes. Instantiated when we touch any child underneath such a node.
*
* @return Currently-written value
*/
- @NonNull NormalizedNode<?, ?> getWrittenValue() {
+ @NonNull NormalizedNode getWrittenValue() {
return verifyNotNull(value);
}
* value contains this component, we need to materialize it as a MERGE modification.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
- final Optional<NormalizedNode<?, ?>> childData = ((NormalizedNodeContainer)value).getChild(child);
- if (childData.isPresent()) {
- childOper.mergeIntoModifiedNode(newlyCreated, childData.get(), modVersion);
+ final NormalizedNode childData = ((DistinctNodeContainer)value).childByArg(child);
+ if (childData != null) {
+ childOper.mergeIntoModifiedNode(newlyCreated, childData, modVersion);
}
}
*
* @param newValue new value
*/
- void write(final NormalizedNode<?, ?> newValue) {
+ void write(final NormalizedNode newValue) {
updateValue(LogicalOperation.WRITE, newValue);
children.clear();
}
* @param type New operation type
* @param newValue New node value
*/
- void updateValue(final LogicalOperation type, final NormalizedNode<?, ?> newValue) {
+ void updateValue(final LogicalOperation type, final NormalizedNode newValue) {
this.value = requireNonNull(newValue);
updateOperationType(type);
}
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataAfter() {
+ public Optional<NormalizedNode> getDataAfter() {
return Optional.empty();
}
@Override
- public Optional<NormalizedNode<?, ?>> getDataBefore() {
+ public Optional<NormalizedNode> getDataBefore() {
return Optional.empty();
}
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
-final class NormalizedNodeContainerSupport<K extends PathArgument, T extends NormalizedNode<K, ?>> {
+final class NormalizedNodeContainerSupport<K extends PathArgument, T extends NormalizedNode> {
final Function<T, NormalizedNodeContainerBuilder<K, ?, ?, T>> copyBuilder;
final Supplier<NormalizedNodeContainerBuilder<K, ?, ?, T>> emptyBuilder;
final ChildTrackingPolicy childPolicy;
this(requiredClass, ChildTrackingPolicy.UNORDERED, copyBuilder, emptyBuilder);
}
- NormalizedNodeContainerBuilder<?, ?, ?, T> createBuilder(final NormalizedNode<?, ?> original) {
+ NormalizedNodeContainerBuilder<?, ?, ?, T> createBuilder(final NormalizedNode original) {
return copyBuilder.apply(cast(original));
}
- NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) {
- return emptyBuilder.get().withNodeIdentifier(cast(original).getIdentifier()).build();
+ NormalizedNode createEmptyValue(final NormalizedNode original) {
+ return emptyBuilder.get().withNodeIdentifier((K) cast(original).getIdentifier()).build();
}
- private T cast(final NormalizedNode<?, ?> original) {
+ private T cast(final NormalizedNode original) {
checkArgument(requiredClass.isInstance(original), "Require %s, got %s", requiredClass, original);
return requiredClass.cast(original);
}
this.modification = requireNonNull(mod);
}
- void write(final NormalizedNode<?, ?> value) {
+ void write(final NormalizedNode value) {
modification.write(value);
/**
* Fast validation of structure, full validation on written data will be run during seal.
applyOperation.quickVerifyStructure(value);
}
- void merge(final NormalizedNode<?, ?> data, final Version version) {
+ void merge(final NormalizedNode data, final Version version) {
/*
* A merge operation will end up overwriting parts of the tree, retaining others. We want to
* make sure we do not validate the complete resulting structure, but rather just what was
* Read a particular child. If the child has been modified and does not have a stable
* view, one will we instantiated with specified version.
*/
- Optional<NormalizedNode<?, ?>> read(final PathArgument child, final Version version) {
+ Optional<NormalizedNode> read(final PathArgument child, final Version version) {
final ModifiedNode childNode = modification.childByArg(child);
if (childNode != null) {
Optional<? extends TreeNode> snapshot = childNode.getSnapshot();
import java.util.List;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
}
}
- static AugmentationModificationStrategy from(final DataNodeContainer resolvedTree,
+ static @Nullable AugmentationModificationStrategy from(final DataNodeContainer resolvedTree,
final AugmentationTarget augSchemas, final AugmentationIdentifier identifier,
final DataTreeConfiguration treeConfig) {
for (final AugmentationSchemaNode potential : augSchemas.getAvailableAugmentations()) {
}
@Override
- final void quickVerifyStructure(final NormalizedNode<?, ?> writtenValue) {
+ final void quickVerifyStructure(final NormalizedNode writtenValue) {
verifyValue(writtenValue);
}
@Override
- final void fullVerifyStructure(final NormalizedNode<?, ?> writtenValue) {
+ final void fullVerifyStructure(final NormalizedNode writtenValue) {
verifyValue(writtenValue);
verifyValueChildren(writtenValue);
}
*
* @param writtenValue Written value
*/
- abstract void verifyValue(NormalizedNode<?, ?> writtenValue);
+ abstract void verifyValue(NormalizedNode writtenValue);
/**
* Verify the children implied by a written value after the value itself has been verified by
*
* @param writtenValue Written value
*/
- void verifyValueChildren(final NormalizedNode<?, ?> writtenValue) {
+ void verifyValueChildren(final NormalizedNode writtenValue) {
// Defaults to no-op
}
*/
protected abstract TreeNode applyMerge(ModifiedNode modification, TreeNode currentMeta, Version version);
- protected abstract TreeNode applyWrite(ModifiedNode modification, NormalizedNode<?, ?> newValue,
+ protected abstract TreeNode applyWrite(ModifiedNode modification, NormalizedNode newValue,
Optional<? extends TreeNode> currentMeta, Version version);
/**
}
@Override
- void enforceOnData(final NormalizedNode<?, ?> data) {
+ void enforceOnData(final NormalizedNode data) {
enforceOnData(data, (message, values) -> new UniqueValidationFailedException(message));
}
@Override
- void enforceOnData(final ModificationPath path, final NormalizedNode<?, ?> data)
- throws UniqueConstraintException {
+ void enforceOnData(final ModificationPath path, final NormalizedNode data) throws UniqueConstraintException {
enforceOnData(data, (message, values) -> new UniqueConstraintException(path.toInstanceIdentifier(), values,
message));
}
- private <T extends @NonNull Exception> void enforceOnData(final NormalizedNode<?, ?> data,
+ private <T extends @NonNull Exception> void enforceOnData(final NormalizedNode data,
final ExceptionSupplier<T> exceptionSupplier) throws T {
final Stopwatch sw = Stopwatch.createStarted();
verify(data instanceof NormalizedNodeContainer, "Unexpected data %s", data);
- final var children = ((NormalizedNodeContainer<?, ?, ?>) data).getValue();
+ final var children = ((NormalizedNodeContainer<?, ?>) data).body();
final var collected = HashMultimap.<UniqueValidator<?>, Object>create(validators.size(), children.size());
- for (NormalizedNode<?, ?> child : children) {
+ for (NormalizedNode child : children) {
verify(child instanceof DataContainerNode, "Unexpected child %s", child);
final DataContainerNode<?> cont = (DataContainerNode<?>) child;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
final Iterator<NodeIdentifier> it = path.iterator();
while (true) {
final NodeIdentifier step = it.next();
- final Optional<DataContainerChild<?, ?>> optNext = current.getChild(step);
- if (optNext.isEmpty()) {
+ final DataContainerChild next = current.childByArg(step);
+ if (next == null) {
return null;
}
- final DataContainerChild<?, ?> next = optNext.orElseThrow();
if (!it.hasNext()) {
checkState(next instanceof LeafNode, "Unexpected node %s at %s", next, path);
- final Object value = next.getValue();
+ final Object value = next.body();
LOG.trace("Resolved {} to value {}", path, value);
return value;
}
import org.opendaylight.yangtools.yang.data.api.schema.tree.spi.Version;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-final class ValueNodeModificationStrategy<T extends DataSchemaNode, V extends NormalizedNode<?, ?>>
+final class ValueNodeModificationStrategy<T extends DataSchemaNode, V extends NormalizedNode>
extends SchemaAwareApplyOperation<T> {
private final @NonNull Class<V> nodeClass;
private final @NonNull T schema;
protected TreeNode applyMerge(final ModifiedNode modification, final TreeNode currentMeta,
final Version version) {
// Just overwrite whatever was there, but be sure to run validation
- final NormalizedNode<?, ?> newValue = modification.getWrittenValue();
+ final NormalizedNode newValue = modification.getWrittenValue();
verifyWrittenValue(newValue);
modification.resolveModificationType(ModificationType.WRITE);
return applyWrite(modification, newValue, null, version);
}
@Override
- protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode<?, ?> newValue,
+ protected TreeNode applyWrite(final ModifiedNode modification, final NormalizedNode newValue,
final Optional<? extends TreeNode> currentMeta, final Version version) {
return TreeNodeFactory.createTreeNode(newValue, version);
}
}
@Override
- void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode<?, ?> value, final Version version) {
+ void mergeIntoModifiedNode(final ModifiedNode node, final NormalizedNode value, final Version version) {
switch (node.getOperation()) {
// Delete performs a data dependency check on existence of the node. Performing a merge
// on DELETE means we
}
@Override
- void verifyValue(final NormalizedNode<?, ?> writtenValue) {
+ void verifyValue(final NormalizedNode writtenValue) {
verifyWrittenValue(writtenValue);
}
@Override
- void recursivelyVerifyStructure(final NormalizedNode<?, ?> value) {
+ void recursivelyVerifyStructure(final NormalizedNode value) {
verifyWrittenValue(value);
}
return helper.add("value", nodeClass.getSimpleName());
}
- private void verifyWrittenValue(final NormalizedNode<?, ?> value) {
+ private void verifyWrittenValue(final NormalizedNode value) {
checkArgument(nodeClass.isInstance(value), "Expected an instance of %s, have %s", nodeClass, value);
}
}
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.jdt.annotation.NonNull;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
}
- private static LeafSetNode<?> createLeafRefLeafListNode() {
-
- final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
- .leafSetBuilder();
- leafSetBuilder.withNodeIdentifier(new NodeIdentifier(leafrefLeafList));
-
- leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k1"));
- leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k2"));
- leafSetBuilder.addChild(createLeafSetEntry(leafrefLeafList, "k3"));
-
- return leafSetBuilder.build();
+ private static @NonNull LeafSetNode<Object> createLeafRefLeafListNode() {
+ return Builders.leafSetBuilder()
+ .withNodeIdentifier(new NodeIdentifier(leafrefLeafList))
+ .addChild(createLeafSetEntry(leafrefLeafList, "k1"))
+ .addChild(createLeafSetEntry(leafrefLeafList, "k2"))
+ .addChild(createLeafSetEntry(leafrefLeafList, "k3"))
+ .build();
}
private static ContainerNode createCon3Node() {
- final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = Builders
- .mapBuilder();
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> mapBuilder = Builders.mapBuilder();
mapBuilder.withNodeIdentifier(new NodeIdentifier(list3InChoice));
mapBuilder.addChild(createList3Entry("k1", "val1", "valA", "valX"));
.mapEntryBuilder();
mapEntryBuilder.withNodeIdentifier(NodeIdentifierWithPredicates.of(list3InChoice, k, keyVal));
- final ListNodeBuilder<Object, LeafSetEntryNode<Object>> leafSetBuilder = Builders
- .leafSetBuilder();
+ final ListNodeBuilder<Object, SystemLeafSetNode<Object>> leafSetBuilder = Builders.leafSetBuilder();
leafSetBuilder.withNodeIdentifier(new NodeIdentifier(l3));
leafSetBuilder.addChild(createLeafSetEntry(l3, l3Val1));
private static ChoiceNode createChoiceNode() {
- final CollectionNodeBuilder<MapEntryNode, MapNode> listInChoiceBuilder = Builders
- .mapBuilder();
- listInChoiceBuilder
- .withNodeIdentifier(new NodeIdentifier(listInChoice));
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listInChoiceBuilder = Builders.mapBuilder();
+ listInChoiceBuilder.withNodeIdentifier(new NodeIdentifier(listInChoice));
- listInChoiceBuilder.addChild(createListInChoiceEntry("key1",
- "leafref-in-choice value", "val1"));
- listInChoiceBuilder.addChild(createListInChoiceEntry("key2",
- "l1 value", "val2"));
- listInChoiceBuilder.addChild(createListInChoiceEntry("key3",
- "l1 value", "val3"));
+ listInChoiceBuilder.addChild(createListInChoiceEntry("key1", "leafref-in-choice value", "val1"));
+ listInChoiceBuilder.addChild(createListInChoiceEntry("key2", "l1 value", "val2"));
+ listInChoiceBuilder.addChild(createListInChoiceEntry("key3", "l1 value", "val3"));
- final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders
- .choiceBuilder();
+ final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choice2Builder = Builders.choiceBuilder();
choice2Builder.withNodeIdentifier(new NodeIdentifier(ch2));
choice2Builder.addChild(listInChoiceBuilder.build());
- final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders
- .choiceBuilder();
+ final DataContainerNodeBuilder<NodeIdentifier, ChoiceNode> choiceBuilder = Builders.choiceBuilder();
choiceBuilder.withNodeIdentifier(new NodeIdentifier(ch1));
choiceBuilder.addChild(choice2Builder.build());
private static ContainerNode createContributorContainer(
final ContainerSchemaNode contributorContSchemaNode) {
- final ListSchemaNode contributorListSchemaNode = (ListSchemaNode) contributorContSchemaNode
- .findDataChildByName(contributor).get();
+ final ListSchemaNode contributorListSchemaNode =
+ (ListSchemaNode) contributorContSchemaNode.findDataChildByName(contributor).get();
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
- .containerBuilder(contributorContSchemaNode);
+ final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr =
+ Builders.containerBuilder(contributorContSchemaNode);
- final MapNode contributorMap = createContributorList(contributorListSchemaNode);
+ final SystemMapNode contributorMap = createContributorList(contributorListSchemaNode);
contributorContainerBldr.addChild(contributorMap);
- final ContainerNode contributorContainer = contributorContainerBldr
- .build();
+ final ContainerNode contributorContainer = contributorContainerBldr.build();
return contributorContainer;
}
- private static MapNode createContributorList(
+ private static SystemMapNode createContributorList(
final ListSchemaNode contributorListSchemaNode) {
- final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
- .mapBuilder(contributorListSchemaNode);
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> contributorMapBldr =
+ Builders.mapBuilder(contributorListSchemaNode);
final MapEntryNode contributorMapEntry1 = createContributorListEntry(
"Leader of Yangtools", "Yangtools Leader name", "Yangtools",
contributorMapBldr.addChild(contributorMapEntry7);
contributorMapBldr.addChild(contributorMapEntry8);
- final MapNode contributorMap = contributorMapBldr.build();
-
- return contributorMap;
-
+ return contributorMapBldr.build();
}
private static MapEntryNode createContributorListEntry(
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> odlProjectContainerBldr = Builders
.containerBuilder(container);
- final MapNode projectMap = createProjectList(projListSchemaNode);
+ final SystemMapNode projectMap = createProjectList(projListSchemaNode);
odlProjectContainerBldr.addChild(projectMap);
final ContainerNode odlProjectContainer = odlProjectContainerBldr
return odlProjectContainer;
}
- private static MapNode createProjectList(
+ private static SystemMapNode createProjectList(
final ListSchemaNode projListSchemaNode) {
- final CollectionNodeBuilder<MapEntryNode, MapNode> projectMapBldr = Builders
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> projectMapBldr = Builders
.mapBuilder(projListSchemaNode);
final MapEntryNode projMapEntry1 = createProjectListEntry("Yangtools",
projectMapBldr.addChild(projMapEntry2);
projectMapBldr.addChild(projMapEntry3);
- final MapNode projectMap = projectMapBldr.build();
-
- return projectMap;
+ return projectMapBldr.build();
}
private static MapEntryNode createProjectListEntry(final String nameVal,
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> contributorContainerBldr = Builders
.containerBuilder(contributorContSchemaNode);
- final MapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
+ final SystemMapNode contributorMap = createBasicContributorList(contributorListSchemaNode);
contributorContainerBldr.addChild(contributorMap);
final ContainerNode contributorContainer = contributorContainerBldr
}
- private static MapNode createBasicContributorList(
+ private static SystemMapNode createBasicContributorList(
final ListSchemaNode contributorListSchemaNode) {
- final CollectionNodeBuilder<MapEntryNode, MapNode> contributorMapBldr = Builders
- .mapBuilder(contributorListSchemaNode);
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> contributorMapBldr =
+ Builders.mapBuilder(contributorListSchemaNode);
final MapEntryNode contributorMapEntry1 = createContributorListEntry(
"Leader of Yangtools", "Yangtools Leader name", "Yangtools",
contributorMapBldr.addChild(contributorMapEntry2);
contributorMapBldr.addChild(contributorMapEntry3);
- final MapNode contributorMap = contributorMapBldr.build();
-
- return contributorMap;
+ return contributorMapBldr.build();
}
}
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
final ListSchemaNode devTypeListSchemaNode = (ListSchemaNode) container.findDataChildByName(deviceType).get();
- final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devTypeContainerBldr = Builders
- .containerBuilder(container);
+ final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devTypeContainerBldr =
+ Builders.containerBuilder(container);
- final MapNode devTypeMap = createDevTypeList(devTypeListSchemaNode);
+ final SystemMapNode devTypeMap = createDevTypeList(devTypeListSchemaNode);
devTypeContainerBldr.addChild(devTypeMap);
return devTypeContainerBldr.build();
}
- private static MapNode createDevTypeList(final ListSchemaNode devTypeListSchemaNode) {
+ private static SystemMapNode createDevTypeList(final ListSchemaNode devTypeListSchemaNode) {
- final CollectionNodeBuilder<MapEntryNode, MapNode> devTypeMapBldr = Builders.mapBuilder(devTypeListSchemaNode);
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> devTypeMapBldr =
+ Builders.mapBuilder(devTypeListSchemaNode);
devTypeMapBldr.addChild(createDevTypeListEntry("dev_type_1", "typedesc1", devTypeListSchemaNode));
devTypeMapBldr.addChild(createDevTypeListEntry("dev_type_2", "typedesc2", devTypeListSchemaNode));
final LeafNode<String> typeLeaf = ImmutableNodes.leafNode(type, typeVal);
final LeafNode<String> descLeaf = ImmutableNodes.leafNode(desc, descVal);
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> devTypeMapEntryBldr = Builders
- .mapEntryBuilder(devTypeListSchemaNode);
+ final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> devTypeMapEntryBldr =
+ Builders.mapEntryBuilder(devTypeListSchemaNode);
devTypeMapEntryBldr.addChild(typeLeaf);
devTypeMapEntryBldr.addChild(descLeaf);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> chipsContainerBldr = Builders
.containerBuilder(container);
- final MapNode chipsMap = createChipsList(chipsListSchemaNode);
+ final SystemMapNode chipsMap = createChipsList(chipsListSchemaNode);
chipsContainerBldr.addChild(chipsMap);
return chipsContainerBldr.build();
}
- private static MapNode createChipsList(final ListSchemaNode chipsListSchemaNode) {
+ private static SystemMapNode createChipsList(final ListSchemaNode chipsListSchemaNode) {
- final CollectionNodeBuilder<MapEntryNode, MapNode> chipsMapBldr = Builders.mapBuilder(chipsListSchemaNode);
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> chipsMapBldr =
+ Builders.mapBuilder(chipsListSchemaNode);
chipsMapBldr.addChild(createChipsListEntry("dev_type_1", "desc1", chipsListSchemaNode));
chipsMapBldr.addChild(createChipsListEntry("dev_type_2", "desc2", chipsListSchemaNode));
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devicesContainerBldr = Builders
.containerBuilder(container);
- final MapNode devicesMap = createDeviceList(devicesListSchemaNode);
+ final SystemMapNode devicesMap = createDeviceList(devicesListSchemaNode);
devicesContainerBldr.addChild(devicesMap);
return devicesContainerBldr.build();
}
- private static MapNode createDeviceList(final ListSchemaNode deviceListSchemaNode) {
+ private static SystemMapNode createDeviceList(final ListSchemaNode deviceListSchemaNode) {
- final CollectionNodeBuilder<MapEntryNode, MapNode> devicesMapBldr = Builders.mapBuilder(deviceListSchemaNode);
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> devicesMapBldr =
+ Builders.mapBuilder(deviceListSchemaNode);
devicesMapBldr.addChild(createDeviceListEntry("dev_type_1", "typedesc1", 123456, "192.168.0.1",
deviceListSchemaNode));
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devTypeContainerBldr = Builders
.containerBuilder(container);
- final MapNode devTypeMap = createDevTypeList(devTypeListSchemaNode);
+ final SystemMapNode devTypeMap = createDevTypeList(devTypeListSchemaNode);
devTypeContainerBldr.addChild(devTypeMap);
return devTypeContainerBldr.build();
}
- private static MapNode createDevTypeList(final ListSchemaNode devTypeListSchemaNode) {
+ private static SystemMapNode createDevTypeList(final ListSchemaNode devTypeListSchemaNode) {
- final CollectionNodeBuilder<MapEntryNode, MapNode> devTypeMapBldr = Builders.mapBuilder(devTypeListSchemaNode);
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> devTypeMapBldr =
+ Builders.mapBuilder(devTypeListSchemaNode);
devTypeMapBldr.addChild(createDevTypeListEntry("dev_type1_1", "dev_type2_1", "dev_type3_1", "typedesc1",
devTypeListSchemaNode));
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> chipsContainerBldr = Builders
.containerBuilder(container);
- final MapNode chipsMap = createChipsList(chipsListSchemaNode);
+ final SystemMapNode chipsMap = createChipsList(chipsListSchemaNode);
chipsContainerBldr.addChild(chipsMap);
return chipsContainerBldr.build();
}
- private static MapNode createChipsList(final ListSchemaNode chipsListSchemaNode) {
+ private static SystemMapNode createChipsList(final ListSchemaNode chipsListSchemaNode) {
- final CollectionNodeBuilder<MapEntryNode, MapNode> chipsMapBldr = Builders.mapBuilder(chipsListSchemaNode);
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> chipsMapBldr =
+ Builders.mapBuilder(chipsListSchemaNode);
chipsMapBldr.addChild(createChipsListEntry("dev_type_1", "desc1", chipsListSchemaNode));
chipsMapBldr.addChild(createChipsListEntry("dev_type_2", "desc2", chipsListSchemaNode));
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devicesContainerBldr = Builders
.containerBuilder(container);
- final MapNode devicesMap = createDeviceList(devicesListSchemaNode);
+ final SystemMapNode devicesMap = createDeviceList(devicesListSchemaNode);
devicesContainerBldr.addChild(devicesMap);
return devicesContainerBldr.build();
}
- private static MapNode createDeviceList(final ListSchemaNode deviceListSchemaNode) {
+ private static SystemMapNode createDeviceList(final ListSchemaNode deviceListSchemaNode) {
- final CollectionNodeBuilder<MapEntryNode, MapNode> devicesMapBldr = Builders.mapBuilder(deviceListSchemaNode);
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> devicesMapBldr =
+ Builders.mapBuilder(deviceListSchemaNode);
devicesMapBldr.addChild(createDeviceListEntry("dev_type1_1", "dev_type2_1", "dev_type3_1", "typedesc1", 123456,
"192.168.0.1", deviceListSchemaNode));
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> devicesContainerBldr = Builders
.containerBuilder(container);
- final MapNode devicesMap = createDevice2List(devicesListSchemaNode);
+ final SystemMapNode devicesMap = createDevice2List(devicesListSchemaNode);
devicesContainerBldr.addChild(devicesMap);
return devicesContainerBldr.build();
}
- private static MapNode createDevice2List(final ListSchemaNode deviceListSchemaNode) {
+ private static SystemMapNode createDevice2List(final ListSchemaNode deviceListSchemaNode) {
- final CollectionNodeBuilder<MapEntryNode, MapNode> devicesMapBldr = Builders.mapBuilder(deviceListSchemaNode);
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> devicesMapBldr =
+ Builders.mapBuilder(deviceListSchemaNode);
devicesMapBldr.addChild(createDeviceListEntry("dev_type1_3", "dev_type2_3", "dev_type3_3", "typedesc3", 123459,
"192.168.0.1", deviceListSchemaNode));
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import java.io.File;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableAugmentationNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeSchemaAwareBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeSchemaAwareBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListEntryNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUnkeyedListNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeSchemaAwareBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserMapNodeSchemaAwareBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableYangModeledAnyXmlNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
final Map<QName, Object> keys = new HashMap<>();
keys.put(LIST_MAIN_CHILD_QNAME_1, 1);
final NodeIdentifierWithPredicates mapEntryPath = NodeIdentifierWithPredicates.of(LIST_MAIN, keys);
- final OrderedMapNode orderedMapNodeCreateNull = ImmutableOrderedMapNodeBuilder.create()
+ final UserMapNode orderedMapNodeCreateNull = ImmutableUserMapNodeBuilder.create()
.withNodeIdentifier(NODE_IDENTIFIER_LIST)
.withChild(LIST_MAIN_CHILD_1)
.addChild(LIST_MAIN_CHILD_2)
.withValue(mapEntryNodeColl)
.build();
- final OrderedMapNode orderedMapNodeCreateSize = ImmutableOrderedMapNodeBuilder.create(SIZE)
+ final UserMapNode orderedMapNodeCreateSize = ImmutableUserMapNodeBuilder.create(SIZE)
.withNodeIdentifier(NODE_IDENTIFIER_LIST)
.build();
- final OrderedMapNode orderedMapNodeCreateNode = ImmutableOrderedMapNodeBuilder.create(orderedMapNodeCreateNull)
+ final UserMapNode orderedMapNodeCreateNode = ImmutableUserMapNodeBuilder.create(orderedMapNodeCreateNull)
.removeChild(mapEntryPath)
.build();
- final OrderedMapNode orderedMapNodeSchemaAware = ImmutableOrderedMapNodeSchemaAwareBuilder.create(list)
+ final UserMapNode orderedMapNodeSchemaAware = ImmutableUserMapNodeSchemaAwareBuilder.create(list)
.withChild(LIST_MAIN_CHILD_1)
.build();
- final OrderedMapNode orderedMapNodeSchemaAwareMapNodeConst = ImmutableOrderedMapNodeSchemaAwareBuilder.create(
- list, getImmutableOrderedMapNode())
+ final UserMapNode orderedMapNodeSchemaAwareMapNodeConst = ImmutableUserMapNodeSchemaAwareBuilder.create(
+ list, getImmutableUserMapNode())
.build();
assertNotNull(Builders.orderedMapBuilder(list));
- assertEquals(SIZE, orderedMapNodeCreateNull.getSize());
- assertEquals(orderedMapNodeCreateNode.getSize(), orderedMapNodeCreateNull.getSize() - 1);
+ assertEquals(SIZE, orderedMapNodeCreateNull.size());
+ assertEquals(orderedMapNodeCreateNode.size(), orderedMapNodeCreateNull.size() - 1);
assertEquals(NODE_IDENTIFIER_LIST, orderedMapNodeCreateSize.getIdentifier());
assertEquals(LIST_MAIN_CHILD_1, orderedMapNodeCreateNull.getChild(0));
assertEquals(SIZE, orderedMapNodeCreateNull.size());
}
@Test
- public void immutableOrderedLeafSetNodeBuilderTest() {
- final NormalizedNode<?, ?> orderedLeafSet = ImmutableOrderedLeafSetNodeBuilder.<String>create()
+ public void immutableUserLeafSetNodeBuilderTest() {
+ final UserLeafSetNode<String> orderedLeafSet = ImmutableUserLeafSetNodeBuilder.<String>create()
.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
.withChild(LEAF_SET_ENTRY_NODE)
.withChildValue("baz")
.removeChild(BAR_PATH)
.build();
final LinkedList<LeafSetNode<?>> mapEntryNodeColl = new LinkedList<>();
- mapEntryNodeColl.add((LeafSetNode<?>)orderedLeafSet);
- final UnmodifiableCollection<?> leafSetCollection = (UnmodifiableCollection<?>)orderedLeafSet.getValue();
- final NormalizedNode<?, ?> orderedMapNodeSchemaAware = ImmutableOrderedLeafSetNodeSchemaAwareBuilder.create(
+ mapEntryNodeColl.add(orderedLeafSet);
+ final UnmodifiableCollection<?> leafSetCollection = (UnmodifiableCollection<?>)orderedLeafSet.body();
+ final NormalizedNode orderedMapNodeSchemaAware = ImmutableUserLeafSetNodeSchemaAwareBuilder.create(
leafList).withChildValue("baz").build();
final UnmodifiableCollection<?> SchemaAwareleafSetCollection =
- (UnmodifiableCollection<?>)orderedMapNodeSchemaAware.getValue();
- final NormalizedNode<?, ?> orderedLeafSetShemaAware = ImmutableOrderedLeafSetNodeSchemaAwareBuilder.create(
- leafList,(LeafSetNode<?>)orderedLeafSet).build();
+ (UnmodifiableCollection<?>) orderedMapNodeSchemaAware.body();
+ final NormalizedNode orderedLeafSetShemaAware = ImmutableUserLeafSetNodeSchemaAwareBuilder.create(
+ leafList, (UserLeafSetNode<?>) orderedLeafSet).build();
assertNotNull(Builders.orderedLeafSetBuilder(leafList));
assertNotNull(Builders.anyXmlBuilder());
assertNotNull(orderedLeafSetShemaAware);
- assertEquals(1, ((OrderedLeafSetNode<?>)orderedLeafSet).getSize());
- assertEquals("baz", ((OrderedLeafSetNode<?>)orderedLeafSet).getChild(0).getValue());
- assertNotNull(((OrderedLeafSetNode<?>)orderedLeafSet).getChild(BAR_PATH));
+ assertEquals(1, ((UserLeafSetNode<?>)orderedLeafSet).size());
+ assertEquals("baz", orderedLeafSet.getChild(0).body());
+ assertNull(orderedLeafSet.childByArg(BAR_PATH));
assertEquals(1, leafSetCollection.size());
assertEquals(1, SchemaAwareleafSetCollection.size());
}
public void immutableMapNodeBuilderTest() {
final LinkedList<MapEntryNode> mapEntryNodeColl = new LinkedList<>();
mapEntryNodeColl.add(LIST_MAIN_CHILD_3);
- final CollectionNodeBuilder<MapEntryNode, MapNode> collectionNodeBuilder = ImmutableMapNodeBuilder.create(1);
+ final CollectionNodeBuilder<MapEntryNode, SystemMapNode> collectionNodeBuilder =
+ ImmutableMapNodeBuilder.create(1);
assertNotNull(collectionNodeBuilder);
collectionNodeBuilder.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST);
collectionNodeBuilder.withValue(mapEntryNodeColl);
- final MapNode mapNode = collectionNodeBuilder.build();
- final MapNode mapNodeSchemaAware = ImmutableMapNodeSchemaAwareBuilder.create(list, getImmutableMapNode())
- .build();
+ final SystemMapNode mapNode = collectionNodeBuilder.build();
+ final SystemMapNode mapNodeSchemaAware = ImmutableMapNodeSchemaAwareBuilder.create(list,
+ getImmutableMapNode()).build();
assertNotNull(mapNodeSchemaAware);
assertNotNull(Builders.mapBuilder(mapNode));
}
// Ignored on purpose
}
- assertNotNull(unkeyedListNodeSize.getValue());
+ assertNotNull(unkeyedListNodeSize.body());
assertEquals(unkeyedListEntryNode, unkeyedListNodeCreated.getChild(0));
assertEquals(unkeyedListNode.getNodeType().getLocalName(), unkeyedListNodeSize.getNodeType()
.getLocalName());
@Test(expected = NullPointerException.class)
public void immutableLeafSetNodeBuilderExceptionTest() {
- final LeafSetNode<?> leafSetNode = ImmutableLeafSetNodeBuilder.create(1)
+ final SystemLeafSetNode<Object> leafSetNode = ImmutableLeafSetNodeBuilder.create(1)
.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST).build();
assertNotNull(leafSetNode);
ImmutableLeafSetNodeSchemaAwareBuilder.create(mock(LeafListSchemaNode.class), leafSetNode).build();
.removeChild(NODE_IDENTIFIER_LIST).build();
}
- @Test(expected = UnsupportedOperationException.class)
- public void immutableOrderedMapNotSchemaAwareExceptionTest1() {
- ImmutableOrderedMapNodeBuilder.create(getImmutableMapNode()).build();
- }
-
@Test(expected = UnsupportedOperationException.class)
public void immutableMapNodeSchemaAwareExceptionTest() {
ImmutableMapNodeSchemaAwareBuilder.create(list, getImmutableMapNode()).withNodeIdentifier(NODE_IDENTIFIER_LIST)
@Test(expected = UnsupportedOperationException.class)
public void immutableOrderedMapSchemaAwareExceptionTest1() {
- ImmutableOrderedMapNodeSchemaAwareBuilder.create(list).withNodeIdentifier(NODE_IDENTIFIER_LIST).build();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void immutableOrderedMapSchemaAwareExceptionTest2() {
- ImmutableOrderedMapNodeSchemaAwareBuilder.create(list, getImmutableMapNode()).build();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void immutableOrderedLeafSetNodeExceptionTest1() {
- ImmutableOrderedLeafSetNodeBuilder.create(getImmutableLeafSetNode()).build();
+ ImmutableUserMapNodeSchemaAwareBuilder.create(list).withNodeIdentifier(NODE_IDENTIFIER_LIST).build();
}
@Test(expected = UnsupportedOperationException.class)
- public void immutableOrderedLeafSetNodeSchemaAwareExceptionTest1() {
- ImmutableOrderedLeafSetNodeSchemaAwareBuilder.create(leafList).withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
+ public void immutableUserLeafSetNodeSchemaAwareExceptionTest1() {
+ ImmutableUserLeafSetNodeSchemaAwareBuilder.create(leafList).withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST)
.build();
}
- private static LeafSetNode<?> getImmutableLeafSetNode() {
- final ListNodeBuilder<String, LeafSetEntryNode<String>> leafSetBuilder = Builders.leafSetBuilder();
+ private static SystemLeafSetNode<String> getImmutableLeafSetNode() {
+ final ListNodeBuilder<String, SystemLeafSetNode<String>> leafSetBuilder = Builders.leafSetBuilder();
leafSetBuilder.withNodeIdentifier(NODE_IDENTIFIER_LEAF_LIST);
leafSetBuilder.addChild(LEAF_SET_ENTRY_NODE);
return leafSetBuilder.build();
}
- private static MapNode getImmutableMapNode() {
+ private static SystemMapNode getImmutableMapNode() {
return ImmutableMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST).withChild(LIST_MAIN_CHILD_1)
.build();
}
- private static MapNode getImmutableOrderedMapNode() {
- return ImmutableOrderedMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST)
+ private static UserMapNode getImmutableUserMapNode() {
+ return ImmutableUserMapNodeBuilder.create().withNodeIdentifier(NODE_IDENTIFIER_LIST)
.withChild(LIST_MAIN_CHILD_1).build();
}
}
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
.forStreamWriter(immutableNormalizedNodeStreamWriter);
normalizedNodeWriter.write(buildOuterContainerNode());
- final NormalizedNode<?, ?> output = result.getResult();
+ final NormalizedNode output = result.getResult();
assertNotNull(output);
- final NormalizedNode<?, ?> expectedNormalizedNode = buildOuterContainerNode();
+ final NormalizedNode expectedNormalizedNode = buildOuterContainerNode();
assertNotNull(expectedNormalizedNode);
assertEquals(expectedNormalizedNode, output);
}
- private NormalizedNode<?, ?> buildOuterContainerNode() {
+ private NormalizedNode buildOuterContainerNode() {
// my-container-1
- MapNode myKeyedListNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(myKeyedList))
+ SystemMapNode myKeyedListNode = Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(myKeyedList))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
NodeIdentifierWithPredicates.of(myKeyedList, myKeyLeaf, "listkeyvalue1"))
.withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList1))
.withChild(Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeafInList2))
.withValue("listleafvalue22").build()).build()).build();
- OrderedMapNode myOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
+ UserMapNode myOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
new NodeIdentifier(myOrderedList))
.withChild(Builders.mapEntryBuilder().withNodeIdentifier(
NodeIdentifierWithPredicates.of(myOrderedList, myKeyLeafInOrderedList, "olistkeyvalue1"))
LeafNode<?> myLeaf1Node = Builders.leafBuilder().withNodeIdentifier(new NodeIdentifier(myLeaf1))
.withValue("value1").build();
- LeafSetNode<?> myLeafListNode = Builders.leafSetBuilder().withNodeIdentifier(new NodeIdentifier(myLeafList))
+ LeafSetNode<?> myLeafListNode = Builders.leafSetBuilder()
+ .withNodeIdentifier(new NodeIdentifier(myLeafList))
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
new NodeWithValue<>(myLeafList, "lflvalue1")).withValue("lflvalue1").build())
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
- new NodeWithValue<>(myLeafList, "lflvalue2")).withValue("lflvalue2").build()).build();
+ new NodeWithValue<>(myLeafList, "lflvalue2")).withValue("lflvalue2").build())
+ .build();
- LeafSetNode<?> myOrderedLeafListNode = Builders.orderedLeafSetBuilder().withNodeIdentifier(
- new NodeIdentifier(myOrderedLeafList))
+ LeafSetNode<?> myOrderedLeafListNode = Builders.orderedLeafSetBuilder()
+ .withNodeIdentifier(new NodeIdentifier(myOrderedLeafList))
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
new NodeWithValue<>(myOrderedLeafList, "olflvalue1")).withValue("olflvalue1").build())
.withChild(Builders.leafSetEntryBuilder().withNodeIdentifier(
- new NodeWithValue<>(myOrderedLeafList, "olflvalue2")).withValue("olflvalue2").build()).build();
+ new NodeWithValue<>(myOrderedLeafList, "olflvalue2")).withValue("olflvalue2").build())
+ .build();
- ContainerNode myContainer1Node = Builders.containerBuilder().withNodeIdentifier(
- new NodeIdentifier(myContainer1))
+ ContainerNode myContainer1Node = Builders.containerBuilder()
+ .withNodeIdentifier(new NodeIdentifier(myContainer1))
.withChild(myKeyedListNode)
.withChild(myOrderedListNode)
.withChild(myUnkeyedListNode)
.withChild(
leaf).build()).build()).build();
- final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
+ final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx,
YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf), leaf);
assertEquals(expectedFilter, filter);
}
Builders.augmentationBuilder().withNodeIdentifier(augmentation)
.withChild(lastLeaf).build()).build()).build();
- final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
+ final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx,
YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf), lastLeaf);
assertEquals(expectedFilter, filter);
}
.build())
.build();
- final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
+ final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx,
YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase), leaf);
assertEquals(expectedFilter, filter);
}
.build()).build()).build()).build())
.build();
- final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
+ final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx,
YangInstanceIdentifier.create(rootContainer), expectedStructure);
assertEquals(expectedStructure, filter);
}
final ContainerNode expectedStructure = Builders.containerBuilder().withNodeIdentifier(rootContainer)
.withChild(lastChild).build();
- NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
+ NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx,
YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey), outerListEntry);
assertEquals(expectedStructure, filter);
filter = ImmutableNodes.fromInstanceId(ctx,
Builders.leafSetEntryBuilder().withNodeIdentifier(leafListWithValue)
.withValue(leafListWithValue.getValue()).build()).build()).build();
- final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
+ final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx,
YangInstanceIdentifier.create(rootContainer, leafList, leafListWithValue));
assertEquals(expectedFilter, filter);
}
final NodeIdentifierWithPredicates id = NodeIdentifierWithPredicates.of(TWO_KEY_LIST.getNodeType(), misordered);
assertArrayEquals(new Object[] { BAR, FOO }, id.keySet().toArray());
- final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
+ final NormalizedNode filter = ImmutableNodes.fromInstanceId(ctx,
YangInstanceIdentifier.create(TWO_KEY_LIST, id));
assertThat(filter, isA(MapNode.class));
- final Collection<MapEntryNode> value = ((MapNode) filter).getValue();
+ final Collection<MapEntryNode> value = ((MapNode) filter).body();
assertEquals(1, value.size());
final MapEntryNode entry = value.iterator().next();
LeafSetNode<Integer> leafList = Builders.<Integer>leafSetBuilder()
.withNodeIdentifier(getNodeIdentifier("leaf"))
.withChildValue(1)
- .withChild(
- Builders.<Integer>leafSetEntryBuilder()
- .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build())
+ .withChild(Builders.<Integer>leafSetEntryBuilder()
+ .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build())
.build();
builder.withChild(leafList);
builder.withChild(leafChild);
LeafListSchemaNode leafListSchemaNode = (LeafListSchemaNode) getSchemaNode(schema, "test", "leafList");
- LeafSetNode<Integer> leafList = Builders.<Integer>leafSetBuilder(leafListSchemaNode).withChildValue(1)
- .withChild(Builders.<Integer>leafSetEntryBuilder(leafListSchemaNode).withValue(3).build()).build();
+ LeafSetNode<Integer> leafList = Builders.<Integer>leafSetBuilder(leafListSchemaNode)
+ .withChildValue(1)
+ .withChild(Builders.<Integer>leafSetEntryBuilder(leafListSchemaNode).withValue(3).build())
+ .build();
builder.withChild(leafList);
ListSchemaNode listSchema = (ListSchemaNode) getSchemaNode(schema, "test", "list");
*
* @return A test document
*/
- private static NormalizedNode<?, ?> createDocumentOne() {
+ private static NormalizedNode createDocumentOne() {
return ImmutableContainerNodeBuilder
.create()
.withNodeIdentifier(new NodeIdentifier(ROOT_QNAME))
@Test
public void findNodeTest() {
- NormalizedNode<?, ?> tree = createDocumentOne();
+ NormalizedNode tree = createDocumentOne();
assertNotNull(tree);
- Optional<NormalizedNode<?, ?>> listFooResult = NormalizedNodes.findNode(tree, LIST_A_FOO_PATH);
+ Optional<NormalizedNode> listFooResult = NormalizedNodes.findNode(tree, LIST_A_FOO_PATH);
assertTrue(listFooResult.isPresent());
- Optional<NormalizedNode<?, ?>> listTwoResult = NormalizedNodes.findNode(tree, LIST_B_TWO_PATH);
+ Optional<NormalizedNode> listTwoResult = NormalizedNodes.findNode(tree, LIST_B_TWO_PATH);
assertTrue(listTwoResult.isPresent());
}
}
--- /dev/null
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.data.impl.schema;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
+
+public class OrderingEqualityTest {
+ private static final QName FOO = QName.create("foo", "foo");
+ private static final QName BAR = QName.create("foo", "bar");
+
+ @Test
+ public void testUserMap() {
+ final UserMapNode firstMap = Builders.orderedMapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(FOO))
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two"))
+ .withChild(ImmutableNodes.leafNode(BAR, "two"))
+ .build())
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one"))
+ .withChild(ImmutableNodes.leafNode(BAR, "one"))
+ .build())
+ .build();
+
+ final UserMapNode secondMap = Builders.orderedMapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(FOO))
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one"))
+ .withChild(ImmutableNodes.leafNode(BAR, "one"))
+ .build())
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two"))
+ .withChild(ImmutableNodes.leafNode(BAR, "two"))
+ .build())
+ .build();
+
+ assertEquals(firstMap.asMap(), secondMap.asMap());
+ assertFalse(firstMap.equals(secondMap));
+ assertFalse(secondMap.equals(firstMap));
+
+ final UserMapNode thirdMap = Builders.orderedMapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(FOO))
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one"))
+ .withChild(ImmutableNodes.leafNode(BAR, "one"))
+ .build())
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two"))
+ .withChild(ImmutableNodes.leafNode(BAR, "two"))
+ .build())
+ .build();
+
+ assertEquals(secondMap.asMap(), thirdMap.asMap());
+ assertFalse(firstMap.equals(thirdMap));
+ assertTrue(secondMap.equals(thirdMap));
+ assertArrayEquals(secondMap.body().toArray(), thirdMap.body().toArray());
+ assertEquals(secondMap.hashCode(), thirdMap.hashCode());
+
+ // Although this map looks as secondMap, it is not equal
+ final SystemMapNode systemMap = Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(FOO))
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one"))
+ .withChild(ImmutableNodes.leafNode(BAR, "one"))
+ .build())
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two"))
+ .withChild(ImmutableNodes.leafNode(BAR, "two"))
+ .build())
+ .build();
+
+ assertEquals(secondMap.asMap(), systemMap.asMap());
+ assertFalse(firstMap.equals(systemMap));
+ assertFalse(secondMap.equals(systemMap));
+ }
+
+ @Test
+ public void testSystemMap() {
+ final SystemMapNode firstMap = Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(FOO))
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one"))
+ .withChild(ImmutableNodes.leafNode(BAR, "one"))
+ .build())
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two"))
+ .withChild(ImmutableNodes.leafNode(BAR, "two"))
+ .build())
+ .build();
+ final SystemMapNode secondMap = Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(FOO))
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two"))
+ .withChild(ImmutableNodes.leafNode(BAR, "two"))
+ .build())
+ .withChild(Builders.mapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one"))
+ .withChild(ImmutableNodes.leafNode(BAR, "one"))
+ .build())
+ .build();
+
+ assertEquals(firstMap.asMap(), secondMap.asMap());
+ // Order does not matter
+ assertTrue(firstMap.equals(secondMap));
+ assertTrue(secondMap.equals(firstMap));
+ assertEquals(firstMap.hashCode(), secondMap.hashCode());
+ }
+}
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
public void testWriteMerge1() throws DataValidationFailedException {
final MapEntryNode fooEntryNode = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
final MapEntryNode barEntryNode = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
- final MapNode mapNode1 = ImmutableNodes.mapNodeBuilder()
+ final SystemMapNode mapNode1 = ImmutableNodes.mapNodeBuilder()
.withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME))
.withChild(fooEntryNode).build();
- final MapNode mapNode2 = ImmutableNodes.mapNodeBuilder()
+ final SystemMapNode mapNode2 = ImmutableNodes.mapNodeBuilder()
.withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME))
.withChild(barEntryNode).build();
final DataTreeSnapshot snapshotAfterTx = inMemoryDataTree.takeSnapshot();
final DataTreeModification modificationAfterTx = snapshotAfterTx.newModification();
- final Optional<NormalizedNode<?, ?>> readNode = modificationAfterTx.readNode(TestModel.OUTER_LIST_PATH);
+ final Optional<NormalizedNode> readNode = modificationAfterTx.readNode(TestModel.OUTER_LIST_PATH);
assertTrue(readNode.isPresent());
- assertEquals(2, ((NormalizedNodeContainer<?,?,?>)readNode.get()).size());
+ assertEquals(2, ((NormalizedNodeContainer<?, ?>)readNode.get()).size());
}
@Test
}
private static void verifyTestDeleteStructuralAndWriteChild(final DataTreeSnapshot snapshot) {
- final Optional<NormalizedNode<?, ?>> readNode = snapshot.readNode(TestModel.NAME_PATH);
+ final Optional<NormalizedNode> readNode = snapshot.readNode(TestModel.NAME_PATH);
assertTrue(readNode.isPresent());
}
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
private void firstModification() throws DataValidationFailedException {
/* MERGE */
- MapNode outerListNode = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(outerList))
- .withChild(createOuterListEntry("1", "o-1"))
- .withChild(createOuterListEntry("2", "o-2"))
- .withChild(createOuterListEntry("3", "o-3"))
- .build();
+ SystemMapNode outerListNode = ImmutableNodes.mapNodeBuilder()
+ .withNodeIdentifier(NodeIdentifier.create(outerList))
+ .withChild(createOuterListEntry("1", "o-1"))
+ .withChild(createOuterListEntry("2", "o-2"))
+ .withChild(createOuterListEntry("3", "o-3"))
+ .build();
ContainerNode rootContainerNode = createRootContainerBuilder()
- .withChild(createSubRootContainerBuilder().withChild(outerListNode).build())
- .build();
+ .withChild(createSubRootContainerBuilder().withChild(outerListNode).build())
+ .build();
YangInstanceIdentifier path = YangInstanceIdentifier.of(root);
DataTreeModification modification = inMemoryDataTree.takeSnapshot().newModification();
modification.merge(path, rootContainerNode);
/* WRITE INNER LIST WITH ENTRIES*/
- MapNode innerListNode = createInnerListBuilder()
+ SystemMapNode innerListNode = createInnerListBuilder()
.withChild(createInnerListEntry("a", "i-a"))
.withChild(createInnerListEntry("b", "i-b"))
.build();
private void secondModification(final int testScenarioNumber) throws DataValidationFailedException {
/* MERGE */
- MapNode outerListNode = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(outerList))
- .withChild(createOuterListEntry("3", "o-3"))
- .withChild(createOuterListEntry("4", "o-4"))
- .withChild(createOuterListEntry("5", "o-5"))
- .build();
+ SystemMapNode outerListNode = ImmutableNodes.mapNodeBuilder()
+ .withNodeIdentifier(NodeIdentifier.create(outerList))
+ .withChild(createOuterListEntry("3", "o-3"))
+ .withChild(createOuterListEntry("4", "o-4"))
+ .withChild(createOuterListEntry("5", "o-5"))
+ .build();
ContainerNode rootContainerNode = createRootContainerBuilder()
- .withChild(createSubRootContainerBuilder().withChild(outerListNode).build())
- .build();
+ .withChild(createSubRootContainerBuilder().withChild(outerListNode).build())
+ .build();
YangInstanceIdentifier path = YangInstanceIdentifier.of(root);
DataTreeModification modification = inMemoryDataTree.takeSnapshot().newModification();
modification.write(path, innerListEntryA);
} else if (testScenarioNumber == 3) {
/* WRITE INNER LIST WITH ENTRIES */
- MapNode innerListNode = createInnerListBuilder().withChild(createInnerListEntry("a", "i-a-3"))
+ SystemMapNode innerListNode = createInnerListBuilder().withChild(createInnerListEntry("a", "i-a-3"))
.withChild(createInnerListEntry("c", "i-c")).build();
path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2"))
.node(innerList);
return ImmutableContainerNodeBuilder.create().withNodeIdentifier(new NodeIdentifier(subRoot));
}
- private CollectionNodeBuilder<MapEntryNode, MapNode> createInnerListBuilder() {
+ private CollectionNodeBuilder<MapEntryNode, SystemMapNode> createInnerListBuilder() {
return ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(innerList));
}
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
import static junit.framework.TestCase.assertFalse;
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableMap;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.opendaylight.yangtools.util.UnmodifiableCollection;
import org.opendaylight.yangtools.yang.common.QName;
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;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
"bar");
private final MapEntryNode bazEntryNode = ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME, MIN_MAX_KEY_LEAF_QNAME,
"baz");
- private final MapNode mapNodeBazFuzWithNodes = ImmutableNodes.mapNodeBuilder()
+ private final SystemMapNode mapNodeBazFuzWithNodes = ImmutableNodes.mapNodeBuilder()
.withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
.withChild(bazEntryNode).withChild(bazEntryNodeWithValue).withChild(fooEntryNode)
.build();
- private final MapNode mapNodeFooWithNodes = ImmutableNodes.mapNodeBuilder()
+ private final SystemMapNode mapNodeFooWithNodes = ImmutableNodes.mapNodeBuilder()
.withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
.withChild(fooEntryNode).withChild(fooEntryNodeWithValue).withChild(barEntryNode).withChild(bazEntryNode)
.build();
- private final MapNode mapNodeBar = ImmutableNodes.mapNodeBuilder()
+ private final SystemMapNode mapNodeBar = ImmutableNodes.mapNodeBuilder()
.withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
.withChild(barEntryNode).build();
- private final MapNode mapNodeBaz = ImmutableNodes.mapNodeBuilder()
+ private final SystemMapNode mapNodeBaz = ImmutableNodes.mapNodeBuilder()
.withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME))
.withChild(bazEntryNode).build();
assertFalse(inMemoryDataTree.toString().contains("list"));
DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
- Optional<NormalizedNode<?, ?>> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
+ Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
assertTrue(!minMaxListRead.isPresent());
modificationTree1.write(MIN_MAX_LIST_PATH, mapNodeFooWithNodes);
DataTreeSnapshot test2 = inMemoryDataTree.takeSnapshot();
minMaxListRead = test2.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertEquals(3, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
+ assertEquals(3, ((NormalizedNodeContainer<?, ?>) minMaxListRead.get()).size());
DataTreeModification tempMod2 = test2.newModification();
tempMod2.write(MIN_MAX_LIST_PATH, mapNodeBaz);
DataTreeSnapshot test3 = inMemoryDataTree.takeSnapshot();
minMaxListRead = test3.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertEquals(1, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
- assertTrue(minMaxListRead.get().getValue().toString().contains("test2"));
+ assertEquals(1, ((NormalizedNodeContainer<?, ?>) minMaxListRead.get()).size());
+ assertThat(minMaxListRead.get().body().toString(), containsString("test2"));
DataTreeModification tempMod3 = test3.newModification();
tempMod3.merge(MIN_MAX_LIST_PATH, mapNodeBar);
final LeafSetNode<Object> fooLeafSetNode = ImmutableLeafSetNodeBuilder.create()
.withNodeIdentifier(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME))
- .withChildValue("foo").build();
+ .withChildValue("foo")
+ .build();
modificationTree.write(MIN_MAX_LEAF_LIST_PATH, fooLeafSetNode);
modificationTree.write(MIN_MAX_LEAF_LIST_PATH.node(barPath), barLeafSetEntry);
inMemoryDataTree.commit(prepare2);
final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
- final Optional<NormalizedNode<?, ?>> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
+ final Optional<NormalizedNode> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
assertTrue(masterContainer.isPresent());
- final Optional<NormalizedNodeContainer<?, ?, ?>> leafList = ((NormalizedNodeContainer) masterContainer.get())
- .getChild(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
+ final Optional<NormalizedNodeContainer<?, ?>> leafList = ((DistinctNodeContainer) masterContainer.get())
+ .findChildByArg(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
assertTrue(leafList.isPresent());
assertEquals(3, leafList.get().size());
}
inMemoryDataTree.commit(prepare);
// Empty list should have disappeared, along with the container, as we are not enforcing root
- final NormalizedNode<?, ?> data = inMemoryDataTree.takeSnapshot()
+ final NormalizedNode data = inMemoryDataTree.takeSnapshot()
.readNode(YangInstanceIdentifier.empty()).get();
assertTrue(data instanceof ContainerNode);
assertEquals(0, ((ContainerNode) data).size());
public void minMaxListNoMinMaxDeleteTest() throws DataValidationFailedException {
final MapEntryNode fooEntryNoMinMaxNode =
ImmutableNodes.mapEntry(MIN_MAX_LIST_QNAME_NO_MINMAX, MIN_MAX_KEY_LEAF_QNAME, "foo");
- final MapNode mapNode1 = ImmutableNodes.mapNodeBuilder()
+ final SystemMapNode mapNode1 = ImmutableNodes.mapNodeBuilder()
.withNodeIdentifier(new NodeIdentifier(MIN_MAX_LIST_QNAME_NO_MINMAX))
.withChild(fooEntryNoMinMaxNode).build();
inMemoryDataTree.commit(prepare);
final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
- final Optional<NormalizedNode<?, ?>> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_NO_MINMAX_PATH);
+ final Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_NO_MINMAX_PATH);
// Empty list should have disappeared
assertFalse(minMaxListRead.isPresent());
}
private static void testLoop(final DataTreeSnapshot snapshot, final String first, final String second) {
- Optional<NormalizedNode<?, ?>> minMaxListRead = snapshot.readNode(MIN_MAX_LIST_PATH);
+ Optional<NormalizedNode> minMaxListRead = snapshot.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertEquals(2, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
- UnmodifiableCollection<?> collectionChildren = (UnmodifiableCollection<?>) minMaxListRead.get().getValue();
+ assertEquals(2, ((NormalizedNodeContainer<?, ?>) minMaxListRead.get()).size());
- for (Object collectionChild : collectionChildren) {
+ for (Object collectionChild : (Collection<?>) minMaxListRead.get().body()) {
if (collectionChild.toString().contains(first)) {
assertTrue(collectionChild.toString().contains(first));
} else {
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
- final MapNode taskNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(TASK)).build();
+ final SystemMapNode taskNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(TASK)).build();
final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(YangInstanceIdentifier.of(TASK_CONTAINER).node(TASK), taskNode);
modificationTree.ready();
inMemoryDataTree.commit(prepare);
}
- private static DataContainerChild<?, ?> createTaskDataContainer(final boolean withMandatoryNode) {
+ private static DataContainerChild createTaskDataContainer(final boolean withMandatoryNode) {
DataContainerNodeBuilder<NodeIdentifier, ContainerNode> taskDataBuilder = Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(TASK_DATA))
.withChild(ImmutableNodes.leafNode(OTHER_DATA, "foo"));
return taskDataBuilder.build();
}
- private static DataContainerChild<?, ?> createTaskDataMultipleContainer(final boolean withPresenceContianer) {
+ private static DataContainerChild createTaskDataMultipleContainer(final boolean withPresenceContianer) {
DataContainerNodeBuilder<NodeIdentifier, ContainerNode> nonPresenceContainerBuilder = Builders
.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(NON_PRESENCE_CONTAINER))
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
public void mergeInvalidContainerTest() throws DataValidationFailedException {
final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
- final MapNode myList = createMap(true);
+ final SystemMapNode myList = createMap(true);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(ROOT)).withChild(myList);
private static void mergeMap(final DataTreeModification modificationTree,
final boolean mandatoryDataMissing) throws DataValidationFailedException {
- final MapNode myList = createMap(mandatoryDataMissing);
- modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), myList);
+ modificationTree.merge(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMap(mandatoryDataMissing));
}
- private static MapNode createMap(final boolean mandatoryDataMissing) throws DataValidationFailedException {
- return Builders
- .mapBuilder()
- .withNodeIdentifier(new NodeIdentifier(MY_LIST))
- .withChild(
- mandatoryDataMissing ? createMapEntry("1", "common-value") : createMapEntry("1",
- "mandatory-value", "common-value")).build();
+ private static SystemMapNode createMap(final boolean mandatoryDataMissing) throws DataValidationFailedException {
+ return Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MY_LIST))
+ .withChild(mandatoryDataMissing ? createMapEntry("1", "common-value")
+ : createMapEntry("1", "mandatory-value", "common-value"))
+ .build();
}
private static void mergeMapEntry(final DataTreeModification modificationTree, final Object listIdValue,
public void mergeValidContainerTest() throws DataValidationFailedException {
final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
- final MapNode myList = createMap(false);
+ final SystemMapNode myList = createMap(false);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(ROOT)).withChild(myList);
.withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue));
}
- private static CollectionNodeBuilder<MapEntryNode, MapNode> createMapBuilder() {
+ private static CollectionNodeBuilder<MapEntryNode, SystemMapNode> createMapBuilder() {
return Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST));
}
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
-import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
public void writeInvalidContainerTest() throws DataValidationFailedException {
final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
- final MapNode myList = createMap(true);
+ final SystemMapNode myList = createMap(true);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(ROOT)).withChild(myList);
}
private static void writeMap(final DataTreeModification modificationTree, final boolean mandatoryDataMissing) {
- final MapNode myList = createMap(mandatoryDataMissing);
- modificationTree.write(YangInstanceIdentifier.of(ROOT).node(MY_LIST), myList);
+ modificationTree.write(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMap(mandatoryDataMissing));
}
- private static MapNode createMap(final boolean mandatoryDataMissing) {
- return Builders
- .mapBuilder()
- .withNodeIdentifier(new NodeIdentifier(MY_LIST))
- .withChild(
- mandatoryDataMissing ? createMapEntry("1", "common-value") : createMapEntry("1",
- "mandatory-value", "common-value")).build();
+ private static SystemMapNode createMap(final boolean mandatoryDataMissing) {
+ return Builders.mapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MY_LIST))
+ .withChild(mandatoryDataMissing ? createMapEntry("1", "common-value")
+ : createMapEntry("1", "mandatory-value", "common-value"))
+ .build();
}
private static void writeMapEntry(final DataTreeModification modificationTree, final Object listIdValue,
public void writeValidContainerTest() throws DataValidationFailedException {
final DataTree inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
- final MapNode myList = createMap(false);
+ final SystemMapNode myList = createMap(false);
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> root = Builders.containerBuilder()
.withNodeIdentifier(new NodeIdentifier(ROOT)).withChild(myList);
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
inMemoryDataTree.commit(prepare2);
- final Optional<NormalizedNode<?, ?>> testNodeAfterCommits = modificationTree1.readNode(TestModel.TEST_PATH);
+ final Optional<NormalizedNode> testNodeAfterCommits = modificationTree1.readNode(TestModel.TEST_PATH);
assertPresentAndType(testNodeAfterCommits, ContainerNode.class);
}
final DataTreeCandidate prepare2 = inMemoryDataTree.prepare(modificationTree2);
inMemoryDataTree.commit(prepare2);
- final Optional<NormalizedNode<?, ?>> testNodeAfterCommits = modificationTree1.readNode(TestModel.TEST_PATH);
+ final Optional<NormalizedNode> testNodeAfterCommits = modificationTree1.readNode(TestModel.TEST_PATH);
assertPresentAndType(testNodeAfterCommits, ContainerNode.class);
}
package org.opendaylight.yangtools.yang.data.impl.schema.tree;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
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.NodeWithValue;
+import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
inMemoryDataTree.commit(prepare);
final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
- final Optional<NormalizedNode<?, ?>> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
+ final Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertEquals(2, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
+ assertEquals(2, ((NormalizedNodeContainer<?, ?>) minMaxListRead.get()).size());
}
@Test(expected = DataValidationFailedException.class)
inMemoryDataTree.commit(prepare1);
DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
- Optional<NormalizedNode<?, ?>> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
+ Optional<NormalizedNode> minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertEquals(2, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
+ assertEquals(2, ((NormalizedNodeContainer<?, ?>) minMaxListRead.get()).size());
modificationTree = inMemoryDataTree.takeSnapshot().newModification();
modificationTree.write(gooPath, gooEntryNode);
snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
minMaxListRead = snapshotAfterCommit.readNode(MIN_MAX_LIST_PATH);
assertTrue(minMaxListRead.isPresent());
- assertEquals(3, ((NormalizedNodeContainer<?, ?, ?>) minMaxListRead.get()).size());
+ assertEquals(3, ((NormalizedNodeContainer<?, ?>) minMaxListRead.get()).size());
modificationTree = inMemoryDataTree.takeSnapshot().newModification();
inMemoryDataTree.commit(prepare1);
final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
- final Optional<NormalizedNode<?, ?>> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
+ final Optional<NormalizedNode> masterContainer = snapshotAfterCommit.readNode(MASTER_CONTAINER_PATH);
assertTrue(masterContainer.isPresent());
- final Optional<NormalizedNodeContainer<?, ?, ?>> leafList = ((NormalizedNodeContainer) masterContainer.get())
- .getChild(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
- assertTrue(leafList.isPresent());
- assertEquals(2, leafList.get().size());
+ final NormalizedNodeContainer<?, ?> leafList =
+ (NormalizedNodeContainer<?, ?>) ((DistinctNodeContainer) masterContainer.get())
+ .childByArg(new NodeIdentifier(MIN_MAX_LEAF_LIST_QNAME));
+ assertNotNull(leafList);
+ assertEquals(2, leafList.size());
}
@Test
inMemoryDataTree.commit(prepare1);
final DataTreeSnapshot snapshotAfterCommit = inMemoryDataTree.takeSnapshot();
- final Optional<NormalizedNode<?, ?>> unkeyedListRead = snapshotAfterCommit.readNode(UNKEYED_LIST_PATH);
+ final Optional<NormalizedNode> unkeyedListRead = snapshotAfterCommit.readNode(UNKEYED_LIST_PATH);
assertTrue(unkeyedListRead.isPresent());
- assertTrue(((UnkeyedListNode) unkeyedListRead.get()).getSize() == 1);
+ assertTrue(((UnkeyedListNode) unkeyedListRead.get()).size() == 1);
}
@Test
*
* @return a test document
*/
- public NormalizedNode<?, ?> createDocumentOne() {
+ public NormalizedNode createDocumentOne() {
return ImmutableContainerNodeBuilder
.create()
.withNodeIdentifier(new NodeIdentifier(SCHEMA_CONTEXT.getQName()))
final DataTreeModification modificationTree = new InMemoryDataTreeModification(
new InMemoryDataTreeSnapshot(SCHEMA_CONTEXT,
TreeNodeFactory.createTreeNode(createDocumentOne(), Version.initial()), rootOper), rootOper);
- final Optional<NormalizedNode<?, ?>> originalBarNode = modificationTree.readNode(OUTER_LIST_2_PATH);
+ final Optional<NormalizedNode> originalBarNode = modificationTree.readNode(OUTER_LIST_2_PATH);
assertTrue(originalBarNode.isPresent());
assertSame(BAR_NODE, originalBarNode.get());
// reads node to /outer-list/1/inner_list/two/value
// and checks if node is already present
- final Optional<NormalizedNode<?, ?>> barTwoCModified = modificationTree.readNode(TWO_TWO_VALUE_PATH);
+ final Optional<NormalizedNode> barTwoCModified = modificationTree.readNode(TWO_TWO_VALUE_PATH);
assertTrue(barTwoCModified.isPresent());
assertEquals(ImmutableNodes.leafNode(TestModel.VALUE_QNAME, "test"), barTwoCModified.get());
// delete node to /outer-list/1/inner_list/two/value
modificationTree.delete(TWO_TWO_VALUE_PATH);
- final Optional<NormalizedNode<?, ?>> barTwoCAfterDelete = modificationTree.readNode(TWO_TWO_VALUE_PATH);
+ final Optional<NormalizedNode> barTwoCAfterDelete = modificationTree.readNode(TWO_TWO_VALUE_PATH);
assertFalse(barTwoCAfterDelete.isPresent());
}
.build());
// Reads list node from /test/outer-list.
- final Optional<NormalizedNode<?, ?>> potentialOuterList = modificationTree.readNode(TestModel.OUTER_LIST_PATH);
+ final Optional<NormalizedNode> potentialOuterList = modificationTree.readNode(TestModel.OUTER_LIST_PATH);
assertFalse(potentialOuterList.isPresent());
// Reads container node from /test and verifies that it contains test node.
- final Optional<NormalizedNode<?, ?>> potentialTest = modificationTree.readNode(TestModel.TEST_PATH);
+ final Optional<NormalizedNode> potentialTest = modificationTree.readNode(TestModel.TEST_PATH);
assertPresentAndType(potentialTest, ContainerNode.class);
}
public void writeSubtreeReadChildren() {
final DataTreeModification modificationTree = createEmptyModificationTree();
modificationTree.write(TestModel.TEST_PATH, createTestContainer());
- final Optional<NormalizedNode<?, ?>> potential = modificationTree.readNode(TWO_TWO_PATH);
+ final Optional<NormalizedNode> potential = modificationTree.readNode(TWO_TWO_PATH);
assertPresentAndType(potential, MapEntryNode.class);
}
modificationTree.write(TestModel.TEST_PATH, createTestContainer());
// We verify data are present
- final Optional<NormalizedNode<?, ?>> potentialBeforeDelete = modificationTree.readNode(TWO_TWO_PATH);
+ final Optional<NormalizedNode> potentialBeforeDelete = modificationTree.readNode(TWO_TWO_PATH);
assertPresentAndType(potentialBeforeDelete, MapEntryNode.class);
modificationTree.delete(TWO_TWO_PATH);
- final Optional<NormalizedNode<?, ?>> potentialAfterDelete = modificationTree.readNode(TWO_TWO_PATH);
+ final Optional<NormalizedNode> potentialAfterDelete = modificationTree.readNode(TWO_TWO_PATH);
assertFalse(potentialAfterDelete.isPresent());
}
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.UserMapNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
}
public void modification1() throws DataValidationFailedException {
- OrderedMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
+ UserMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
new NodeIdentifier(parentOrderedList))
.withChild(createParentOrderedListEntry("pkval1", "plfval1"))
.withChild(createParentOrderedListEntry("pkval2", "plfval2"))
DataTreeModification treeModification = inMemoryDataTree.takeSnapshot().newModification();
treeModification.write(path1, parentContainerNode);
- OrderedMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
+ UserMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
new NodeIdentifier(childOrderedList))
.withChild(createChildOrderedListEntry("chkval1", "chlfval1"))
.withChild(createChildOrderedListEntry("chkval2", "chlfval2")).build();
inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification));
DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
- Optional<NormalizedNode<?, ?>> readNode = snapshotAfterCommits.readNode(path1);
+ Optional<NormalizedNode> readNode = snapshotAfterCommits.readNode(path1);
assertTrue(readNode.isPresent());
readNode = snapshotAfterCommits.readNode(path2);
}
public void modification2() throws DataValidationFailedException {
- OrderedMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
+ UserMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
new NodeIdentifier(parentOrderedList))
.withChild(createParentOrderedListEntry("pkval3", "plfval3updated"))
.withChild(createParentOrderedListEntry("pkval4", "plfval4"))
YangInstanceIdentifier path1 = YangInstanceIdentifier.of(parentContainer);
treeModification.merge(path1, parentContainerNode);
- OrderedMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
+ UserMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
new NodeIdentifier(childOrderedList))
.withChild(createChildOrderedListEntry("chkval1", "chlfval1updated"))
.withChild(createChildOrderedListEntry("chkval2", "chlfval2updated"))
inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification));
DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
- Optional<NormalizedNode<?, ?>> readNode = snapshotAfterCommits.readNode(path1);
+ Optional<NormalizedNode> readNode = snapshotAfterCommits.readNode(path1);
assertTrue(readNode.isPresent());
readNode = snapshotAfterCommits.readNode(path2);
}
public void modification3() throws DataValidationFailedException {
- OrderedMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
+ UserMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
new NodeIdentifier(parentOrderedList))
.withChild(createParentOrderedListEntry("pkval1", "plfval1")).build();
DataTreeModification treeModification = inMemoryDataTree.takeSnapshot().newModification();
treeModification.write(path1, parentContainerNode);
- OrderedMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
+ UserMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
new NodeIdentifier(childOrderedList))
.withChild(createChildOrderedListEntry("chkval1", "chlfval1new")).build();
}
DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
- Optional<NormalizedNode<?, ?>> readNode = snapshotAfterCommits.readNode(path1);
+ Optional<NormalizedNode> readNode = snapshotAfterCommits.readNode(path1);
assertTrue(readNode.isPresent());
readNode = snapshotAfterCommits.readNode(path2);
DataTreeModification treeModification1 = inMemoryDataTree.takeSnapshot().newModification();
DataTreeModification treeModification2 = inMemoryDataTree.takeSnapshot().newModification();
- OrderedMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
+ UserMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
new NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval1", "plfval1"))
.build();
- OrderedMapNode parentOrderedListNode2 = Builders.orderedMapBuilder().withNodeIdentifier(
+ UserMapNode parentOrderedListNode2 = Builders.orderedMapBuilder().withNodeIdentifier(
new NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval2", "plfval2"))
.build();
}
DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
- Optional<NormalizedNode<?, ?>> readNode = snapshotAfterCommits.readNode(path);
+ Optional<NormalizedNode> readNode = snapshotAfterCommits.readNode(path);
assertTrue(readNode.isPresent());
}
inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification));
DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
- Optional<NormalizedNode<?, ?>> readNode = snapshotAfterCommits.readNode(path);
+ Optional<NormalizedNode> readNode = snapshotAfterCommits.readNode(path);
assertFalse(readNode.isPresent());
}
inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification));
DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
- Optional<NormalizedNode<?, ?>> readNode = snapshotAfterCommits.readNode(path);
+ Optional<NormalizedNode> readNode = snapshotAfterCommits.readNode(path);
assertFalse(readNode.isPresent());
}
DataTreeConfiguration.DEFAULT_OPERATIONAL));
}
- public NormalizedNode<?, ?> createDocumentOne() {
+ public NormalizedNode createDocumentOne() {
return ImmutableContainerNodeBuilder
.create()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(SCHEMA_CONTEXT.getQName()))
private void assertNodeExistence(final YangInstanceIdentifier outerListParentPath, final boolean shouldBePresent) {
final DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
- final Optional<NormalizedNode<?, ?>> readNode = snapshotAfterCommits.readNode(outerListParentPath);
+ final Optional<NormalizedNode> readNode = snapshotAfterCommits.readNode(outerListParentPath);
assertEquals(readNode.isPresent(), shouldBePresent);
}
writeChoice(anyXmlBuilder().withNodeIdentifier(BAZ).withValue(new DOMSource()).build());
}
- private void writeChoice(final DataContainerChild<?, ?> child) throws DataValidationFailedException {
+ private void writeChoice(final DataContainerChild child) throws DataValidationFailedException {
final DataTreeModification mod = dataTree.takeSnapshot().newModification();
mod.write(YangInstanceIdentifier.create(FOO), choiceBuilder().withNodeIdentifier(FOO).withChild(child).build());
mod.ready();
// Hidden on purpose
}
- public static NormalizedNode<?, ?> transformQNames(final NormalizedNode<?, ?> original,
+ public static NormalizedNode transformQNames(final NormalizedNode original,
final Function<QName, QName> mapping) {
NormalizedNodeResult result = new NormalizedNodeResult();
NormalizedNodeStreamWriter nodeWriter = ImmutableNormalizedNodeStreamWriter.from(result);
* @param mapping Map of QNames to transform. Not listed QNames are preserved.
* @return Normalized Node with replaced QNames.
*/
- public static NormalizedNode<?, ?> replaceQNames(final @NonNull NormalizedNode<?, ?> original,
+ public static NormalizedNode replaceQNames(final @NonNull NormalizedNode original,
final @NonNull Map<QName, QName> mapping) {
return transformQNames(original, new QNameReplacementFunction(mapping));
}
* @param mapping Map of QNameModules to transform. Not listed QNameModules are preserved.
* @return Normalized Node with replaced QNameModules.
*/
- public static NormalizedNode<?, ?> replaceQNameModules(final @NonNull NormalizedNode<?, ?> original,
+ public static NormalizedNode replaceQNameModules(final @NonNull NormalizedNode original,
final @NonNull Map<QNameModule, QNameModule> mapping) {
return transformQNames(original, new QNameModuleReplacementFunction(mapping));
}
@NonNullByDefault
public class ImmutableNormalizedAnydata extends AbstractEffectiveModelContextProvider implements NormalizedAnydata {
private final DataSchemaNode contextNode;
- private final NormalizedNode<?, ?> data;
+ private final NormalizedNode data;
public ImmutableNormalizedAnydata(final EffectiveModelContext schemaContext, final DataSchemaNode contextNode,
- final NormalizedNode<?, ?> data) {
+ final NormalizedNode data) {
super(schemaContext);
this.contextNode = requireNonNull(contextNode);
this.data = requireNonNull(data);
}
@Override
- public final NormalizedNode<?, ?> getData() {
+ public final NormalizedNode getData() {
return data;
}
* @author Robert Varga
*/
@Beta
-public interface NormalizedNodeDocument extends XPathDocument<NormalizedNode<?, ?>> {
+public interface NormalizedNodeDocument extends XPathDocument<NormalizedNode> {
}