Last active
November 13, 2018 11:33
-
-
Save hudsonmendes/21532b76c21f964838ef123621ac2a3e to your computer and use it in GitHub Desktop.
Sort using an implementation of Comparator<>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SearchResultComparator implements Comparator<SearchResult> { | |
@Override | |
public int compare(final SearchResult o1, final SearchResult o2) { | |
// TODO: address null references for getName() | |
return o1.getName().compareToIgnoreCase(o2.getName()); | |
} | |
} | |
public class OrderingServiceImpl implements OrderingService { | |
@Override | |
public List<SearchResult> orderWithComparator(List<SearchResult>) { | |
return results | |
.stream() | |
.distinct() | |
.sorted(new SearchResultComparator()) | |
.collect(toList()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment