Skip to content

Instantly share code, notes, and snippets.

@spencerwi
Last active December 22, 2015 21:09
Show Gist options
  • Save spencerwi/6531056 to your computer and use it in GitHub Desktop.
Save spencerwi/6531056 to your computer and use it in GitHub Desktop.
List<PersonEntity> attendees = conference.getAttendees();
Collections.sort(new Comparator<PersonEntity> {
@Override
public int sort(PersonEntity person1, PersonEntity person2) {
Date person1ArrivalDate = person1.getArrivalDate(),
person2ArrivalDate = person2.getArrivalDate();
if (person1ArrivalDate == null) person1ArrivalDate = DEFAULT_ARRIVAL_DATE;
if (person2ArrivalDate == null) person2ArrivalDate = DEFAULT_ARRIVAL_DATE;
int comparisonByArrivalDateResult = person1ArrivalDate.compareTo(person2ArrivalDate);
if (comparisonByArrivalDateResult == 0) {
TicketTier person1TicketTier = person1.getTicketTier(),
person2TicketTier = person2.getTicketTier();
if (person1TicketTier == null) person1TicketTier = DEFAULT_TICKET_TIER;
if (person2TicketTier == null) person2TicketTier = DEFAULT_TICKET_TIER;
int comparisonByTicketTierResult = person1TicketTier.compareTo(person2TicketTier);
if (comparisonByTicketTierResult == 0) {
String person1LastName = person1.getLastName(),
person2LastName = person2.getLastName();
if (person1LastName == null) person1LastName = "";
if (person2LastName == null) person2LastName = "";
return person1LastName.compareTo(person2LastName);
}
return comparisonByTicketTierResult
}
return comparisonByArrivalDateResult;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment