From 28fb3e9d25a5a05371bfc8d9d7a656ade1f6aaa0 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Tue, 24 Mar 2020 21:11:16 +0100 Subject: [PATCH] Revised toString method in Group and changed id to final in Contact --- src/main/java/envoy/data/Contact.java | 2 +- src/main/java/envoy/data/Group.java | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/envoy/data/Contact.java b/src/main/java/envoy/data/Contact.java index 3e830f1..96b703e 100644 --- a/src/main/java/envoy/data/Contact.java +++ b/src/main/java/envoy/data/Contact.java @@ -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; diff --git a/src/main/java/envoy/data/Group.java b/src/main/java/envoy/data/Group.java index 7de0f20..cab866f 100644 --- a/src/main/java/envoy/data/Group.java +++ b/src/main/java/envoy/data/Group.java @@ -2,6 +2,7 @@ package envoy.data; import java.util.ArrayList; import java.util.List; +import java.util.StringJoiner; /** * Project: envoy-common
@@ -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(); } }