2 * Copyright (c) 2014 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.controller.md.sal.dom.store.impl.tree.spi;
10 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
11 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
12 import org.opendaylight.yangtools.yang.data.api.schema.OrderedNodeContainer;
14 import com.google.common.primitives.UnsignedLong;
16 public final class TreeNodeFactory {
17 private TreeNodeFactory() {
18 throw new UnsupportedOperationException("Utility class should not be instantiated");
22 * Create a new AbstractTreeNode from a data node, descending recursively as needed.
23 * This method should only ever be used for new data.
25 * @param data data node
26 * @param version data node version
27 * @return new AbstractTreeNode instance, covering the data tree provided
29 public static final TreeNode createTreeNode(final NormalizedNode<?, ?> data, final UnsignedLong version) {
30 if (data instanceof NormalizedNodeContainer<?, ?, ?>) {
31 @SuppressWarnings("unchecked")
32 NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>> container = (NormalizedNodeContainer<?, ?, NormalizedNode<?, ?>>) data;
33 return ContainerNode.create(version, container);
36 if (data instanceof OrderedNodeContainer<?>) {
37 @SuppressWarnings("unchecked")
38 OrderedNodeContainer<NormalizedNode<?, ?>> container = (OrderedNodeContainer<NormalizedNode<?, ?>>) data;
39 return ContainerNode.create(version, container);
42 return new ValueNode(data, version);