Изменил формат даты внутри библиотеки на LocalDateTime

This commit is contained in:
Mark Struchkov 2019-05-17 00:29:24 +03:00
parent f759971840
commit b94ca5827f
5 changed files with 27 additions and 18 deletions

View File

@ -2,13 +2,14 @@ package org.sadtech.bot.core.domain;
import org.sadtech.bot.core.domain.attachment.Attachment; import org.sadtech.bot.core.domain.attachment.Attachment;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
public class Mail extends Content { public class Mail extends Content {
private Integer id; private Integer id;
private Integer date; private LocalDateTime date;
private String message; private String message;
private List<Attachment> attachments; private List<Attachment> attachments;
@ -31,11 +32,11 @@ public class Mail extends Content {
this.id = id; this.id = id;
} }
public Integer getDate() { public LocalDateTime getDate() {
return date; return date;
} }
public void setDate(Integer date) { public void setDate(LocalDateTime date) {
this.date = date; this.date = date;
} }

View File

@ -0,0 +1,5 @@
package org.sadtech.bot.core.exception;
public class MailSendException extends RuntimeException {
}

View File

@ -2,12 +2,13 @@ package org.sadtech.bot.core.repository;
import org.sadtech.bot.core.domain.Mail; import org.sadtech.bot.core.domain.Mail;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
public interface MailRepository { public interface MailRepository {
void add(Mail mail); void add(Mail mail);
List<Mail> getMailByTime(Integer timeFrom, Integer timeTo); List<Mail> getMailByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
} }

View File

@ -4,6 +4,7 @@ import org.sadtech.bot.core.domain.Mail;
import org.sadtech.bot.core.repository.EventRepository; import org.sadtech.bot.core.repository.EventRepository;
import org.sadtech.bot.core.repository.MailRepository; import org.sadtech.bot.core.repository.MailRepository;
import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Queue; import java.util.Queue;
@ -11,33 +12,33 @@ import java.util.concurrent.ConcurrentLinkedQueue;
public class MailRepositoryList implements EventRepository<Mail>, MailRepository { public class MailRepositoryList implements EventRepository<Mail>, MailRepository {
private final List<Mail> messages = new ArrayList<>(); private final List<Mail> mails = new ArrayList<>();
@Override @Override
public void add(Mail mail) { public void add(Mail mail) {
messages.add(mail); mails.add(mail);
} }
@Override @Override
public void cleanAll() { public void cleanAll() {
messages.clear(); mails.clear();
} }
@Override @Override
public Queue<Mail> getEventQueue() { public Queue<Mail> getEventQueue() {
return new ConcurrentLinkedQueue<>(messages); return new ConcurrentLinkedQueue<>(mails);
} }
public List<Mail> getMailByTime(Integer timeFrom, Integer timeTo) { public List<Mail> getMailByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
ArrayList<Mail> mails = new ArrayList<>(); ArrayList<Mail> rezultMails = new ArrayList<>();
for (int i = messages.size() - 1; i >= 0; i--) { for (int i = mails.size() - 1; i >= 0; i--) {
if (messages.get(i).getDate() >= timeFrom && messages.get(i).getDate() < timeTo) { if (!(mails.get(i).getDate().isBefore(timeFrom) || mails.get(i).getDate().isAfter(timeTo))) {
mails.add(messages.get(i)); rezultMails.add(this.mails.get(i));
} else if (messages.get(i).getDate() < timeFrom) { } else if (mails.get(i).getDate().isBefore(timeFrom)) {
break; break;
} }
} }
return mails; return rezultMails;
} }

View File

@ -1,15 +1,16 @@
package org.sadtech.bot.core.service; package org.sadtech.bot.core.service;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
public interface EventService<T> { public interface EventService<T> {
void add(T event); void add(T event);
List<T> getEvent(Integer timeFrom, Integer timeTo); List<T> getEvent(LocalDateTime timeFrom, LocalDateTime timeTo);
List<T> getFirstEventByTime(Integer timeFrom, Integer timeTo); List<T> getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
List<T> getLastEventByTime(Integer timeFrom, Integer timeTo); List<T> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
} }