From fbaaac3a91e5486e418786c577dea2bd3ca5110b Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 18 Dec 2018 23:02:48 +0400 Subject: [PATCH] sort filtered papers --- .../ru/ulstu/paper/service/PaperService.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 88ea8c9..bfb70c3 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -47,15 +47,7 @@ public class PaperService { } public List findAll() { - return paperRepository.findAll().stream().sorted((paper1, paper2) -> { - int statusCompareResult = - Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper1.getStatus())) - .compareTo(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper2.getStatus())); - if (statusCompareResult != 0) { - return statusCompareResult; - } - return paper1.getTitle().compareTo(paper2.getTitle()); - }).collect(Collectors.toList()); + return sortPapers(paperRepository.findAll()); } public List findAllDto() { @@ -145,9 +137,21 @@ public class PaperService { } public List filter(PaperFilterDto filterDto) { - return convert(paperRepository.filter( + return convert(sortPapers(paperRepository.filter( filterDto.getFilterAuthorId() == null ? null : userService.findById(filterDto.getFilterAuthorId()), - filterDto.getYear()), PaperDto::new); + filterDto.getYear())), PaperDto::new); + } + + private List sortPapers(List papers) { + return papers.stream().sorted((paper1, paper2) -> { + int statusCompareResult = + Integer.valueOf(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper1.getStatus())) + .compareTo(Arrays.asList(Paper.PaperStatus.values()).indexOf(paper2.getStatus())); + if (statusCompareResult != 0) { + return statusCompareResult; + } + return paper1.getTitle().compareTo(paper2.getTitle()); + }).collect(Collectors.toList()); } public PaperDto findPaper(int id) {