final class SponsorComparator implements Comparator<Sponsor> {
@Override public int compare(Sponsor lhs, Sponsor rhs) {
SponsorLevel lhsMin = Collections.min(lhs.getSponsorLevels());
SponsorLevel rhsMin = Collections.min(rhs.getSponsorLevels());
int result = ComparisonChain.start() //
.compare(lhsMin, rhsMin) //
.result();
if (result == 0) {
return ComparisonChain.start() //
.compare(lhs.getName(), rhs.getName()) //
.result();
}
return result;
}
}
This sorts sponsors by sponsor level sort order, where lowest sort order is displayed at the top of the list (so a Platinum sponsor is displayed higher in the list than a Bronze sponsor, for example).
We could remove the SponsorLevel object entirely from the mobile apps if it was the responsibility of the API to return a sorted array instead of the mobile app's responsibility.
Here is a class from the Android app:
This sorts sponsors by sponsor level sort order, where lowest sort order is displayed at the top of the list (so a Platinum sponsor is displayed higher in the list than a Bronze sponsor, for example).
We could remove the
SponsorLevel
object entirely from the mobile apps if it was the responsibility of the API to return a sorted array instead of the mobile app's responsibility.What do you think?