Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects

In-memory sorting of roles returned by RoleService#search

Merged Jean Claude Correale requested to merge feature/fix-roles-search-sorting into develop
@@ -248,19 +248,18 @@ public class RoleServiceImpl implements RoleService {
private static Optional<Comparator<RoleDTO>> toComparator(PropertyDescriptor property, Sort.Direction direction) {
if (Comparable.class.isAssignableFrom(property.getPropertyType())) {
return buildComparator(property, direction);
return Optional.of(buildComparator(property, direction));
} else {
return Optional.empty();
}
}
private static Optional<Comparator<RoleDTO>> buildComparator(
PropertyDescriptor property, Sort.Direction direction) {
private static Comparator<RoleDTO> buildComparator(PropertyDescriptor property, Sort.Direction direction) {
var comparator = Comparator.<RoleDTO, Comparable<Object>>comparing(o -> get(o, property));
if (direction == Sort.Direction.DESC) {
comparator = comparator.reversed();
}
return Optional.of(comparator);
return comparator;
}
private static Comparator<RoleDTO> unsortedComparator() {
Loading