class MappingGroupComparator implements Comparator<SnomedConcept> {

    public int compare(final SnomedConcept o1, final SnomedConcept o2) {
        if (o1 == o2) return 0;
        if (o1 != null) {
            if (o2 == null) return 1;
                // sort shorter mapping groups first
            else if (o1.mappingGroup.length() != o2.mappingGroup.length()) {
                return ((Integer)o1.mappingGroup.length()).compareTo(o2.mappingGroup.length());
            }
            else return o1.mappingGroup.compareTo(o2.mappingGroup);
        }
        return -1;
    }

}