Allow getChildNodes() to become a Collection
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / util / NodeContainerProxy.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sal.connect.netconf.util;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.Maps;
12 import com.google.common.collect.Sets;
13 import java.util.Collection;
14 import java.util.Collections;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.Set;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
20 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
21 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
24 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
25 import org.opendaylight.yangtools.yang.model.api.Status;
26 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
27 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.UsesNode;
29
30 class NodeContainerProxy implements ContainerSchemaNode {
31
32     private final Map<QName, DataSchemaNode> childNodes;
33     private final QName qName;
34
35     public NodeContainerProxy(final QName qName, final Map<QName, DataSchemaNode> childNodes) {
36         this.childNodes = Preconditions.checkNotNull(childNodes, "childNodes");
37         this.qName = Preconditions.checkNotNull(qName, "qName");
38     }
39
40     public NodeContainerProxy(final QName qName, final Collection<DataSchemaNode> childNodes) {
41         this(qName, asMap(childNodes));
42     }
43
44     private static Map<QName, DataSchemaNode> asMap(final Collection<DataSchemaNode> childNodes) {
45         final Map<QName, DataSchemaNode> mapped = Maps.newHashMap();
46         for (final DataSchemaNode childNode : childNodes) {
47             mapped.put(childNode.getQName(), childNode);
48         }
49         return mapped;
50     }
51
52     @Override
53     public Set<TypeDefinition<?>> getTypeDefinitions() {
54         return Collections.emptySet();
55     }
56
57     @Override
58     public Set<DataSchemaNode> getChildNodes() {
59         return Sets.newHashSet(childNodes.values());
60     }
61
62     @Override
63     public Set<GroupingDefinition> getGroupings() {
64         return Collections.emptySet();
65     }
66
67     @Override
68     public DataSchemaNode getDataChildByName(final QName qName) {
69         return childNodes.get(qName);
70     }
71
72     @Override
73     public DataSchemaNode getDataChildByName(final String s) {
74         throw new UnsupportedOperationException();
75     }
76
77     @Override
78     public Set<UsesNode> getUses() {
79         return Collections.emptySet();
80     }
81
82     @Override
83     public boolean isPresenceContainer() {
84         throw new UnsupportedOperationException();
85     }
86
87     @Override
88     public Set<AugmentationSchema> getAvailableAugmentations() {
89         throw new UnsupportedOperationException();
90     }
91
92     @Override
93     public boolean isAugmenting() {
94         throw new UnsupportedOperationException();
95     }
96
97     @Override
98     public boolean isAddedByUses() {
99         throw new UnsupportedOperationException();
100     }
101
102     @Override
103     public boolean isConfiguration() {
104         throw new UnsupportedOperationException();
105     }
106
107     @Override
108     public ConstraintDefinition getConstraints() {
109         throw new UnsupportedOperationException();
110     }
111
112     @Override
113     public QName getQName() {
114         return qName;
115     }
116
117     @Override
118     public SchemaPath getPath() {
119         throw new UnsupportedOperationException();
120     }
121
122     @Override
123     public String getDescription() {
124         throw new UnsupportedOperationException();
125     }
126
127     @Override
128     public String getReference() {
129         throw new UnsupportedOperationException();
130     }
131
132     @Override
133     public Status getStatus() {
134         throw new UnsupportedOperationException();
135     }
136
137     @Override
138     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
139         return Collections.emptyList();
140     }
141 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.