Merge "BUG-1433: augmentation field visibility changed to default"
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / util / AbstractDocumentedDataNodeContainer.java
index 259a48e471b47005bce8dbb8d7bb9e1871956542..766b61fbce1605e094f920187822eeecc9d186e5 100644 (file)
@@ -1,9 +1,18 @@
+/*
+ * Copyright (c) 2014 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.yangtools.yang.parser.builder.util;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
+
 import java.util.Map;
 import java.util.Set;
+
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -17,6 +26,7 @@ public abstract class AbstractDocumentedDataNodeContainer extends AbstractDocume
     private final Set<GroupingDefinition> groupings;
     private final Set<UsesNode> uses;
     private final Set<TypeDefinition<?>> typeDefinitions;
+    private final Set<DataSchemaNode> publicChildNodes;
 
     protected AbstractDocumentedDataNodeContainer(final AbstractDocumentedDataNodeContainerBuilder data) {
         super(data);
@@ -27,6 +37,7 @@ public abstract class AbstractDocumentedDataNodeContainer extends AbstractDocume
         groupings = ImmutableSet.copyOf(data.getGroupings());
         uses = ImmutableSet.copyOf(data.getUsesNodes());
         typeDefinitions = ImmutableSet.copyOf(data.getTypeDefinitions());
+        publicChildNodes = ImmutableSet.copyOf(childNodes.values());
     }
 
     @Override
@@ -36,7 +47,7 @@ public abstract class AbstractDocumentedDataNodeContainer extends AbstractDocume
 
     @Override
     public final Set<DataSchemaNode> getChildNodes() {
-        return ImmutableSet.copyOf(childNodes.values());
+        return publicChildNodes;
     }
 
     @Override
@@ -46,12 +57,8 @@ public abstract class AbstractDocumentedDataNodeContainer extends AbstractDocume
 
     @Override
     public final DataSchemaNode getDataChildByName(final QName name) {
-        for (DataSchemaNode node : childNodes.values()) {
-            if (node.getQName().equals(name)) {
-                return node;
-            }
-        }
-        return null;
+        // Child nodes are keyed by their container name, so we can do a direct lookup
+        return childNodes.get(name);
     }
 
     @Override