Рефакторинг

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 Float aLong;
private Integer stickerId; 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() { public String getMessage() {
return message; return message;
} }
@ -50,6 +65,10 @@ public class BoxAnswer {
this.stickerId = stickerId; this.stickerId = stickerId;
} }
public BoxAnswer clone() {
return new BoxAnswer(this);
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
@ -66,4 +85,6 @@ public class BoxAnswer {
public int hashCode() { public int hashCode() {
return Objects.hash(message, keyboard, lat, aLong, stickerId); return Objects.hash(message, keyboard, lat, aLong, stickerId);
} }
} }

View File

@ -1,10 +1,9 @@
package org.sadtech.bot.core.domain; package org.sadtech.bot.core.domain;
//@TODO: Дописать класс //@TODO: Дописать класс
public class Comment { public class Comment extends Content {
private Integer postId; private Integer postId;
private Person person;
private String text; private String text;
private Integer data; 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; import java.util.Objects;
public class Mail { public class Mail extends Content {
private Integer id; private Integer id;
private Integer date; private Integer date;
private Integer peerId; private String message;
private String body;
public Mail() { public Mail() {
} }
public Mail(Mail source) {
super(source);
this.id = source.getId();
this.date = source.getDate();
this.message = source.getMessage();
}
public Integer getId() { public Integer getId() {
return id; return id;
} }
@ -30,44 +36,31 @@ public class Mail {
} }
public String getBody() { public String getMessage() {
return body; return message;
} }
public void setBody(String body) { public void setMessage(String message) {
this.body = body; this.message = message;
} }
public Integer getPeerId() { public Mail clone() {
return peerId; return new Mail(this);
}
public void setPeerId(Integer peerId) {
this.peerId = peerId;
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; 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; Mail mail = (Mail) o;
return Objects.equals(id, mail.id) && return Objects.equals(id, mail.id) &&
Objects.equals(date, mail.date) && Objects.equals(date, mail.date) &&
Objects.equals(body, mail.body); Objects.equals(message, mail.message);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(id, date, body); return Objects.hash(super.hashCode(), id, date, message);
}
@Override
public String toString() {
return "Mail{" +
"id=" + id +
", date=" + date +
", peerId=" + peerId +
", body='" + body + '\'' +
'}';
} }
} }

View File

@ -6,12 +6,13 @@ import java.util.regex.Pattern;
public class InsertWords { public class InsertWords {
private String inText; private InsertWords() {
private String outText; throw new IllegalStateException();
}
public void insert(List<String> words) { public static String insert(String text, List<String> words) {
Pattern pattern = Pattern.compile("\\{(\\d+)}"); Pattern pattern = Pattern.compile("\\{(\\d+)}");
Matcher m = pattern.matcher(inText); Matcher m = pattern.matcher(text);
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
while (m.find()) { while (m.find()) {
if (Integer.parseInt(m.group(1)) < words.size()) { if (Integer.parseInt(m.group(1)) < words.size()) {
@ -21,15 +22,7 @@ public class InsertWords {
} }
} }
m.appendTail(result); m.appendTail(result);
outText = result.toString(); return result.toString();
}
public void setInText(String inText) {
this.inText = inText;
}
public String getOutText() {
return outText;
} }
} }