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;
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,
36 List<Node<?>> children, CompositeNode parent) {
37 return new ContainerNodeTO(name, parent, nodeMapFromList(children));
40 public static Map<QName, List<Node<?>>> nodeMapFromList(
41 List<Node<?>> children) {
42 Map<QName, List<Node<?>>> map = new HashMap<QName, List<Node<?>>>();
43 for (Node<?> node : children) {
45 QName name = node.getNodeType();
46 List<Node<?>> targetList = map.get(name);
47 if (targetList == null) {
48 targetList = new ArrayList<Node<?>>();
49 map.put(name, targetList);
56 private static class ContainerNodeTO extends AbstractContainerNode {
58 private final Map<QName, List<Node<?>>> nodeMap;
60 public ContainerNodeTO(QName name, Map<QName, List<Node<?>>> nodeMap) {
62 this.nodeMap = nodeMap;
65 public ContainerNodeTO(QName name, CompositeNode parent,
66 Map<QName, List<Node<?>>> nodeMap) {
68 this.nodeMap = nodeMap;
72 protected Map<QName, List<Node<?>>> getNodeMap() {
78 * @see 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
91 private final T value;
93 protected SimpleNodeTO(QName name, T val, CompositeNode parent) {
100 public T getValue() {
105 * @see org.opendaylight.yangtools.yang.data.api.SimpleNode#asMutable()
108 public MutableSimpleNode<T> asMutable() {
109 // TODO Auto-generated method stub