Skip to content
Snippets Groups Projects
Commit 1eed12da authored by Emmanuel Bruno's avatar Emmanuel Bruno
Browse files

moves sort before filter.

parent 923ec403
No related branches found
No related tags found
No related merge requests found
...@@ -64,7 +64,12 @@ public class BiblioModel { ...@@ -64,7 +64,12 @@ public class BiblioModel {
} }
public List<Auteur> getWithFilter(PaginationInfo paginationInfo) { public List<Auteur> getWithFilter(PaginationInfo paginationInfo) {
Stream<Auteur> auteurStream = auteurs.stream(); Stream<Auteur> auteurStream = auteurs.stream()
.sorted(Comparator.comparing(auteur -> switch (valueOf(paginationInfo.getSortKey().toUpperCase())) {
case NOM -> auteur.getNom();
case PRENOM -> auteur.getPrenom();
default -> throw new InvalidParameterException();
}));
if (paginationInfo.getNom() != null) if (paginationInfo.getNom() != null)
auteurStream = auteurStream.filter(auteur -> auteur.getNom().equalsIgnoreCase(paginationInfo.getNom())); auteurStream = auteurStream.filter(auteur -> auteur.getNom().equalsIgnoreCase(paginationInfo.getNom()));
if (paginationInfo.getPrenom() != null) if (paginationInfo.getPrenom() != null)
...@@ -77,11 +82,7 @@ public class BiblioModel { ...@@ -77,11 +82,7 @@ public class BiblioModel {
.limit(paginationInfo.getPageSize()); .limit(paginationInfo.getPageSize());
} }
return auteurStream.sorted(Comparator.comparing(auteur -> switch (valueOf(paginationInfo.getSortKey().toUpperCase())) { return auteurStream.collect(Collectors.toList());
case NOM -> auteur.getNom();
case PRENOM -> auteur.getPrenom();
default -> throw new InvalidParameterException();
})).collect(Collectors.toList());
} }
public void supprimerAuteurs() { public void supprimerAuteurs() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment