X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Fbuilder%2Futil%2FAbstractDocumentedDataNodeContainerBuilder.java;h=22b2a98a4821cd379ec50dcf084ea77cbc3f2b86;hb=42abb28b99a02f9580f4676ce5c315628e5bcd24;hp=6877538607c62f64a4c7db3005b3729aaab4a96a;hpb=b0acc8cf2b17ea7ba67a33acc4e868c4433c45b5;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedDataNodeContainerBuilder.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedDataNodeContainerBuilder.java index 6877538607..22b2a98a48 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedDataNodeContainerBuilder.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/util/AbstractDocumentedDataNodeContainerBuilder.java @@ -1,15 +1,18 @@ /* - * 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 */ package org.opendaylight.yangtools.yang.parser.builder.util; +import java.util.ArrayList; import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Set; -import java.util.TreeMap; import java.util.TreeSet; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; @@ -29,12 +32,15 @@ import org.opendaylight.yangtools.yang.parser.util.YangParseException; /** * Basic implementation of DataNodeContainerBuilder. + * + * @deprecated Pre-Beryllium implementation, scheduled for removal. */ +@Deprecated public abstract class AbstractDocumentedDataNodeContainerBuilder extends AbstractDocumentedNodeBuilder implements DataNodeContainerBuilder { protected final QName qname; - private final Map childNodes = new TreeMap<>(); - private final Set addedChildNodes = new HashSet<>(); + private final Map childNodes = new LinkedHashMap<>(); + private final List addedChildNodes = new ArrayList<>(); private final Set groupings = new TreeSet<>(Comparators.SCHEMA_NODE_COMP); private final Set addedGroupings = new HashSet<>(); @@ -43,7 +49,7 @@ public abstract class AbstractDocumentedDataNodeContainerBuilder extends Abstrac private final Set addedTypedefs = new HashSet<>(); private final Set usesNodes = new HashSet<>(); - private final Set addedUsesNodes = new HashSet<>(); + private final List addedUsesNodes = new ArrayList<>(); protected AbstractDocumentedDataNodeContainerBuilder(final String moduleName, final int line, final QName qname) { super(moduleName, line); @@ -84,7 +90,7 @@ public abstract class AbstractDocumentedDataNodeContainerBuilder extends Abstrac } @Override - public final Set getChildNodeBuilders() { + public final List getChildNodeBuilders() { return addedChildNodes; } @@ -100,15 +106,28 @@ public abstract class AbstractDocumentedDataNodeContainerBuilder extends Abstrac @Override public final void addChildNode(final DataSchemaNodeBuilder child) { - QName childName = child.getQName(); + checkIsPresent(child); + addedChildNodes.add(child); + } + + @Override + public final void addChildNode(final int index, final DataSchemaNodeBuilder child) { + checkIsPresent(child); + if (index > addedChildNodes.size()) { + addedChildNodes.add(child); + } else { + addedChildNodes.add(index, child); + } + } + + private void checkIsPresent(final DataSchemaNodeBuilder child) { for (DataSchemaNodeBuilder addedChildNode : addedChildNodes) { - if (addedChildNode.getQName().equals(childName)) { + if (addedChildNode.getQName().equals(child.getQName())) { 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); } @Override @@ -120,14 +139,12 @@ public abstract class AbstractDocumentedDataNodeContainerBuilder extends Abstrac public final void addChildNode(final DataSchemaNode child) { checkNotSealed(); QName childName = child.getQName(); - for (DataSchemaNode childNode : childNodes.values()) { - if (childNode.getQName().equals(childName)) { - 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())); - } + if (childNodes.containsKey(childName)) { + 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.put(child.getQName(), child); + childNodes.put(childName, child); } @Override @@ -141,7 +158,7 @@ public abstract class AbstractDocumentedDataNodeContainerBuilder extends Abstrac } @Override - public final void addGrouping(final GroupingBuilder grouping) { + public void addGrouping(final GroupingBuilder grouping) { checkNotSealed(); QName groupingName = grouping.getQName(); for (GroupingBuilder addedGrouping : addedGroupings) { @@ -164,7 +181,7 @@ public abstract class AbstractDocumentedDataNodeContainerBuilder extends Abstrac } @Override - public final Set getUsesNodeBuilders() { + public final List getUsesNodeBuilders() { return addedUsesNodes; } @@ -216,25 +233,4 @@ public abstract class AbstractDocumentedDataNodeContainerBuilder extends Abstrac } } - @Deprecated - protected static DataSchemaNode getChildNode(final Set childNodes, final QName name) { - for (DataSchemaNode node : childNodes) { - if (node.getQName().equals(name)) { - return node; - } - } - return null; - } - - @Deprecated - protected static DataSchemaNode getChildNode(final Set childNodes, final String name) { - for (DataSchemaNode node : childNodes) { - if (node.getQName().getLocalName().equals(name)) { - return node; - } - } - return null; - } - - }