diff --git a/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java b/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java index d0e037c..968965a 100644 --- a/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java +++ b/src/main/java/org/sadtech/bot/core/domain/BoxAnswer.java @@ -10,6 +10,21 @@ public class BoxAnswer { private Float aLong; private Integer stickerId; + public BoxAnswer() { + + } + + public BoxAnswer(BoxAnswer target) { + if (target != null) { + this.message = target.getMessage(); + this.keyboard = target.getKeyboard(); + this.lat = target.getLat(); + this.aLong = target.getaLong(); + this.stickerId = target.getStickerId(); + } + } + + public String getMessage() { return message; } @@ -50,6 +65,10 @@ public class BoxAnswer { this.stickerId = stickerId; } + public BoxAnswer clone() { + return new BoxAnswer(this); + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -66,4 +85,6 @@ public class BoxAnswer { public int hashCode() { return Objects.hash(message, keyboard, lat, aLong, stickerId); } + + } diff --git a/src/main/java/org/sadtech/bot/core/domain/Comment.java b/src/main/java/org/sadtech/bot/core/domain/Comment.java index d69cd77..40cc584 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Comment.java +++ b/src/main/java/org/sadtech/bot/core/domain/Comment.java @@ -1,10 +1,9 @@ package org.sadtech.bot.core.domain; //@TODO: Дописать класс -public class Comment { +public class Comment extends Content { private Integer postId; - private Person person; private String text; private Integer data; @@ -12,11 +11,4 @@ public class Comment { } - public Person getPerson() { - return person; - } - - public void setPerson(Person person) { - this.person = person; - } } diff --git a/src/main/java/org/sadtech/bot/core/domain/Content.java b/src/main/java/org/sadtech/bot/core/domain/Content.java new file mode 100644 index 0000000..96ae304 --- /dev/null +++ b/src/main/java/org/sadtech/bot/core/domain/Content.java @@ -0,0 +1,37 @@ +package org.sadtech.bot.core.domain; + +import java.util.Objects; + +public abstract class Content { + + private Integer personId; + + public Content() { + + } + + public Content(Content source) { + this.personId = source.getPersonId(); + } + + public Integer getPersonId() { + return personId; + } + + public void setPersonId(Integer personId) { + this.personId = personId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Content)) return false; + Content content = (Content) o; + return Objects.equals(personId, content.personId); + } + + @Override + public int hashCode() { + return Objects.hash(personId); + } +} 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 1952d8e..2e06d0b 100644 --- a/src/main/java/org/sadtech/bot/core/domain/Mail.java +++ b/src/main/java/org/sadtech/bot/core/domain/Mail.java @@ -2,17 +2,23 @@ package org.sadtech.bot.core.domain; import java.util.Objects; -public class Mail { +public class Mail extends Content { private Integer id; private Integer date; - private Integer peerId; - private String body; + private String message; public Mail() { } + public Mail(Mail source) { + super(source); + this.id = source.getId(); + this.date = source.getDate(); + this.message = source.getMessage(); + } + public Integer getId() { return id; } @@ -30,44 +36,31 @@ public class Mail { } - public String getBody() { - return body; + public String getMessage() { + return message; } - public void setBody(String body) { - this.body = body; + public void setMessage(String message) { + this.message = message; } - public Integer getPeerId() { - return peerId; - } - - public void setPeerId(Integer peerId) { - this.peerId = peerId; + public Mail clone() { + return new Mail(this); } @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (!(o instanceof Mail)) return false; + if (!super.equals(o)) return false; Mail mail = (Mail) o; return Objects.equals(id, mail.id) && Objects.equals(date, mail.date) && - Objects.equals(body, mail.body); + Objects.equals(message, mail.message); } @Override public int hashCode() { - return Objects.hash(id, date, body); - } - - @Override - public String toString() { - return "Mail{" + - "id=" + id + - ", date=" + date + - ", peerId=" + peerId + - ", body='" + body + '\'' + - '}'; + return Objects.hash(super.hashCode(), id, date, message); } } diff --git a/src/main/java/org/sadtech/bot/core/insert/InsertWords.java b/src/main/java/org/sadtech/bot/core/insert/InsertWords.java index 6f0ca70..687d9a7 100644 --- a/src/main/java/org/sadtech/bot/core/insert/InsertWords.java +++ b/src/main/java/org/sadtech/bot/core/insert/InsertWords.java @@ -6,12 +6,13 @@ import java.util.regex.Pattern; public class InsertWords { - private String inText; - private String outText; + private InsertWords() { + throw new IllegalStateException(); + } - public void insert(List words) { + public static String insert(String text, List words) { Pattern pattern = Pattern.compile("\\{(\\d+)}"); - Matcher m = pattern.matcher(inText); + Matcher m = pattern.matcher(text); StringBuffer result = new StringBuffer(); while (m.find()) { if (Integer.parseInt(m.group(1)) < words.size()) { @@ -21,15 +22,7 @@ public class InsertWords { } } m.appendTail(result); - outText = result.toString(); - } - - public void setInText(String inText) { - this.inText = inText; - } - - public String getOutText() { - return outText; + return result.toString(); } }