2 * Copyright (c) 2013 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.util;
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.List;
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
17 import org.opendaylight.yangtools.yang.data.api.MutableCompositeNode;
18 import org.opendaylight.yangtools.yang.data.api.MutableSimpleNode;
19 import org.opendaylight.yangtools.yang.data.api.Node;
20 import org.opendaylight.yangtools.yang.data.api.SimpleNode;
22 public final class Nodes {
27 public static <T> SimpleNode<T> leafNode(QName name, T value) {
28 return new SimpleNodeTO<T>(name, value, null);
31 public static CompositeNode containerNode(QName name, List<Node<?>> children) {
32 return containerNode(name, children, null);
35 public static CompositeNode containerNode(QName name, List<Node<?>> children, CompositeNode parent) {
36 return new ContainerNodeTO(name, parent, nodeMapFromList(children));
39 public static Map<QName, List<Node<?>>> nodeMapFromList(List<Node<?>> children) {
40 Map<QName, List<Node<?>>> map = new HashMap<QName, List<Node<?>>>();
41 for (Node<?> node : children) {
43 QName name = node.getNodeType();
44 List<Node<?>> targetList = map.get(name);
45 if (targetList == null) {
46 targetList = new ArrayList<Node<?>>();
47 map.put(name, targetList);
54 private static class ContainerNodeTO extends AbstractContainerNode {
56 private final Map<QName, List<Node<?>>> nodeMap;
58 public ContainerNodeTO(QName name, Map<QName, List<Node<?>>> nodeMap) {
60 this.nodeMap = nodeMap;
63 public ContainerNodeTO(QName name, CompositeNode parent, Map<QName, List<Node<?>>> nodeMap) {
65 this.nodeMap = nodeMap;
69 protected Map<QName, List<Node<?>>> getNodeMap() {
78 * org.opendaylight.yangtools.yang.data.api.CompositeNode#asMutable()
81 public MutableCompositeNode asMutable() {
82 // TODO Auto-generated method stub
88 private static class SimpleNodeTO<T> extends AbstractNode<T> implements SimpleNode<T> {
90 private final T value;
92 protected SimpleNodeTO(QName name, T val, CompositeNode parent) {
106 * @see org.opendaylight.yangtools.yang.data.api.SimpleNode#asMutable()
109 public MutableSimpleNode<T> asMutable() {
110 // TODO Auto-generated method stub