2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.tree.spi;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.Collections2;
13 import com.google.common.collect.ImmutableList;
14 import java.util.Collection;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
17 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
18 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
19 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
20 import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
23 * Utility implementation of {@link DataTreeCandidateNode} which acts as if
24 * the {@link NormalizedNode} passed to it at creation time were freshly written.
26 final class NormalizedNodeDataTreeCandidateNode implements DataTreeCandidateNode {
27 private final NormalizedNode data;
30 * Create a new instance backed by supplied data.
32 * @param data Backing {@link NormalizedNode} data.
34 NormalizedNodeDataTreeCandidateNode(final @NonNull NormalizedNode data) {
35 this.data = requireNonNull(data);
39 public PathArgument name() {
44 public ModificationType modificationType() {
45 return ModificationType.WRITE;
49 public NormalizedNode dataBefore() {
54 public NormalizedNode dataAfter() {
59 public Collection<DataTreeCandidateNode> childNodes() {
60 if (data instanceof DistinctNodeContainer<?, ?> container) {
61 return Collections2.transform(container.body(),
62 input -> input == null ? null : new NormalizedNodeDataTreeCandidateNode(input));
64 return ImmutableList.of();
68 @SuppressWarnings({ "rawtypes", "unchecked" })
69 public DataTreeCandidateNode modifiedChild(final PathArgument childName) {
70 if (data instanceof DistinctNodeContainer container) {
71 final var child = container.childByArg(childName);
72 return child != null ? new NormalizedNodeDataTreeCandidateNode(child) : null;