Рефакторинг

This commit is contained in:
Mark Struchkov 2019-05-08 12:37:21 +03:00
parent 028ab802af
commit 44d6e3321f
5 changed files with 84 additions and 48 deletions

View File

@ -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);
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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<String> words) {
public static String insert(String text, List<String> 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();
}
}