Revised toString method in Group and changed id to final in Contact

This commit is contained in:
DieGurke 2020-03-24 21:11:16 +01:00
parent 7a795e320b
commit 28fb3e9d25
2 changed files with 7 additions and 8 deletions

View File

@ -15,7 +15,7 @@ import java.io.Serializable;
*/ */
public abstract class Contact implements Serializable { public abstract class Contact implements Serializable {
private long id; private final long id;
private String name; private String name;
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;

View File

@ -2,6 +2,7 @@ package envoy.data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.StringJoiner;
/** /**
* Project: <strong>envoy-common</strong><br> * Project: <strong>envoy-common</strong><br>
@ -57,12 +58,10 @@ public class Group extends Contact {
*/ */
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); var joiner = new StringJoiner(",", "Group[id=", "]");
sb.append("Group[id=" + getId() + ",name=" + getName() + ",memberIDs=["); joiner.add("id=" + getId());
memberIDs.forEach(id -> { sb.append(id); sb.append(", "); }); joiner.add("name=" + getName());
// deleting the final ", " joiner.add("memberIDs=" + getMemberIDs());
sb.delete(sb.length() - 2, sb.length()); return joiner.toString();
sb.append("]]");
return sb.toString();
} }
} }