From 938a0c5947dafd73566f2709f4b12d191fb0f87e Mon Sep 17 00:00:00 2001
From: DieGurke <55625494+DieGurke@users.noreply.github.com>
Date: Thu, 26 Mar 2020 18:55:48 +0100
Subject: [PATCH] Revised message related classes
Added GroupMessage class as subclass from Message and adjusted the
MessageBuilder
---
.classpath | 56 ++++++++++----------
.settings/org.eclipse.jdt.ui.prefs | 2 +-
src/main/java/envoy/data/GroupMessage.java | 46 ++++++++++++++++
src/main/java/envoy/data/MessageBuilder.java | 17 ++++--
4 files changed, 89 insertions(+), 32 deletions(-)
create mode 100644 src/main/java/envoy/data/GroupMessage.java
diff --git a/.classpath b/.classpath
index 7d2ffae..3603647 100644
--- a/.classpath
+++ b/.classpath
@@ -1,28 +1,28 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs
index f2ac36a..1a7acd7 100644
--- a/.settings/org.eclipse.jdt.ui.prefs
+++ b/.settings/org.eclipse.jdt.ui.prefs
@@ -1,3 +1,3 @@
eclipse.preferences.version=1
org.eclipse.jdt.ui.javadoc=true
-org.eclipse.jdt.ui.text.custom_code_templates=/**\n * @return the ${bare_field_name}\n * @since Envoy Common v0.1-beta\n *//**\n * @param ${param} the ${bare_field_name} to set\n * @since Envoy Common v0.1-beta\n *//**\n * @since Envoy Common v0.1-beta\n *//**\n * Project\: <strong>${project_name}</strong><br>\n * File\: <strong>${file_name}</strong><br>\n * Created\: <strong>${date}</strong><br>\n * \n * @author ${user}\n * @since Envoy Common v0.1-beta\n *//**\n * ${tags}\n * @since Envoy Common v0.1-beta\n *//**\n * @author ${user}\n *\n * ${tags}\n * @since Envoy Common v0.1-beta\n *//**\n * {@inheritDoc}\n *//**\n * ${tags}\n * ${see_to_target}\n * @since Envoy Common v0.1-beta\n */${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}\n\n\n\n${exception_var}.printStackTrace();${body_statement}${body_statement}return ${field};${field} \= ${param};
+org.eclipse.jdt.ui.text.custom_code_templates=/**\r\n * @return the ${bare_field_name}\r\n * @since Envoy Common v0.1-beta\r\n *//**\r\n * @param ${param} the ${bare_field_name} to set\r\n * @since Envoy Common v0.1-beta\r\n *//**\r\n * ${tags}\r\n * @since Envoy Common v0.1-beta\r\n *//**\r\n * Project\: <strong>${project_name}</strong><br>\r\n * File\: <strong>${file_name}</strong><br>\r\n * Created\: <strong>${date}</strong><br>\r\n * \r\n * @author ${user}\r\n * @since Envoy Common v0.1-beta\r\n *//**\r\n * ${tags}\r\n * @since Envoy Common v0.1-beta\r\n *//**\r\n * @author ${user}\r\n *\r\n * ${tags}\r\n * @since Envoy Common v0.1-beta\r\n *//**\r\n * {@inheritDoc}\r\n *//**\r\n * ${tags}\r\n * ${see_to_target}\r\n * @since Envoy Common v0.1-beta\r\n */${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}\r\n\r\n\r\n\r\n${exception_var}.printStackTrace();${body_statement}${body_statement}return ${field};${field} \= ${param};
diff --git a/src/main/java/envoy/data/GroupMessage.java b/src/main/java/envoy/data/GroupMessage.java
new file mode 100644
index 0000000..ec2e773
--- /dev/null
+++ b/src/main/java/envoy/data/GroupMessage.java
@@ -0,0 +1,46 @@
+package envoy.data;
+
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * Project: envoy-common
+ * File: GroupMessage.java
+ * Created: 26.03.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Common v0.1-beta
+ */
+public final class GroupMessage extends Message {
+
+ private final Map memberStatuses;
+
+ private static final long serialVersionUID = 0L;
+
+ /**
+ * Initializes a {@link GroupMessage} with values for all of its properties. The
+ * use
+ * of this constructor is only intended for the {@link MessageBuilder} class, as
+ * this class provides {@code null} checks and default values for all
+ * properties.
+ *
+ * @param id unique ID
+ * @param senderID the ID of the user who sends the message
+ * @param recipientID the ID of the user who receives the message
+ * @param creationDate the creation date of the message
+ * @param text the text content of the message
+ * @param attachment the attachment of the message, if present
+ * @param status the current {@link MessageStatus} of the message
+ * @param forwarded whether this message was forwarded
+ * @param memberStatuses a map of all members and their status according to this
+ * {@link GroupMessage}
+ * @since Envoy Common v0.1-beta
+ */
+ GroupMessage(long id, long senderID, long groupID, Date creationDate, String text, MessageAttachment> attachment, MessageStatus status,
+ boolean forwarded, Map memberStatuses) {
+ super(id, senderID, groupID, creationDate, text, attachment, status, forwarded);
+ this.memberStatuses = memberStatuses;
+ }
+
+ public Map getMemberStatuses() { return memberStatuses; }
+}
diff --git a/src/main/java/envoy/data/MessageBuilder.java b/src/main/java/envoy/data/MessageBuilder.java
index c23f663..34dc3f1 100644
--- a/src/main/java/envoy/data/MessageBuilder.java
+++ b/src/main/java/envoy/data/MessageBuilder.java
@@ -1,6 +1,7 @@
package envoy.data;
import java.util.Date;
+import java.util.HashMap;
import envoy.data.Message.MessageStatus;
@@ -97,12 +98,22 @@ public class MessageBuilder {
* @since Envoy Common v0.2-alpha
*/
public Message build() {
- // Supplement default values
+ supplyDefaults();
+ return new Message(id, senderID, recipientID, creationDate, text, attachment, status, forwarded);
+ }
+
+ public GroupMessage buildGroupMessage(Group group) {
+ if (group == null) throw new NullPointerException();
+ supplyDefaults();
+ var memberStatuses = new HashMap();
+ group.getMemberIDs().forEach(id -> memberStatuses.put(id, MessageStatus.WAITING));
+ return new GroupMessage(id, senderID, recipientID, creationDate, text, attachment, status, forwarded, memberStatuses);
+ }
+
+ private void supplyDefaults() {
if (creationDate == null) creationDate = new Date();
if (text == null) text = "";
if (status == null) status = MessageStatus.WAITING;
-
- return new Message(id, senderID, recipientID, creationDate, text, attachment, status, forwarded);
}
/**