Degrade DataNodeContainer.getChildNodes() from Set to Collection 52/9352/6
authorRobert Varga <rovarga@cisco.com>
Sat, 26 Jul 2014 02:17:52 +0000 (04:17 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Mon, 28 Jul 2014 13:26:35 +0000 (13:26 +0000)
Datastore-geared workload shows that around 1% of CPU is being used by
AbstractDocumentedDataNodeContainer.getChildNodes(). Of that, around 72%
is spent in ImmutableSet.copyOf(). We could perform that copy in the
constructor, but we can actually do better.

As it turns out, there is already a childNodes map, which is immutable
and indexed via QName present. That indexing guarantees that the values
compare as distinct, so we can reuse childNodes.values(), except for the
contract.

None of the callers care if the return is a Collection, so downgrade the
return, such that we can elide copying the stuff completely. Also fixup
all the callers. Requires https://git.opendaylight.org/gerrit/#/c/9340/
to fix controller-based users.

Change-Id: I310b351d80955a37f6672064dd238bb9cb1e16b1
Signed-off-by: Robert Varga <rovarga@cisco.com>
15 files changed:
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/LazyGeneratedCodecRegistry.java
code-generator/binding-type-provider/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/GroupingDefinitionDependencySort.java
code-generator/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/yangtools/yang/unified/doc/generator/GeneratorImpl.xtend
integration-test/yang-runtime-tests/src/test/java/org/opendaylight/yangtools/it/yang/runtime/tests/MultipleRevisionsSupportTest.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtils.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/SchemaUtils.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizedDataBuilderTest.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/DataNodeContainer.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/AugmentTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/GroupingTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/OrderingTest.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/UsesAugmentTest.java

index 15fa0902d0029ee7084d6f64ea63d1e76a1a7257..d448db765947b544e5d2ef3d3da289ab52da4af0 100644 (file)
@@ -30,6 +30,7 @@ import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findP
 import com.google.common.base.Splitter;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Sets;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -38,6 +39,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil;
 import org.opendaylight.yangtools.binding.generator.util.BindingTypes;
 import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;
@@ -525,8 +527,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
                         notification.getChildNodes());
 
                 listenerInterface.addMethod("on" + notificationInterface.getName())
-                        .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification")
-                        .setComment(notification.getDescription()).setReturnType(Types.VOID);
+                .setAccessModifier(AccessModifier.PUBLIC).addParameter(notificationInterface, "notification")
+                .setComment(notification.getDescription()).setReturnType(Types.VOID);
             }
         }
 
@@ -594,7 +596,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
                     .getQNameModule());
             final String returnTypeName = BindingMapping.getClassName(baseIdentity.getQName());
             final GeneratedTransferObject gto = new GeneratedTOBuilderImpl(returnTypePkgName, returnTypeName)
-                    .toInstance();
+            .toInstance();
             newType.setExtendsType(gto);
         }
         newType.setAbstract(true);
@@ -641,7 +643,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
     private void groupingsToGenTypes(final Module module, final Collection<GroupingDefinition> groupings) {
         final String basePackageName = BindingMapping.getRootPackageName(module.getQNameModule());
         final List<GroupingDefinition> groupingsSortedByDependencies = new GroupingDefinitionDependencySort()
-                .sort(groupings);
+        .sort(groupings);
         for (GroupingDefinition grouping : groupingsSortedByDependencies) {
             groupingToGenType(basePackageName, grouping, module);
         }
@@ -996,8 +998,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
      *         added to it.
      */
     private GeneratedTypeBuilder resolveDataSchemaNodes(final Module module, final String basePackageName,
-            final GeneratedTypeBuilder parent, final GeneratedTypeBuilder childOf, final Set<DataSchemaNode> schemaNodes) {
-        if ((schemaNodes != null) && (parent != null)) {
+            final GeneratedTypeBuilder parent, final GeneratedTypeBuilder childOf, final Iterable<DataSchemaNode> schemaNodes) {
+        if (schemaNodes != null && parent != null) {
             for (DataSchemaNode schemaNode : schemaNodes) {
                 if (!schemaNode.isAugmenting() && !schemaNode.isAddedByUses()) {
                     addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, parent, childOf, module);
@@ -1031,7 +1033,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
      */
     private GeneratedTypeBuilder augSchemaNodeToMethods(final Module module, final String basePackageName,
             final GeneratedTypeBuilder typeBuilder, final GeneratedTypeBuilder childOf,
-            final Set<DataSchemaNode> schemaNodes) {
+            final Iterable<DataSchemaNode> schemaNodes) {
         if ((schemaNodes != null) && (typeBuilder != null)) {
             for (DataSchemaNode schemaNode : schemaNodes) {
                 if (!schemaNode.isAugmenting()) {
@@ -1164,7 +1166,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 caseTypeBuilder.addImplementsType(refChoiceType);
                 genCtx.get(module).addCaseType(caseNode.getPath(), caseTypeBuilder);
                 genCtx.get(module).addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode);
-                final Set<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
+                final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
                 if (caseChildNodes != null) {
                     Object parentNode = null;
                     final SchemaPath nodeSp = choiceNode.getPath();
@@ -1183,7 +1185,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
                             if (targetSchemaNode == null) {
                                 throw new IllegalStateException(
                                         "Failed to find target node from grouping for augmentation " + augSchema
-                                                + " in module " + module.getName());
+                                        + " in module " + module.getName());
                             }
                         }
                         parent = targetSchemaNode;
@@ -1231,7 +1233,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
      *             </ul>
      */
     private void generateTypesFromAugmentedChoiceCases(final Module module, final String basePackageName,
-            final Type targetType, final ChoiceNode targetNode, final Set<DataSchemaNode> augmentedNodes) {
+            final Type targetType, final ChoiceNode targetNode, final Iterable<DataSchemaNode> augmentedNodes) {
         checkArgument(basePackageName != null, "Base Package Name cannot be NULL.");
         checkArgument(targetType != null, "Referenced Choice Type cannot be NULL.");
         checkArgument(augmentedNodes != null, "Set of Choice Case Nodes cannot be NULL.");
@@ -1267,7 +1269,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 } else {
                     node = targetNode.getCaseNodeByName(caseNode.getQName().getLocalName());
                 }
-                final Set<DataSchemaNode> childNodes = node.getChildNodes();
+                final Iterable<DataSchemaNode> childNodes = node.getChildNodes();
                 if (childNodes != null) {
                     resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, childNodes);
                 }
index e87683db0710fe8ee10377a180a4d93fc1225e7c..86f0cdf881a64b156cde44b0a45ccb6270da2563 100644 (file)
@@ -311,8 +311,7 @@ class LazyGeneratedCodecRegistry implements CodecRegistry, SchemaContextListener
     }
 
     private DataSchemaNode searchInChoices(final DataNodeContainer node, final QName arg) {
-        Set<DataSchemaNode> children = node.getChildNodes();
-        for (DataSchemaNode child : children) {
+        for (DataSchemaNode child : node.getChildNodes()) {
             if (child instanceof ChoiceNode) {
                 ChoiceNode choiceNode = (ChoiceNode) child;
                 DataSchemaNode potential = searchInCases(choiceNode, arg);
@@ -425,8 +424,8 @@ class LazyGeneratedCodecRegistry implements CodecRegistry, SchemaContextListener
         for (Map.Entry<Type, AugmentationSchema> entry : bimap.entrySet()) {
             Type key = entry.getKey();
             AugmentationSchema value = entry.getValue();
-            Set<DataSchemaNode> augmentedNodes = value.getChildNodes();
-            if (augmentedNodes != null && !(augmentedNodes.isEmpty())) {
+            Collection<DataSchemaNode> augmentedNodes = value.getChildNodes();
+            if (augmentedNodes != null && !augmentedNodes.isEmpty()) {
                 typeToAugment.put(key, value);
             }
         }
index 1b6ffd9822baf31b9b2fab78b0348c01ec8060ef..b697bf99121377d019080e166d98652283ab86e5 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.yangtools.sal.binding.yang.types;
 
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -25,9 +28,6 @@ import org.opendaylight.yangtools.yang.model.api.UsesNode;
 import org.opendaylight.yangtools.yang.parser.util.TopologicalSort;
 import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Node;
 
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
 public class GroupingDefinitionDependencySort {
 
     /**
@@ -132,7 +132,7 @@ public class GroupingDefinitionDependencySort {
      *            data node container which can contain some uses of grouping
      * @return set of uses nodes which were find in <code>container</code>.
      */
-    private Set<UsesNode> getAllUsesNodes(DataNodeContainer container) {
+    private Set<UsesNode> getAllUsesNodes(final DataNodeContainer container) {
         Set<UsesNode> ret = new HashSet<>();
         Set<UsesNode> usesNodes = container.getUses();
         ret.addAll(usesNodes);
@@ -146,8 +146,7 @@ public class GroupingDefinitionDependencySort {
         for (GroupingDefinition groupingDefinition : groupings) {
             ret.addAll(getAllUsesNodes(groupingDefinition));
         }
-        Set<DataSchemaNode> childNodes = container.getChildNodes();
-        for (DataSchemaNode childNode : childNodes) {
+        for (DataSchemaNode childNode : container.getChildNodes()) {
             if (childNode instanceof DataNodeContainer) {
                 ret.addAll(getAllUsesNodes((DataNodeContainer) childNode));
             } else if (childNode instanceof ChoiceNode) {
index 8acc2ad11129abe0c24ccfc61863e3ec4695c645..bc4e267b0c6c429f1a52b8cf43dcf4cce1704d6b 100644 (file)
@@ -367,7 +367,7 @@ class GeneratorImpl {
         return targetPathNodes
     }
     
-    private def DataSchemaNode findNodeInChildNodes(QName findingNode, Set<DataSchemaNode> childNodes) {
+    private def DataSchemaNode findNodeInChildNodes(QName findingNode, Iterable<DataSchemaNode> childNodes) {
         for(child : childNodes) {
             if (child.QName.equals(findingNode))
                 return child;
@@ -950,7 +950,7 @@ class GeneratorImpl {
         '''
     }
 
-    def CharSequence printChildren(Set<DataSchemaNode> nodes, int level, InstanceIdentifier path) {
+    def CharSequence printChildren(Iterable<DataSchemaNode> nodes, int level, InstanceIdentifier path) {
         val anyxmlNodes = nodes.filter(AnyXmlSchemaNode)
         val leafNodes = nodes.filter(LeafSchemaNode)
         val leafListNodes = nodes.filter(LeafListSchemaNode)
@@ -1000,13 +1000,13 @@ class GeneratorImpl {
         '''
     }
 
-    def CharSequence xmlExample(Set<DataSchemaNode> nodes, QName name,InstanceIdentifier path) '''
+    def CharSequence xmlExample(Iterable<DataSchemaNode> nodes, QName name,InstanceIdentifier path) '''
     <pre>
         Â«xmlExampleTag(name,nodes.xmplExampleTags(path))»
     </pre>
     '''
 
-    def CharSequence xmplExampleTags(Set<DataSchemaNode> nodes, InstanceIdentifier identifier) '''
+    def CharSequence xmplExampleTags(Iterable<DataSchemaNode> nodes, InstanceIdentifier identifier) '''
         <!-- Child nodes -->
         Â«FOR node : nodes»
         <!-- Â«node.QName.localName» -->
index 16f408c243ee583777895488536082d1c6d23a3e..d75c5657bf1bceecc4be7925a286e9fbca481178 100644 (file)
@@ -11,6 +11,10 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import com.google.common.collect.ImmutableSet;
+
 import java.io.InputStream;
 import java.net.URI;
 import java.util.List;
@@ -30,10 +34,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
-import com.google.common.collect.ImmutableSet;
-
 public class MultipleRevisionsSupportTest {
 
     public static final YangModuleInfo TOPOLOGY_OLD_MODULE = org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev130712.$YangModuleInfoImpl
@@ -117,7 +117,7 @@ public class MultipleRevisionsSupportTest {
         verifyBindingDifference(schemaContext, TOPOLOGY_OLD_MODULE, TOPOLOGY_NEW_MODULE);
     }
 
-    private SchemaContext contextVerified(List<InputStream> streams) {
+    private SchemaContext contextVerified(final List<InputStream> streams) {
         YangParserImpl parser = new YangParserImpl();
         Set<Module> modules = parser.parseYangModelsFromStreams(streams);
         assertNotNull(modules);
@@ -127,19 +127,19 @@ public class MultipleRevisionsSupportTest {
         return context;
     }
 
-    private void verifyBindingDifference(SchemaContext schemaContext, YangModuleInfo oldModule, YangModuleInfo newModule) {
+    private void verifyBindingDifference(final SchemaContext schemaContext, final YangModuleInfo oldModule, final YangModuleInfo newModule) {
         generatedTypesVerified(schemaContext, oldModule, newModule);
     }
 
-    private Map<Module, ModuleContext> generatedTypesVerified(SchemaContext schemaContext, YangModuleInfo oldModule,
-            YangModuleInfo newModule) {
+    private Map<Module, ModuleContext> generatedTypesVerified(final SchemaContext schemaContext, final YangModuleInfo oldModule,
+            final YangModuleInfo newModule) {
         BindingGeneratorImpl generator = new BindingGeneratorImpl();
         generator.generateTypes(schemaContext);
         return generator.getModuleContexts();
     }
 
-    private void verifySchemaDifference(SchemaContext context, YangModuleInfo topologyOldModule,
-            YangModuleInfo topologyNewModule) {
+    private void verifySchemaDifference(final SchemaContext context, final YangModuleInfo topologyOldModule,
+            final YangModuleInfo topologyNewModule) {
         Module oldModel = context.findModuleByNamespaceAndRevision(//
                 URI.create(TOPOLOGY_OLD_MODULE.getNamespace()), QName.parseRevision(TOPOLOGY_OLD_MODULE.getRevision()));
 
@@ -156,7 +156,7 @@ public class MultipleRevisionsSupportTest {
         assertDeepRevision(TOPOLOGY_NEW_MODULE.getRevision(), newNode);
     }
 
-    private static void assertDeepRevision(String revision, SchemaNode node) {
+    private static void assertDeepRevision(final String revision, final SchemaNode node) {
         assertEquals("Wrong revision: " + node.getPath(), revision, node.getQName().getFormattedRevision());
         if (node instanceof DataNodeContainer) {
             for (DataSchemaNode child : ((DataNodeContainer) node).getChildNodes()) {
@@ -169,7 +169,7 @@ public class MultipleRevisionsSupportTest {
         }
     }
 
-    private static final SchemaNode findSchemaNode(DataNodeContainer container, String... pathArgs) {
+    private static final SchemaNode findSchemaNode(final DataNodeContainer container, final String... pathArgs) {
         DataNodeContainer previous = container;
 
         SchemaNode result = (container instanceof SchemaNode) ? (SchemaNode) container : null;
@@ -177,8 +177,7 @@ public class MultipleRevisionsSupportTest {
             if (previous == null) {
                 return null;
             }
-            Set<DataSchemaNode> childs = previous.getChildNodes();
-            for (DataSchemaNode child : childs) {
+            for (DataSchemaNode child : previous.getChildNodes()) {
                 if (child.getQName().getLocalName().equals(arg)) {
                     if (child instanceof DataNodeContainer) {
                         previous = (DataNodeContainer) child;
@@ -193,7 +192,7 @@ public class MultipleRevisionsSupportTest {
         return result;
     }
 
-    private static final Iterable<? extends InputStream> toInputStreams(Set<YangModuleInfo> moduleInfos)
+    private static final Iterable<? extends InputStream> toInputStreams(final Set<YangModuleInfo> moduleInfos)
             throws Exception {
         Builder<InputStream> streams = ImmutableList.<InputStream> builder();
         for (YangModuleInfo yangModuleInfo : moduleInfos) {
index 2da30e54bd5a03053d8ed01a4aab8a4c17d1c626..262a48a93385579c74061d497ea11c0abcdcb18a 100644 (file)
@@ -9,6 +9,13 @@ package org.opendaylight.yangtools.yang.data.impl.codec.xml;
 
 import static com.google.common.base.Preconditions.checkState;
 
+import com.google.common.base.Function;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.List;
@@ -54,13 +61,6 @@ import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
-import com.google.common.base.Function;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableList;
-
 public class XmlDocumentUtils {
     private static class ElementWithSchemaContext {
         Element element;
@@ -278,8 +278,8 @@ public class XmlDocumentUtils {
         checkState(qName.getLocalName().equals(xmlElement.getLocalName()));
     }
 
-    public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Set<DataSchemaNode> dataSchemaNode) {
-        if (dataSchemaNode != null && !dataSchemaNode.isEmpty() && qname != null) {
+    public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Iterable<DataSchemaNode> dataSchemaNode) {
+        if (dataSchemaNode != null && qname != null) {
             for (DataSchemaNode dsn : dataSchemaNode) {
                 if (qname.isEqualWithoutRevision(dsn.getQName())) {
                     return Optional.<DataSchemaNode> of(dsn);
@@ -326,7 +326,7 @@ public class XmlDocumentUtils {
         return ImmutableCompositeNode.create(qname, values.build());
     }
 
-    public static List<Node<?>> toDomNodes(final Element element, final Optional<Set<DataSchemaNode>> context,final SchemaContext schemaCtx) {
+    public static List<Node<?>> toDomNodes(final Element element, final Optional<? extends Iterable<DataSchemaNode>> context, final SchemaContext schemaCtx) {
         return forEachChild(element.getChildNodes(),schemaCtx, new Function<ElementWithSchemaContext, Optional<Node<?>>>() {
 
             @Override
@@ -335,7 +335,7 @@ public class XmlDocumentUtils {
                     QName partialQName = qNameFromElement(input.getElement());
                     Optional<DataSchemaNode> schemaNode = findFirstSchema(partialQName, context.get());
                     if (schemaNode.isPresent()) {
-                        return Optional.<Node<?>> fromNullable(//
+                        return Optional.<Node<?>> fromNullable(
                                 toNodeWithSchema(input.getElement(), schemaNode.get(), XmlUtils.DEFAULT_XML_CODEC_PROVIDER, input.getSchemaContext()));
                     }
                 }
@@ -346,8 +346,8 @@ public class XmlDocumentUtils {
 
     }
 
-    public static List<Node<?>> toDomNodes(final Element element, final Optional<Set<DataSchemaNode>> context) {
-        return toDomNodes(element,context,null);
+    public static List<Node<?>> toDomNodes(final Element element, final Optional<? extends Iterable<DataSchemaNode>> context) {
+        return toDomNodes(element, context, null);
     }
 
     /**
@@ -383,9 +383,9 @@ public class XmlDocumentUtils {
                     final Optional<NotificationDefinition> notificationDef = findNotification(partialQName,
                             notifications.get());
                     if (notificationDef.isPresent()) {
-                        final Set<DataSchemaNode> dataNodes = notificationDef.get().getChildNodes();
+                        final Iterable<DataSchemaNode> dataNodes = notificationDef.get().getChildNodes();
                         final List<Node<?>> domNodes = toDomNodes(childElement,
-                                Optional.<Set<DataSchemaNode>> fromNullable(dataNodes),schemaCtx);
+                                Optional.<Iterable<DataSchemaNode>> fromNullable(dataNodes),schemaCtx);
                         return ImmutableCompositeNode.create(notificationDef.get().getQName(), domNodes);
                     }
                 }
index fe5892a3f61cb5e906ff939fd52b59fe6de90a3d..bafeeaeb8a16de93d367f25a99e56fac5f08e4f4 100644 (file)
@@ -36,8 +36,8 @@ public final class SchemaUtils {
     private SchemaUtils() {
     }
 
-    public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Set<DataSchemaNode> dataSchemaNode) {
-        if (dataSchemaNode != null && !dataSchemaNode.isEmpty() && qname != null) {
+    public static final Optional<DataSchemaNode> findFirstSchema(final QName qname, final Iterable<DataSchemaNode> dataSchemaNode) {
+        if (dataSchemaNode != null && qname != null) {
             for (DataSchemaNode dsn : dataSchemaNode) {
                 if (qname.isEqualWithoutRevision(dsn.getQName())) {
                     return Optional.<DataSchemaNode> of(dsn);
@@ -55,11 +55,10 @@ public final class SchemaUtils {
     }
 
     public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname) {
-        Set<DataSchemaNode> childNodes = schema.getChildNodes();
-        return findSchemaForChild(schema, qname, childNodes);
+        return findSchemaForChild(schema, qname, schema.getChildNodes());
     }
 
-    public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname, final Set<DataSchemaNode> childNodes) {
+    public static DataSchemaNode findSchemaForChild(final DataNodeContainer schema, final QName qname, final Iterable<DataSchemaNode> childNodes) {
         Optional<DataSchemaNode> childSchema = findFirstSchema(qname, childNodes);
         Preconditions.checkState(childSchema.isPresent(),
                 "Unknown child(ren) node(s) detected, identified by: %s, in: %s", qname, schema);
@@ -125,12 +124,10 @@ public final class SchemaUtils {
      * @return Map with all child nodes, to their most top augmentation
      */
     public static Map<QName, ChoiceNode> mapChildElementsFromChoices(final DataNodeContainer schema) {
-        Set<DataSchemaNode> childNodes = schema.getChildNodes();
-
-        return mapChildElementsFromChoices(schema, childNodes);
+        return mapChildElementsFromChoices(schema, schema.getChildNodes());
     }
 
-    private static Map<QName, ChoiceNode> mapChildElementsFromChoices(final DataNodeContainer schema, final Set<DataSchemaNode> childNodes) {
+    private static Map<QName, ChoiceNode> mapChildElementsFromChoices(final DataNodeContainer schema, final Iterable<DataSchemaNode> childNodes) {
         Map<QName, ChoiceNode> mappedChoices = Maps.newLinkedHashMap();
 
         for (final DataSchemaNode childSchema : childNodes) {
index 6fcc0f345db85206043ad4a230dc4b5467f7ffb2..d15c6339c72b93d3c28f638d5ed197e940d2fe24 100644 (file)
@@ -7,6 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema;
 
+import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
 import java.io.InputStream;
 import java.net.URI;
 import java.util.Collections;
@@ -38,34 +44,28 @@ import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
 
-import com.google.common.base.Function;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
 public class NormalizedDataBuilderTest {
 
     private ContainerSchemaNode containerNode;
     private SchemaContext schema;
 
-    SchemaContext parseTestSchema(String... yangPath) {
+    SchemaContext parseTestSchema(final String... yangPath) {
         YangParserImpl yangParserImpl = new YangParserImpl();
         Set<Module> modules = yangParserImpl.parseYangModelsFromStreams(getTestYangs(yangPath));
         return yangParserImpl.resolveSchemaContext(modules);
     }
 
-    List<InputStream> getTestYangs(String... yangPaths) {
+    List<InputStream> getTestYangs(final String... yangPaths) {
 
         return Lists.newArrayList(Collections2.transform(Lists.newArrayList(yangPaths),
                 new Function<String, InputStream>() {
-                    @Override
-                    public InputStream apply(String input) {
-                        InputStream resourceAsStream = getClass().getResourceAsStream(input);
-                        Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream);
-                        return resourceAsStream;
-                    }
-                }));
+            @Override
+            public InputStream apply(final String input) {
+                InputStream resourceAsStream = getClass().getResourceAsStream(input);
+                Preconditions.checkNotNull(resourceAsStream, "File %s was null", resourceAsStream);
+                return resourceAsStream;
+            }
+        }));
     }
 
     @Before
@@ -92,8 +92,8 @@ public class NormalizedDataBuilderTest {
                 .withChildValue(1)
                 .withChild(
                         Builders.<Integer> leafSetEntryBuilder()
-                                .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build())
-                .build();
+                        .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3)).withValue(3).build())
+                        .build();
         builder.withChild(leafList);
 
         // list
@@ -101,12 +101,12 @@ public class NormalizedDataBuilderTest {
                 .mapEntryBuilder()
                 .withChild(
                         Builders.<Integer> leafBuilder().withNodeIdentifier(getNodeIdentifier("uint32InList"))
-                                .withValue(1).build())
-                .withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("containerInList")).build())
-                .withNodeIdentifier(
-                        new InstanceIdentifier.NodeIdentifierWithPredicates(getNodeIdentifier("list").getNodeType(),
-                                Collections.singletonMap(getNodeIdentifier("uint32InList").getNodeType(), (Object) 1)))
-                .build();
+                        .withValue(1).build())
+                        .withChild(Builders.containerBuilder().withNodeIdentifier(getNodeIdentifier("containerInList")).build())
+                        .withNodeIdentifier(
+                                new InstanceIdentifier.NodeIdentifierWithPredicates(getNodeIdentifier("list").getNodeType(),
+                                        Collections.singletonMap(getNodeIdentifier("uint32InList").getNodeType(), (Object) 1)))
+                                        .build();
 
         MapNode list = Builders.mapBuilder().withChild(listChild1).withNodeIdentifier(getNodeIdentifier("list"))
                 .build();
@@ -116,8 +116,8 @@ public class NormalizedDataBuilderTest {
                 .augmentationBuilder()
                 .withNodeIdentifier(
                         new InstanceIdentifier.AugmentationIdentifier(Sets.newHashSet(getQName("augmentUint32"))))
-                .withChild(
-                        Builders.<Integer> leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32"))
+                        .withChild(
+                                Builders.<Integer> leafBuilder().withNodeIdentifier(getNodeIdentifier("augmentUint32"))
                                 .withValue(11).build()).build();
 
         builder.withChild(augmentation);
@@ -186,7 +186,7 @@ public class NormalizedDataBuilderTest {
         // .build());
     }
 
-    private AugmentationSchema getAugmentationSchemaForChild(ContainerSchemaNode containerNode, QName qName) {
+    private AugmentationSchema getAugmentationSchemaForChild(final ContainerSchemaNode containerNode, final QName qName) {
         for (AugmentationSchema augmentationSchema : containerNode.getAvailableAugmentations()) {
             if (augmentationSchema.getDataChildByName(qName) != null) {
                 return augmentationSchema;
@@ -195,20 +195,20 @@ public class NormalizedDataBuilderTest {
         throw new IllegalStateException("Unable to find child augmentation in " + containerNode);
     }
 
-    private InstanceIdentifier.NodeWithValue getNodeWithValueIdentifier(String localName, Object value) {
+    private InstanceIdentifier.NodeWithValue getNodeWithValueIdentifier(final String localName, final Object value) {
         return new InstanceIdentifier.NodeWithValue(getQName(localName), value);
     }
 
-    private QName getQName(String localName) {
+    private QName getQName(final String localName) {
         String namespace = "namespace";
         return new QName(URI.create(namespace), localName);
     }
 
-    private InstanceIdentifier.NodeIdentifier getNodeIdentifier(String localName) {
+    private InstanceIdentifier.NodeIdentifier getNodeIdentifier(final String localName) {
         return new InstanceIdentifier.NodeIdentifier(getQName(localName));
     }
 
-    public static DataSchemaNode getSchemaNode(SchemaContext context, String moduleName, String childNodeName) {
+    public static DataSchemaNode getSchemaNode(final SchemaContext context, final String moduleName, final String childNodeName) {
         for (Module module : context.getModules()) {
             if (module.getName().equals(moduleName)) {
                 DataSchemaNode found = findChildNode(module.getChildNodes(), childNodeName);
@@ -219,12 +219,13 @@ public class NormalizedDataBuilderTest {
         throw new IllegalStateException("Unable to find child node " + childNodeName);
     }
 
-    static DataSchemaNode findChildNode(Set<DataSchemaNode> children, String name) {
+    private static DataSchemaNode findChildNode(final Iterable<DataSchemaNode> children, final String name) {
         List<DataNodeContainer> containers = Lists.newArrayList();
 
         for (DataSchemaNode dataSchemaNode : children) {
-            if (dataSchemaNode.getQName().getLocalName().equals(name))
+            if (dataSchemaNode.getQName().getLocalName().equals(name)) {
                 return dataSchemaNode;
+            }
             if (dataSchemaNode instanceof DataNodeContainer) {
                 containers.add((DataNodeContainer) dataSchemaNode);
             } else if (dataSchemaNode instanceof ChoiceNode) {
index 8b20b2b72f3ee8f0f00444029d162b8f58988283..8b15c979a276d1b8819b342c4152abb17a5da23d 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.model.api;
 
+import java.util.Collection;
 import java.util.Set;
 
 import org.opendaylight.yangtools.yang.common.QName;
@@ -25,10 +26,12 @@ public interface DataNodeContainer {
 
     /**
      * Returns set of all child nodes defined within this DataNodeContainer.
+     * Although the return type is a collection, each node is guaranteed to
+     * be present at most once.
      *
      * @return child nodes in lexicographical order
      */
-    Set<DataSchemaNode> getChildNodes();
+    Collection<DataSchemaNode> getChildNodes();
 
     /**
      * Returns set of all groupings defined within this DataNodeContainer.
index 850b51de87f52d091536008723b4075c1ba4763e..025c11c1e26b3fd53d1f7b99b28be84fcb65f59c 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.model.util;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -109,7 +110,7 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
             return;
         }
 
-        final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();
+        final Iterable<DataSchemaNode> childNodes = dataNode.getChildNodes();
         if (childNodes != null) {
             for (DataSchemaNode childNode : childNodes) {
                 if (childNode.isAugmenting()) {
@@ -183,7 +184,7 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
     @Override
     public boolean hasNext() {
         if (container.getChildNodes() != null) {
-            final Set<DataSchemaNode> childNodes = container.getChildNodes();
+            final Collection<DataSchemaNode> childNodes = container.getChildNodes();
 
             if ((childNodes != null) && !childNodes.isEmpty()) {
                 return childNodes.iterator().hasNext();
index b227759c6ea93e0c199e4562a4c01bcdb3aeccc2..2ce662647a0994fd0bce50c48d8af92dd3abdce3 100644 (file)
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
+
 import org.apache.commons.io.IOUtils;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -662,8 +663,8 @@ public final class BuilderUtils {
     }
 
     public static Set<DataSchemaNodeBuilder> wrapChildNodes(final String moduleName, final int line,
-            final Set<DataSchemaNode> nodes, final SchemaPath parentPath, final QName parentQName) {
-        Set<DataSchemaNodeBuilder> result = new LinkedHashSet<>();
+            final Collection<DataSchemaNode> nodes, final SchemaPath parentPath, final QName parentQName) {
+        Set<DataSchemaNodeBuilder> result = new LinkedHashSet<>(nodes.size());
 
         for (DataSchemaNode node : nodes) {
             QName qname = QName.create(parentQName, node.getQName().getLocalName());
index 30c46efc752a6d2fb0d1ae738fd9247f555d10bc..b20c9780875c3729a7219fd9cf7f0ae15f7816ed 100644 (file)
@@ -19,10 +19,12 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Set;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -86,7 +88,7 @@ public class AugmentTest {
         expectedSchemaPath = SchemaPath.create(qnames, true);
         assertEquals(expectedSchemaPath, augment.getTargetPath());
 
-        Set<DataSchemaNode> augmentChildren = augment.getChildNodes();
+        Collection<DataSchemaNode> augmentChildren = augment.getChildNodes();
         assertEquals(4, augmentChildren.size());
         for (DataSchemaNode dsn : augmentChildren) {
             TestUtils.checkIsAugmenting(dsn, false);
@@ -285,7 +287,7 @@ public class AugmentTest {
         qnames.add(qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, id.getPath());
-        Set<DataSchemaNode> idChildren = id.getChildNodes();
+        Collection<DataSchemaNode> idChildren = id.getChildNodes();
         assertEquals(1, idChildren.size());
 
         // case node1
@@ -294,7 +296,7 @@ public class AugmentTest {
         qnames.set(4, qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, node1.getPath());
-        Set<DataSchemaNode> node1Children = node1.getChildNodes();
+        Collection<DataSchemaNode> node1Children = node1.getChildNodes();
         assertTrue(node1Children.isEmpty());
 
         // case node2
@@ -303,7 +305,7 @@ public class AugmentTest {
         qnames.set(4, qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, node2.getPath());
-        Set<DataSchemaNode> node2Children = node2.getChildNodes();
+        Collection<DataSchemaNode> node2Children = node2.getChildNodes();
         assertTrue(node2Children.isEmpty());
 
         // case node3
@@ -312,7 +314,7 @@ public class AugmentTest {
         qnames.set(4, qname);
         expectedPath = SchemaPath.create(qnames, true);
         assertEquals(expectedPath, node3.getPath());
-        Set<DataSchemaNode> node3Children = node3.getChildNodes();
+        Collection<DataSchemaNode> node3Children = node3.getChildNodes();
         assertEquals(1, node3Children.size());
 
         // test cases
@@ -402,7 +404,7 @@ public class AugmentTest {
         assertEquals(qnames[3], attach.getQName());
         expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
         assertEquals(expectedPath, attach.getPath());
-        Set<DataSchemaNode> attachChildren = attach.getChildNodes();
+        Collection<DataSchemaNode> attachChildren = attach.getChildNodes();
         assertEquals(1, attachChildren.size());
 
         // case create
@@ -410,7 +412,7 @@ public class AugmentTest {
         assertEquals(qnames[3], create.getQName());
         expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
         assertEquals(expectedPath, create.getPath());
-        Set<DataSchemaNode> createChildren = create.getChildNodes();
+        Collection<DataSchemaNode> createChildren = create.getChildNodes();
         assertEquals(1, createChildren.size());
 
         // case attach
@@ -418,7 +420,7 @@ public class AugmentTest {
         assertEquals(qnames[3], destroy.getQName());
         expectedPath = SchemaPath.create(Arrays.asList(qnames), true);
         assertEquals(expectedPath, destroy.getPath());
-        Set<DataSchemaNode> destroyChildren = destroy.getChildNodes();
+        Collection<DataSchemaNode> destroyChildren = destroy.getChildNodes();
         assertEquals(1, destroyChildren.size());
     }
 
index 043c3c7f2944d006aa354734f4205f8d20ed581d..03dc0663de7ba5910a5f54bc294e1d09afe55cfe 100644 (file)
@@ -18,6 +18,7 @@ import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.text.SimpleDateFormat;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
@@ -122,7 +123,7 @@ public class GroupingTest {
         Set<GroupingDefinition> groupings = testModule.getGroupings();
         assertEquals(1, groupings.size());
         GroupingDefinition grouping = groupings.iterator().next();
-        Set<DataSchemaNode> children = grouping.getChildNodes();
+        Collection<DataSchemaNode> children = grouping.getChildNodes();
         assertEquals(5, children.size());
     }
 
@@ -352,7 +353,7 @@ public class GroupingTest {
         assertEquals(1, usesAugments.size());
         AugmentationSchema augment = usesAugments.iterator().next();
         assertEquals("inner augment", augment.getDescription());
-        Set<DataSchemaNode> children = augment.getChildNodes();
+        Collection<DataSchemaNode> children = augment.getChildNodes();
         assertEquals(1, children.size());
         DataSchemaNode leaf = children.iterator().next();
         assertTrue(leaf instanceof LeafSchemaNode);
@@ -411,7 +412,7 @@ public class GroupingTest {
         SchemaPath expectedPath;
 
         // grouping-U
-        Set<DataSchemaNode> childNodes = gu.getChildNodes();
+        Collection<DataSchemaNode> childNodes = gu.getChildNodes();
         assertEquals(7, childNodes.size());
 
         LeafSchemaNode leafGroupingU = (LeafSchemaNode) gu.getDataChildByName("leaf-grouping-U");
index dbdde51e265899e66730686aada2db05645917c7..0ea41a074465192dbb3b076215a0dc58e8527934 100644 (file)
@@ -13,7 +13,9 @@ import static org.junit.Assert.assertNotNull;
 
 import java.io.IOException;
 import java.net.URISyntaxException;
+import java.util.Collection;
 import java.util.Set;
+
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
@@ -71,7 +73,7 @@ public class OrderingTest {
         Set<Module> modules = TestUtils.loadModules(getClass().getResource("/model").toURI());
         Module foo = TestUtils.findModule(modules, "foo");
 
-        Set<DataSchemaNode> childNodes = foo.getChildNodes();
+        Collection<DataSchemaNode> childNodes = foo.getChildNodes();
         String[] expectedOrder = new String[] { "int32-leaf", "string-leaf", "length-leaf", "decimal-leaf",
                 "decimal-leaf2", "ext", "union-leaf", "custom-union-leaf", "transfer", "datas", "mycont", "data",
                 "how", "address", "port", "addresses", "peer" };
@@ -93,7 +95,7 @@ public class OrderingTest {
         assertEquals(1, groupings.size());
         GroupingDefinition target = groupings.iterator().next();
 
-        Set<DataSchemaNode> childNodes = target.getChildNodes();
+        Collection<DataSchemaNode> childNodes = target.getChildNodes();
         String[] expectedOrder = new String[] { "data", "how", "address", "port", "addresses" };
         String[] actualOrder = new String[childNodes.size()];
 
@@ -109,10 +111,9 @@ public class OrderingTest {
     public void testOrderingNestedChildNodes3() throws Exception {
         Module baz = TestUtils.loadModule(getClass().getResourceAsStream("/ordering/foo.yang"));
         ContainerSchemaNode x = (ContainerSchemaNode) baz.getDataChildByName("x");
-        Set<DataSchemaNode> childNodes = x.getChildNodes();
+        Collection<DataSchemaNode> childNodes = x.getChildNodes();
 
-        String[] expectedOrder = new String[] { "x15", "x10", "x5", "x1", "a5", "a1", "x2", "b5", "b1", "x3", "ax15",
-                "ax5" };
+        String[] expectedOrder = new String[] { "x15", "x10", "x5", "x1", "a5", "a1", "x2", "b5", "b1", "x3", "ax15", "ax5" };
         String[] actualOrder = new String[childNodes.size()];
 
         int i = 0;
index 79136aa5fc49dc48a51f88a751ed507729257aed..010570dc10b9d4d8d2402f10cefb77e1f38ac653 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.Lists;
+
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.URI;
@@ -20,10 +21,12 @@ import java.net.URISyntaxException;
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.util.Collection;
 import java.util.Date;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
+
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -130,7 +133,7 @@ public class UsesAugmentTest {
         path.offer(expectedQName);
         SchemaPath expectedPath = SchemaPath.create(path, true);
         assertEquals(expectedPath, pcreq.getPath());
-        Set<DataSchemaNode> childNodes = pcreq.getChildNodes();
+        Collection<DataSchemaNode> childNodes = pcreq.getChildNodes();
         assertEquals(4, childNodes.size());
         // * |-- leaf version
         LeafSchemaNode version = (LeafSchemaNode) pcreq.getDataChildByName("version");