From b94ca5827fb7f95278d661c0584ac8c2acf88d47 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 17 May 2019 00:29:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20=D0=B4=D0=B0=D1=82=D1=8B?= =?UTF-8?q?=20=D0=B2=D0=BD=D1=83=D1=82=D1=80=D0=B8=20=D0=B1=D0=B8=D0=B1?= =?UTF-8?q?=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA=D0=B8=20=D0=BD=D0=B0=20Loc?= =?UTF-8?q?alDateTime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/sadtech/bot/core/domain/Mail.java | 7 +++--- .../bot/core/exception/MailSendException.java | 5 ++++ .../bot/core/repository/MailRepository.java | 3 ++- .../repository/impl/MailRepositoryList.java | 23 ++++++++++--------- .../bot/core/service/EventService.java | 7 +++--- 5 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/sadtech/bot/core/exception/MailSendException.java diff --git a/src/main/java/org/sadtech/bot/core/domain/Mail.java b/src/main/java/org/sadtech/bot/core/domain/Mail.java index 08a0746..9057d34 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Mail.java +++ b/src/main/java/org/sadtech/bot/core/domain/Mail.java @@ -2,13 +2,14 @@ package org.sadtech.bot.core.domain; import org.sadtech.bot.core.domain.attachment.Attachment; +import java.time.LocalDateTime; import java.util.List; import java.util.Objects; public class Mail extends Content { private Integer id; - private Integer date; + private LocalDateTime date; private String message; private List attachments; @@ -31,11 +32,11 @@ public class Mail extends Content { this.id = id; } - public Integer getDate() { + public LocalDateTime getDate() { return date; } - public void setDate(Integer date) { + public void setDate(LocalDateTime date) { this.date = date; } diff --git a/src/main/java/org/sadtech/bot/core/exception/MailSendException.java b/src/main/java/org/sadtech/bot/core/exception/MailSendException.java new file mode 100644 index 0000000..f627380 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/exception/MailSendException.java @@ -0,0 +1,5 @@ +package org.sadtech.bot.core.exception; + +public class MailSendException extends RuntimeException { + +} diff --git a/src/main/java/org/sadtech/bot/core/repository/MailRepository.java b/src/main/java/org/sadtech/bot/core/repository/MailRepository.java index 0ae005f..697cb6f 100644 --- a/src/main/java/org/sadtech/bot/core/repository/MailRepository.java +++ b/src/main/java/org/sadtech/bot/core/repository/MailRepository.java @@ -2,12 +2,13 @@ package org.sadtech.bot.core.repository; import org.sadtech.bot.core.domain.Mail; +import java.time.LocalDateTime; import java.util.List; public interface MailRepository { void add(Mail mail); - List getMailByTime(Integer timeFrom, Integer timeTo); + List getMailByTime(LocalDateTime timeFrom, LocalDateTime timeTo); } diff --git a/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java b/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java index 6012f54..4231cb1 100644 --- a/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java +++ b/src/main/java/org/sadtech/bot/core/repository/impl/MailRepositoryList.java @@ -4,6 +4,7 @@ import org.sadtech.bot.core.domain.Mail; import org.sadtech.bot.core.repository.EventRepository; import org.sadtech.bot.core.repository.MailRepository; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Queue; @@ -11,33 +12,33 @@ import java.util.concurrent.ConcurrentLinkedQueue; public class MailRepositoryList implements EventRepository, MailRepository { - private final List messages = new ArrayList<>(); + private final List mails = new ArrayList<>(); @Override public void add(Mail mail) { - messages.add(mail); + mails.add(mail); } @Override public void cleanAll() { - messages.clear(); + mails.clear(); } @Override public Queue getEventQueue() { - return new ConcurrentLinkedQueue<>(messages); + return new ConcurrentLinkedQueue<>(mails); } - public List getMailByTime(Integer timeFrom, Integer timeTo) { - ArrayList mails = new ArrayList<>(); - for (int i = messages.size() - 1; i >= 0; i--) { - if (messages.get(i).getDate() >= timeFrom && messages.get(i).getDate() < timeTo) { - mails.add(messages.get(i)); - } else if (messages.get(i).getDate() < timeFrom) { + public List getMailByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + ArrayList rezultMails = new ArrayList<>(); + for (int i = mails.size() - 1; i >= 0; i--) { + if (!(mails.get(i).getDate().isBefore(timeFrom) || mails.get(i).getDate().isAfter(timeTo))) { + rezultMails.add(this.mails.get(i)); + } else if (mails.get(i).getDate().isBefore(timeFrom)) { break; } } - return mails; + return rezultMails; } diff --git a/src/main/java/org/sadtech/bot/core/service/EventService.java b/src/main/java/org/sadtech/bot/core/service/EventService.java index b62c1a9..fcb7a1e 100644 --- a/src/main/java/org/sadtech/bot/core/service/EventService.java +++ b/src/main/java/org/sadtech/bot/core/service/EventService.java @@ -1,15 +1,16 @@ package org.sadtech.bot.core.service; +import java.time.LocalDateTime; import java.util.List; public interface EventService { void add(T event); - List getEvent(Integer timeFrom, Integer timeTo); + List getEvent(LocalDateTime timeFrom, LocalDateTime timeTo); - List getFirstEventByTime(Integer timeFrom, Integer timeTo); + List getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo); - List getLastEventByTime(Integer timeFrom, Integer timeTo); + List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo); }