Revised message related classes

Added GroupMessage class as subclass from Message and adjusted the
MessageBuilder
This commit is contained in:
DieGurke 2020-03-26 18:55:48 +01:00
parent 4a26ef8c4a
commit a3e7034713
4 changed files with 89 additions and 32 deletions

View File

@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,46 @@
package envoy.data;
import java.util.Date;
import java.util.Map;
/**
* Project: <strong>envoy-common</strong><br>
* File: <strong>GroupMessage.java</strong><br>
* Created: <strong>26.03.2020</strong><br>
*
* @author Maximilian K&auml;fer
* @since Envoy Common v0.1-beta
*/
public final class GroupMessage extends Message {
private final Map<Long, MessageStatus> 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<Long, MessageStatus> memberStatuses) {
super(id, senderID, groupID, creationDate, text, attachment, status, forwarded);
this.memberStatuses = memberStatuses;
}
public Map<Long, MessageStatus> getMemberStatuses() { return memberStatuses; }
}

View File

@ -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<Long, Message.MessageStatus>();
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);
}
/**