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.controller.yang.data.util;
10 import java.util.ArrayList;
11 import java.util.HashMap;
12 import java.util.List;
15 import org.opendaylight.controller.yang.common.QName;
16 import org.opendaylight.controller.yang.data.api.CompositeNode;
17 import org.opendaylight.controller.yang.data.api.Node;
18 import org.opendaylight.controller.yang.data.api.SimpleNode;
25 public static <T> SimpleNode<T> leafNode(QName name, T value) {
26 return new SimpleNodeTO<T>(name, value, null);
29 public static CompositeNode containerNode(QName name, List<Node<?>> children) {
30 return containerNode(name, children, null);
33 public static CompositeNode containerNode(QName name,
34 List<Node<?>> children, CompositeNode parent) {
35 return new ContainerNodeTO(name, parent, nodeMapFromList(children));
38 public static Map<QName, List<Node<?>>> nodeMapFromList(
39 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,
64 Map<QName, List<Node<?>>> nodeMap) {
66 this.nodeMap = nodeMap;
70 protected Map<QName, List<Node<?>>> getNodeMap() {
76 private static class SimpleNodeTO<T> extends AbstractNode<T> implements
79 private final T value;
81 protected SimpleNodeTO(QName name, T val, CompositeNode parent) {