2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.data.util;
\r
10 import java.util.ArrayList;
\r
11 import java.util.HashMap;
\r
12 import java.util.List;
\r
13 import java.util.Map;
\r
15 import org.opendaylight.controller.yang.common.QName;
\r
16 import org.opendaylight.controller.yang.data.api.CompositeNode;
\r
17 import org.opendaylight.controller.yang.data.api.Node;
\r
18 import org.opendaylight.controller.yang.data.api.SimpleNode;
\r
20 public class Nodes {
\r
25 public static <T> SimpleNode<T> leafNode(QName name, T value) {
\r
26 return new SimpleNodeTO<T>(name, value, null);
\r
29 public static CompositeNode containerNode(QName name, List<Node<?>> children) {
\r
30 return containerNode(name, children, null);
\r
33 public static CompositeNode containerNode(QName name,
\r
34 List<Node<?>> children, CompositeNode parent) {
\r
35 return new ContainerNodeTO(name, parent, nodeMapFromList(children));
\r
38 public static Map<QName, List<Node<?>>> nodeMapFromList(
\r
39 List<Node<?>> children) {
\r
40 Map<QName, List<Node<?>>> map = new HashMap<QName, List<Node<?>>>();
\r
41 for (Node<?> node : children) {
\r
43 QName name = node.getNodeType();
\r
44 List<Node<?>> targetList = map.get(name);
\r
45 if (targetList == null) {
\r
46 targetList = new ArrayList<Node<?>>();
\r
47 map.put(name, targetList);
\r
49 targetList.add(node);
\r
54 private static class ContainerNodeTO extends AbstractContainerNode {
\r
56 private final Map<QName, List<Node<?>>> nodeMap;
\r
58 public ContainerNodeTO(QName name, Map<QName, List<Node<?>>> nodeMap) {
\r
60 this.nodeMap = nodeMap;
\r
63 public ContainerNodeTO(QName name, CompositeNode parent,
\r
64 Map<QName, List<Node<?>>> nodeMap) {
\r
65 super(name, parent);
\r
66 this.nodeMap = nodeMap;
\r
70 protected Map<QName, List<Node<?>>> getNodeMap() {
\r
76 private static class SimpleNodeTO<T> extends AbstractNode<T> implements
\r
79 private final T value;
\r
81 protected SimpleNodeTO(QName name, T val, CompositeNode parent) {
\r
82 super(name, parent);
\r
88 public T getValue() {
\r