diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index dea58cf..85702ca 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -64,20 +64,20 @@ public class Message implements Serializable { * 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 date 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 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 * @since Envoy Common v0.2-alpha */ - Message(long id, long senderId, long recipientId, Date date, String text, MessageAttachment attachment, MessageStatus status) { + Message(long id, long senderId, long recipientId, Date creationDate, String text, MessageAttachment attachment, MessageStatus status) { this.id = id; this.senderId = senderId; this.recipientId = recipientId; - creationDate = date; + this.creationDate = creationDate; this.text = text; this.attachment = attachment; this.status = status; diff --git a/src/main/java/envoy/data/MessageBuilder.java b/src/main/java/envoy/data/MessageBuilder.java index 43e929e..5166352 100644 --- a/src/main/java/envoy/data/MessageBuilder.java +++ b/src/main/java/envoy/data/MessageBuilder.java @@ -10,7 +10,7 @@ import envoy.data.Message.MessageStatus; * Project: envoy-common
* File: MessageBuilder.java
* Created: 31.12.2019
- * + * * @author Kai S. K. Engelbart * @since Envoy Common v0.2-alpha */ @@ -21,7 +21,7 @@ public class MessageBuilder { // Properties with default values private long id; - private Date date; + private Date creationDate; private String text; private MessageAttachment attachment; private Message.MessageStatus status; @@ -32,11 +32,27 @@ public class MessageBuilder { * * @param senderId the ID of the user who sends the {@link Message} * @param recipientId the ID of the user who received the {@link Message} + * @param idGenerator the ID generator used to generate a unique {@link Message} + * id * @since Envoy Common v0.2-alpha */ - public MessageBuilder(long senderId, long recipientId) { + public MessageBuilder(long senderId, long recipientId, IdGenerator idGenerator) { + this(senderId, recipientId, idGenerator.next()); + } + + /** + * Creates an instance of {@link MessageBuilder} with all mandatory values + * without defaults for the {@link Message} class. + * + * @param senderId the ID of the user who sends the {@link Message} + * @param recipientId the ID of the user who received the {@link Message} + * @param messageId the ID of the {@link Message} + * @since Envoy Common v0.2-alpha + */ + public MessageBuilder(long senderId, long recipientId, long messageId) { this.senderId = senderId; this.recipientId = recipientId; + id = messageId; } /** @@ -57,36 +73,26 @@ public class MessageBuilder { * {@code MessageStatus.WAITING} * * - * + * * @return a new instance of {@link Message} * @since Envoy Common v0.2-alpha */ public Message build() { // Supplement default values - if (date == null) date = new Date(); + if (creationDate == null) creationDate = new Date(); if (text == null) text = ""; if (status == null) status = MessageStatus.WAITING; - return new Message(id, senderId, recipientId, date, text, attachment, status); + return new Message(id, senderId, recipientId, creationDate, text, attachment, status); } /** - * @param id the unique ID of the {@link Message} to create + * @param creationDate the creation date of the {@link Message} to create * @return this {@link MessageBuilder} * @since Envoy Common v0.2-alpha */ - public MessageBuilder setId(long id) { - this.id = id; - return this; - } - - /** - * @param date the creation date of the {@link Message} to create - * @return this {@link MessageBuilder} - * @since Envoy Common v0.2-alpha - */ - public MessageBuilder setDate(Date date) { - this.date = date; + public MessageBuilder setDate(Date creationDate) { + this.creationDate = creationDate; return this; }