--- /dev/null
+/*
+ * 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.sal.java.api.generator;
+
+import java.util.Comparator;
+import org.opendaylight.yangtools.sal.binding.model.api.TypeMember;
+
+/**
+ * Alphabetically type member {@link Comparator} which provides sorting by name for type members
+ * (variables and methods) in generated class.
+ *
+ * @param <T>
+ */
+public class AlphabeticallyTypeMemberComparator<T extends TypeMember> implements Comparator<T>{
+
+ @Override
+ public int compare(T member1, T member2) {
+ return member1.getName().compareTo(member2.getName());
+ }
+}
*/
package org.opendaylight.yangtools.sal.java.api.generator
-import java.util.Arrays;
+import com.google.common.collect.ImmutableSortedSet
+import com.google.common.collect.Range
+import java.util.ArrayList
+import java.util.Arrays
+import java.util.Collection
+import java.util.Collections
+import java.util.HashMap
+import java.util.HashSet
import java.util.LinkedHashSet
import java.util.List
import java.util.Map
import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl
import org.opendaylight.yangtools.binding.generator.util.Types
import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl
+import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature
import org.opendaylight.yangtools.sal.binding.model.api.Type
import org.opendaylight.yangtools.yang.binding.Augmentable
-import static org.opendaylight.yangtools.binding.generator.util.Types.*
-import java.util.HashMap
-import java.util.Collections
import org.opendaylight.yangtools.yang.binding.DataObject
-import java.util.ArrayList
-import java.util.HashSet
-import java.util.Collection
import org.opendaylight.yangtools.yang.binding.Identifiable
-import com.google.common.collect.Range
-import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType
/**
* Template for generating JAVA builder classes.
*/
val Set<GeneratedProperty> properties
+ private static val METHOD_COMPARATOR = new AlphabeticallyTypeMemberComparator<MethodSignature>();
+
/**
* Constructs new instance of this class.
* @throws IllegalArgumentException if <code>genType</code> equals <code>null</code>
* @returns set of method signature instances
*/
def private Set<MethodSignature> createMethods() {
- val Set<MethodSignature> methods = new LinkedHashSet
+ val Set<MethodSignature> methods = new LinkedHashSet();
methods.addAll(type.methodDefinitions)
collectImplementedMethods(methods, type.implements)
- return methods
+ val Set<MethodSignature> sortedMethods = ImmutableSortedSet.orderedBy(METHOD_COMPARATOR).addAll(methods).build()
+
+ return sortedMethods
}
/**
* Adds to the <code>methods</code> set all the methods of the <code>implementedIfcs</code>
- * and recursivelly their implemented interfaces.
+ * and recursively their implemented interfaces.
*
* @param methods set of method signatures
* @param implementedIfcs list of implemented interfaces
throw new IllegalArgumentException("Method, method name, method return type reference cannot be NULL or empty!")
}
var prefix = "get";
- if(BOOLEAN.equals(method.returnType)) {
+ if(Types.BOOLEAN.equals(method.returnType)) {
prefix = "is";
}
if (method.name.startsWith(prefix)) {