Revised message related classes
Added GroupMessage class as subclass from Message and adjusted the MessageBuilder
This commit is contained in:
parent
5448ff957d
commit
938a0c5947
56
.classpath
56
.classpath
@ -1,28 +1,28 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="optional" value="true"/>
|
<attribute name="optional" value="true"/>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="test" value="true"/>
|
<attribute name="test" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
File diff suppressed because one or more lines are too long
46
src/main/java/envoy/data/GroupMessage.java
Normal file
46
src/main/java/envoy/data/GroupMessage.java
Normal 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ä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; }
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package envoy.data;
|
package envoy.data;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import envoy.data.Message.MessageStatus;
|
import envoy.data.Message.MessageStatus;
|
||||||
|
|
||||||
@ -97,12 +98,22 @@ public class MessageBuilder {
|
|||||||
* @since Envoy Common v0.2-alpha
|
* @since Envoy Common v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public Message build() {
|
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 (creationDate == null) creationDate = new Date();
|
||||||
if (text == null) text = "";
|
if (text == null) text = "";
|
||||||
if (status == null) status = MessageStatus.WAITING;
|
if (status == null) status = MessageStatus.WAITING;
|
||||||
|
|
||||||
return new Message(id, senderID, recipientID, creationDate, text, attachment, status, forwarded);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user