import java.lang.invoke.MethodHandles;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
import org.opendaylight.yangtools.concepts.Codec;
import org.opendaylight.yangtools.yang.binding.Identifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
try {
ctor = MethodHandles.publicLookup().unreflectConstructor(getConstructor(keyClass));
} catch (IllegalAccessException e) {
- throw new IllegalArgumentException("Missing construct in class " + keyClass);
+ throw new IllegalArgumentException("Missing constructor in class " + keyClass, e);
}
final MethodHandle inv = MethodHandles.spreadInvoker(ctor.type(), 0);
this.ctorInvoker = inv.asType(inv.type().changeReturnType(Identifier.class));
*
* We do not have to perform a sort if the source collection has less than two
* elements.
-
+ *
* We always perform an ImmutableList.copyOf(), as that will turn into a no-op
* if the source is already immutable. It will also produce optimized implementations
* for empty and singleton collections.
final List<QName> sortedKeys;
if (unsortedKeys.size() > 1) {
final List<QName> tmp = new ArrayList<>(unsortedKeys);
- Collections.sort(tmp, (q1, q2) -> q1.getLocalName().compareToIgnoreCase(q2.getLocalName()));
+ // This is not terribly efficient but gets the job done
+ tmp.sort(Comparator.comparing(qname -> BindingMapping.getPropertyName(qname.getLocalName())));
sortedKeys = tmp;
} else {
sortedKeys = unsortedKeys;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
- final IdentifiableItem identifiableItem = new IdentifiableItem(identifiable, identifier);
+ final IdentifiableItem identifiableItem = IdentifiableItem.of((Class) identifiable, (Identifier) identifier);
return identifiableItem;
}