*/
package org.opendaylight.controller.sal.connect.netconf.util;
+import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
-class NodeContainerProxy implements ContainerSchemaNode {
+/**
+ * Simple proxy for container like schema nodes, where user provides a collection of children schema nodes
+ */
+public final class NodeContainerProxy implements ContainerSchemaNode {
private final Map<QName, DataSchemaNode> childNodes;
private final QName qName;
+ private final Set<AugmentationSchema> availableAugmentations;
- public NodeContainerProxy(final QName qName, final Map<QName, DataSchemaNode> childNodes) {
+ public NodeContainerProxy(final QName qName, final Map<QName, DataSchemaNode> childNodes, final Set<AugmentationSchema> availableAugmentations) {
+ this.availableAugmentations = availableAugmentations;
this.childNodes = Preconditions.checkNotNull(childNodes, "childNodes");
- this.qName = Preconditions.checkNotNull(qName, "qName");
+ this.qName = qName;
+ }
+
+ public NodeContainerProxy(final QName qName, final Collection<DataSchemaNode> childNodes) {
+ this(qName, asMap(childNodes), Collections.<AugmentationSchema>emptySet());
}
- public NodeContainerProxy(final QName qName, final Set<DataSchemaNode> childNodes) {
- this(qName, asMap(childNodes));
+ public NodeContainerProxy(final QName qName, final Collection<DataSchemaNode> childNodes, final Set<AugmentationSchema> availableAugmentations) {
+ this(qName, asMap(childNodes), availableAugmentations);
}
- private static Map<QName, DataSchemaNode> asMap(final Set<DataSchemaNode> childNodes) {
- final Map<QName, DataSchemaNode> mapped = Maps.newHashMap();
- for (final DataSchemaNode childNode : childNodes) {
- mapped.put(childNode.getQName(), childNode);
- }
- return mapped;
+ private static Map<QName, DataSchemaNode> asMap(final Collection<DataSchemaNode> childNodes) {
+ return Maps.uniqueIndex(childNodes, new Function<DataSchemaNode, QName>() {
+ @Override
+ public QName apply(final DataSchemaNode input) {
+ return input.getQName();
+ }
+ });
}
@Override
@Override
public Set<AugmentationSchema> getAvailableAugmentations() {
- throw new UnsupportedOperationException();
+ return availableAugmentations;
}
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
return Collections.emptyList();
}
-}
+}
\ No newline at end of file