package com.thebluealliance.androidclient.comparators;

import com.thebluealliance.androidclient.models.Event;
import com.thebluealliance.androidclient.types.EventType;

import java.util.Comparator;

public class EventSortByTypeAndNameComparator implements Comparator<Event> {
    @Override
    public int compare(Event event, Event event2) {
        // Preseason < regional < district < district_cmp < cmp_division < cmp_finals < offseason
        if (event.getEventTypeEnum() == event2.getEventTypeEnum()) {
            int districtSort = event.getDistrictKey().compareTo(event2.getDistrictKey());
            int nameSort = event.getShortName().compareTo(event2.getShortName());
            if (districtSort == 0) {
                return nameSort;
            } else {
                return districtSort;
            }
        } else {
            EventType type1 = event.getEventTypeEnum();
            EventType type2 = event2.getEventTypeEnum();
            int typeCompare = type1.getSortOrder() - type2.getSortOrder();
            if (typeCompare == 0 && event.getEventTypeEnum() == EventType.DISTRICT) {
                return event.getDistrictKey().compareTo(event2.getDistrictKey());
            } else {
                return typeCompare;
            }
        }
    }

    @Override
    public boolean equals(Object o) {
        return false;
    }
}

@@ -538,82 +538,327 @@
 t = 
-event.getDistrictKey().compareTo(event2.getDistrictKey());%0A            int
+0;%0A            if (event.getDistrictKey() != null && event2.getDistrictKey() != null) %7B%0A                districtSort = event.getDistrictKey().compareTo(event2.getDistrictKey());%0A            %7D%0A%0A            int nameSort = 0;%0A            if (event.getShortName() != null && event2.getShortName() != null) %7B%0A               
  nam
@@ -916,24 +916,39 @@
 ortName());%0A
+            %7D%0A%0A
             
@@ -1314,16 +1314,36 @@
 are == 0
+%0A                   
  && even
@@ -1384,16 +1384,125 @@
 DISTRICT
+%0A                    && event.getDistrictKey() != null%0A                    && event2.getDistrictKey() != null
 ) %7B%0A    

Improve null safety in EventSortByTypeAndNameComparator