import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilderBase
import com.google.common.collect.Sets
+import java.util.TreeSet
public class BindingGeneratorImpl implements BindingGenerator {
checkState(module.augmentations !== null, "Augmentations Set cannot be NULL.");
val Set<AugmentationSchema> augmentations = module.augmentations;
- val List<AugmentationSchema> sortedAugmentations = new ArrayList(augmentations);
+ var List<AugmentationSchema> sortedAugmentations = getSortedOrNull(augmentations)
+ if (sortedAugmentations != null) {
+ return sortedAugmentations
+ }
+ sortedAugmentations = new ArrayList(augmentations);
Collections.sort(sortedAugmentations,
[ augSchema1, augSchema2 |
- if (augSchema1.targetPath.path.size() > augSchema2.targetPath.path.size()) {
- return 1;
- } else if (augSchema1.targetPath.path.size() < augSchema2.targetPath.path.size()) {
- return -1;
+ val Iterator<QName> thisIt = augSchema1.targetPath.getPath().iterator();
+ val Iterator<QName> otherIt = augSchema2.getTargetPath().getPath().iterator();
+ while (thisIt.hasNext()) {
+ if (otherIt.hasNext()) {
+ val int comp = thisIt.next().compareTo(otherIt.next());
+ if (comp != 0) {
+ return comp
+ }
+ } else {
+ return 1
+ }
+ }
+ if (otherIt.hasNext()) {
+ return -1
}
- return 0;
+ return 0
]);
return sortedAugmentations;
}
+ private def List<AugmentationSchema> getSortedOrNull(Collection<AugmentationSchema> collection) {
+ val TreeSet<AugmentationSchema> set = new TreeSet()
+ for (e : collection) {
+ if (e instanceof Comparable<?>) {
+ set.add(e)
+ } else {
+ return null
+ }
+ }
+ return new ArrayList(set.toArray)
+ }
+
/**
* Converts whole <b>module</b> to <code>GeneratedType</code> object.
* Firstly is created the module builder object from which is vally
*/
package org.opendaylight.yangtools.yang.parser.builder.api;
-import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
/**
* Interface for builders of 'augment' statement.
*/
void setResolved(boolean resolved);
+ int getOrder();
+
}
*/
package org.opendaylight.yangtools.yang.parser.builder.impl;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.parser.util.ParserUtils;
import org.opendaylight.yangtools.yang.parser.util.YangParseException;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContainerBuilder implements
AugmentationSchemaBuilder {
+ private final int order;
private AugmentationSchemaImpl instance;
private String whenCondition;
private boolean resolved;
private AugmentationSchemaBuilder copyOf;
- public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr) {
+ public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr, int order) {
super(moduleName, line, null);
+ this.order = order;
this.augmentTargetStr = augmentTargetStr;
targetPath = ParserUtils.parseXPathString(augmentTargetStr);
}
return instance;
}
- instance = new AugmentationSchemaImpl(targetPath);
+ instance = new AugmentationSchemaImpl(targetPath, order);
instance.description = description;
instance.reference = reference;
this.targetNodeSchemaPath = path;
}
+ @Override
+ public int getOrder() {
+ return order;
+ }
+
@Override
public int hashCode() {
final int prime = 17;
copyOf = old;
}
- private static final class AugmentationSchemaImpl implements AugmentationSchema, NamespaceRevisionAware {
+ private static final class AugmentationSchemaImpl implements AugmentationSchema, NamespaceRevisionAware,
+ Comparable<AugmentationSchemaImpl> {
+ private final int order;
private SchemaPath targetPath;
private RevisionAwareXPath whenCondition;
private ImmutableSet<DataSchemaNode> childNodes;
private ImmutableList<UnknownSchemaNode> unknownNodes;
private AugmentationSchema copyOf;
- private AugmentationSchemaImpl(final SchemaPath targetPath) {
+ public AugmentationSchemaImpl(final SchemaPath targetPath, final int order) {
this.targetPath = targetPath;
+ this.order = order;
}
public void setCopyOf(final AugmentationSchema build) {
sb.append("]");
return sb.toString();
}
+
+ @Override
+ public int compareTo(AugmentationSchemaImpl o) {
+ Iterator<QName> thisIt = this.targetPath.getPath().iterator();
+ Iterator<QName> otherIt = o.getTargetPath().getPath().iterator();
+ while (thisIt.hasNext()) {
+ if (otherIt.hasNext()) {
+ int comp = thisIt.next().compareTo(otherIt.next());
+ if (comp != 0) {
+ return comp;
+ }
+ } else {
+ return 1;
+ }
+ }
+ if (otherIt.hasNext()) {
+ return -1;
+ }
+ return this.order - o.order;
+ }
}
}
import java.util.Date;
import java.util.Deque;
import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
private final Set<ModuleImport> imports = new HashSet<ModuleImport>();
- private final Set<AugmentationSchema> augments = new HashSet<>();
+ private final Set<AugmentationSchema> augments = new LinkedHashSet<>();
private final List<AugmentationSchemaBuilder> augmentBuilders = new ArrayList<>();
private final List<AugmentationSchemaBuilder> allAugments = new ArrayList<>();
return builder;
}
- public AugmentationSchemaBuilder addAugment(final int line, final String augmentTargetStr) {
- final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, augmentTargetStr);
+ public AugmentationSchemaBuilder addAugment(final int line, final String augmentTargetStr, final int order) {
+ final AugmentationSchemaBuilder builder = new AugmentationSchemaBuilderImpl(name, line, augmentTargetStr, order);
Builder parent = getActualNode();
builder.setParent(parent);
private final DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
private final Stack<Stack<QName>> actualPath = new Stack<>();
+ private int augmentOrder;
private void addNodeToPath(QName name) {
actualPath.peek().push(name);
enterLog(AUGMENT_STR, augmentPath, line);
actualPath.push(new Stack<QName>());
- AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath);
+ AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, augmentOrder++);
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
final String augmentPath = stringFromNode(ctx);
enterLog(AUGMENT_STR, augmentPath, line);
- AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath);
+ AugmentationSchemaBuilder builder = moduleBuilder.addAugment(line, augmentPath, augmentOrder++);
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
*/
package org.opendaylight.yangtools.yang.parser.util;
-import java.net.URI;
import java.util.Comparator;
-import java.util.Date;
-
-import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
public final class Comparators {
- /**
- * Comparator based on alphabetical order of qname's local name.
- */
- public static final QNameComparator QNAME_COMP = new QNameComparator();
-
/**
* Comparator based on alphabetical order of local name of SchemaNode's qname.
*/
private Comparators() {
}
- private static final class QNameComparator implements Comparator<QName> {
- @Override
- public int compare(QName o1, QName o2) {
- return o1.getLocalName().compareTo(o2.getLocalName());
- }
- }
-
private static final class SchemaNodeComparator implements Comparator<SchemaNode> {
@Override
public int compare(SchemaNode o1, SchemaNode o2) {
- QName q1 = o1.getQName();
- QName q2 = o2.getQName();
- int result = q1.getLocalName().compareTo(q2.getLocalName());
- if (result == 0) {
- URI ns1 = q1.getNamespace();
- URI ns2 = q2.getNamespace();
- if (ns1 == null && ns2 == null) {
- Date rev1 = q1.getRevision();
- Date rev2 = q2.getRevision();
-
- if (rev1 == null && rev2 == null) {
- String p1 = q1.getPrefix();
- String p2 = q2.getPrefix();
- if (p1 == null && p2 == null) {
- throw new IllegalArgumentException("Failed to sort nodes: " + o1 + ", " + o2);
- }
- if (p1 == null || p2 == null) {
- if (p1 == null) {
- return -1;
- } else {
- return 1;
- }
- }
- return p1.compareTo(p2);
- }
- if (rev1 == null || rev2 == null) {
- if (rev1 == null) {
- return -1;
- } else {
- return -2;
- }
- }
- return rev1.compareTo(rev2);
- }
- if (ns1 == null || ns2 == null) {
- if (ns1 == null) {
- return -1;
- } else {
- return 1;
- }
- }
- return ns1.toString().compareTo(ns2.toString());
- } else {
- return result;
- }
+ return o1.getQName().compareTo(o2.getQName());
}
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
private static AugmentationSchemaBuilder copyAugment(final AugmentationSchemaBuilder old, final Builder newParent) {
AugmentationSchemaBuilderImpl copy = new AugmentationSchemaBuilderImpl(newParent.getModuleName(),
- newParent.getLine(), old.getTargetPathAsString());
+ newParent.getLine(), old.getTargetPathAsString(), old.getOrder());
copy.setParent(newParent);
copy.setCopyOf(old);
copy.setDescription(old.getDescription());