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 {
private long id;
private final long id;
private String name;
private static final long serialVersionUID = 0L;

View File

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