From edd38beb67a91d616cb5640072c3b4320c4aba48 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Sun, 23 Dec 2018 02:22:06 +0400 Subject: [PATCH] Add function getNextDeadline() --- src/main/java/ru/ulstu/grant/model/Grant.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 092317b..1bd7ff9 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -10,11 +10,7 @@ import ru.ulstu.user.model.User; import javax.persistence.*; import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; @Entity public class Grant extends BaseEntity { @@ -103,4 +99,13 @@ public class Grant extends BaseEntity { public void setProject(Project project) { this.project = project; } + + public Optional getNextDeadline() { + return deadlines + .stream() + .filter(deadline -> deadline.getDate() != null) + .sorted(Comparator.comparing(Deadline::getDate)) + .filter(d -> d.getDate().after(new Date())) + .findFirst(); + } }