/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.yang.data.util; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.opendaylight.controller.yang.common.QName; import org.opendaylight.controller.yang.data.api.CompositeNode; import org.opendaylight.controller.yang.data.api.ModifyAction; import org.opendaylight.controller.yang.data.api.MutableCompositeNode; import org.opendaylight.controller.yang.data.api.MutableSimpleNode; import org.opendaylight.controller.yang.data.api.Node; import org.opendaylight.controller.yang.data.api.SimpleNode; public class Nodes { private Nodes() { } public static SimpleNode leafNode(QName name, T value) { return new SimpleNodeTO(name, value, null); } public static CompositeNode containerNode(QName name, List> children) { return containerNode(name, children, null); } public static CompositeNode containerNode(QName name, List> children, CompositeNode parent) { return new ContainerNodeTO(name, parent, nodeMapFromList(children)); } public static Map>> nodeMapFromList( List> children) { Map>> map = new HashMap>>(); for (Node node : children) { QName name = node.getNodeType(); List> targetList = map.get(name); if (targetList == null) { targetList = new ArrayList>(); map.put(name, targetList); } targetList.add(node); } return map; } private static class ContainerNodeTO extends AbstractContainerNode { private final Map>> nodeMap; public ContainerNodeTO(QName name, Map>> nodeMap) { super(name); this.nodeMap = nodeMap; } public ContainerNodeTO(QName name, CompositeNode parent, Map>> nodeMap) { super(name, parent); this.nodeMap = nodeMap; } @Override protected Map>> getNodeMap() { return nodeMap; } /* (non-Javadoc) * @see org.opendaylight.controller.yang.data.api.CompositeNode#asMutable() */ @Override public MutableCompositeNode asMutable() { // TODO Auto-generated method stub return null; } } private static class SimpleNodeTO extends AbstractNode implements SimpleNode { private final T value; protected SimpleNodeTO(QName name, T val, CompositeNode parent) { super(name, parent); value = val; } @Override public T getValue() { return value; } /* (non-Javadoc) * @see org.opendaylight.controller.yang.data.api.SimpleNode#asMutable() */ @Override public MutableSimpleNode asMutable() { // TODO Auto-generated method stub return null; } } }