package com.rockwellcollins.atc.resolute.analysis.execution;

import java.util.Comparator;

import org.osate.aadl2.NamedElement;

import com.rockwellcollins.atc.resolute.analysis.values.NamedElementValue;

public class NamedElementComparator implements Comparator<NamedElement> {
    @Override
    public int compare(NamedElement arg0, NamedElement arg1) {
        if (arg0 == arg1) {
            return 0;
        }
        
        String text0 = new NamedElementValue(arg0).toString();
        String text1 = new NamedElementValue(arg1).toString();
        int r = text0.compareToIgnoreCase(text1);
        if (r != 0) {
            return r;
        }
        
        r = Integer.compare(arg0.hashCode(), arg1.hashCode());
        if (r == 0) {
            throw new IllegalArgumentException("Unable to order distinct objects via hashcode");
        }
        return r;
    }
}

package com.rockwellcollins.atc.resolute.analysis.execution;

import java.util.Comparator;

import org.osate.aadl2.NamedElement;

public class NamedElementComparator implements Comparator<NamedElement> {
    @Override
    public int compare(NamedElement arg0, NamedElement arg1) {
        if (arg0 == arg1) {
            return 0;
        }
        
        int r = arg0.getName().compareToIgnoreCase(arg1.getName());
        if (r != 0) {
            return r;
        }
        
        r = Integer.compare(arg0.hashCode(), arg1.hashCode());
        if (r == 0) {
            throw new IllegalArgumentException("Unable to order distinct objects via hashcode");
        }
        return r;
    }
}

--- 
+++ 
@@ -3,6 +3,8 @@
 import java.util.Comparator;
 
 import org.osate.aadl2.NamedElement;
+
+import com.rockwellcollins.atc.resolute.analysis.values.NamedElementValue;
 
 public class NamedElementComparator implements Comparator<NamedElement> {
     @Override
@@ -11,7 +13,9 @@
             return 0;
         }
         
-        int r = arg0.getName().compareToIgnoreCase(arg1.getName());
+        String text0 = new NamedElementValue(arg0).toString();
+        String text1 = new NamedElementValue(arg1).toString();
+        int r = text0.compareToIgnoreCase(text1);
         if (r != 0) {
             return r;
         }
Order based on name used in assurance case
