API Clarity: Documented o.o.y.yang.parser.builder.api
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / builder / api / AbstractDataNodeContainerBuilder.java
index 798862b457df19dacefad5cca4a00a2571820dc6..9a86e5ca2f03ff78c9310201cb286d0b7a9dadf3 100644 (file)
@@ -1,6 +1,5 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- *
+ * 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
@@ -24,9 +23,9 @@ import org.opendaylight.yangtools.yang.parser.util.YangParseException;
  * Basic implementation of DataNodeContainerBuilder.
  */
 public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder implements DataNodeContainerBuilder {
-    protected QName qname;
+    protected final QName qname;
 
-    protected final Set<DataSchemaNode> childNodes = new HashSet<>();
+    protected final Set<DataSchemaNode> childNodes = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
     protected final Set<DataSchemaNodeBuilder> addedChildNodes = new HashSet<>();
 
     protected final Set<GroupingDefinition> groupings = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
@@ -72,9 +71,9 @@ public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder i
         QName childName = child.getQName();
         for (DataSchemaNodeBuilder addedChildNode : addedChildNodes) {
             if (addedChildNode.getQName().equals(childName)) {
-                throw new YangParseException(child.getModuleName(), child.getLine(), "Can not add '" + child + "' to '"
-                        + this + "' in module '" + moduleName + "': node with same name already declared at line "
-                        + addedChildNode.getLine());
+                throw new YangParseException(child.getModuleName(), child.getLine(), String.format(
+                        "Can not add '%s' to '%s' in module '%s': node with same name already declared at line %d",
+                        child, this, getModuleName(), addedChildNode.getLine()));
             }
         }
         addedChildNodes.add(child);
@@ -90,8 +89,9 @@ public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder i
         QName childName = child.getQName();
         for (DataSchemaNode childNode : childNodes) {
             if (childNode.getQName().equals(childName)) {
-                throw new YangParseException(moduleName, line, "Can not add '" + child + "' to '" + this
-                        + "' in module '" + moduleName + "': node with same name already declared");
+                throw new YangParseException(getModuleName(), getLine(), String.format(
+                        "Can not add '%s' to '%s' in module '%s': node with same name already declared", child, this,
+                        getModuleName()));
             }
         }
         childNodes.add(child);
@@ -105,6 +105,7 @@ public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder i
         return groupings;
     }
 
+    @Override
     public Set<GroupingBuilder> getGroupingBuilders() {
         return addedGroupings;
     }
@@ -114,9 +115,9 @@ public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder i
         QName groupingName = grouping.getQName();
         for (GroupingBuilder addedGrouping : addedGroupings) {
             if (addedGrouping.getQName().equals(groupingName)) {
-                throw new YangParseException(grouping.getModuleName(), grouping.getLine(), "Can not add '" + grouping
-                        + "': grouping with same name already declared in module '" + moduleName + "' at line "
-                        + addedGrouping.getLine());
+                throw new YangParseException(grouping.getModuleName(), grouping.getLine(), String.format(
+                        "Can not add '%s': grouping with same name already declared in module '%s' at line %d",
+                        grouping, getModuleName(), addedGrouping.getLine()));
             }
         }
         addedGroupings.add(grouping);
@@ -141,7 +142,7 @@ public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder i
         addedUsesNodes.add(usesNode);
     }
 
-    public DataSchemaNode getChildNode(Set<DataSchemaNode> childNodes, QName name) {
+    protected static DataSchemaNode getChildNode(Set<DataSchemaNode> childNodes, QName name) {
         for (DataSchemaNode node : childNodes) {
             if (node.getQName().equals(name)) {
                 return node;
@@ -150,7 +151,7 @@ public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder i
         return null;
     }
 
-    public DataSchemaNode getChildNode(Set<DataSchemaNode> childNodes, String name) {
+    protected static DataSchemaNode getChildNode(Set<DataSchemaNode> childNodes, String name) {
         for (DataSchemaNode node : childNodes) {
             if (node.getQName().getLocalName().equals(name)) {
                 return node;