Skip to content

Instantly share code, notes, and snippets.

@hudsonmendes
Last active November 13, 2018 11:33
Show Gist options
  • Save hudsonmendes/21532b76c21f964838ef123621ac2a3e to your computer and use it in GitHub Desktop.
Save hudsonmendes/21532b76c21f964838ef123621ac2a3e to your computer and use it in GitHub Desktop.
Sort using an implementation of Comparator<>
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