Made id a mandatory field in MessageBuilder
Added support for IdGenerator in the MessageBuilder constructor.
This commit is contained in:
parent
dd3f920e94
commit
aed8016485
@ -64,20 +64,20 @@ public class Message implements Serializable {
|
|||||||
* this class provides {@code null} checks and default values for all
|
* this class provides {@code null} checks and default values for all
|
||||||
* properties.
|
* properties.
|
||||||
*
|
*
|
||||||
* @param id unique ID
|
* @param id unique ID
|
||||||
* @param senderId the ID of the user who sends the message
|
* @param senderId the ID of the user who sends the message
|
||||||
* @param recipientId the ID of the user who receives the message
|
* @param recipientId the ID of the user who receives the message
|
||||||
* @param date the creation date of the message
|
* @param creationDate the creation date of the message
|
||||||
* @param text the text content of the message
|
* @param text the text content of the message
|
||||||
* @param attachment the attachment of the message, if present
|
* @param attachment the attachment of the message, if present
|
||||||
* @param status the current {@link MessageStatus} of the message
|
* @param status the current {@link MessageStatus} of the message
|
||||||
* @since Envoy Common v0.2-alpha
|
* @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.id = id;
|
||||||
this.senderId = senderId;
|
this.senderId = senderId;
|
||||||
this.recipientId = recipientId;
|
this.recipientId = recipientId;
|
||||||
creationDate = date;
|
this.creationDate = creationDate;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.attachment = attachment;
|
this.attachment = attachment;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
|
@ -21,7 +21,7 @@ public class MessageBuilder {
|
|||||||
|
|
||||||
// Properties with default values
|
// Properties with default values
|
||||||
private long id;
|
private long id;
|
||||||
private Date date;
|
private Date creationDate;
|
||||||
private String text;
|
private String text;
|
||||||
private MessageAttachment<?> attachment;
|
private MessageAttachment<?> attachment;
|
||||||
private Message.MessageStatus status;
|
private Message.MessageStatus status;
|
||||||
@ -32,11 +32,27 @@ public class MessageBuilder {
|
|||||||
*
|
*
|
||||||
* @param senderId the ID of the user who sends the {@link Message}
|
* @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 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
|
* @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.senderId = senderId;
|
||||||
this.recipientId = recipientId;
|
this.recipientId = recipientId;
|
||||||
|
id = messageId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,30 +79,20 @@ public class MessageBuilder {
|
|||||||
*/
|
*/
|
||||||
public Message build() {
|
public Message build() {
|
||||||
// Supplement default values
|
// Supplement default values
|
||||||
if (date == null) date = 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, 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}
|
* @return this {@link MessageBuilder}
|
||||||
* @since Envoy Common v0.2-alpha
|
* @since Envoy Common v0.2-alpha
|
||||||
*/
|
*/
|
||||||
public MessageBuilder setId(long id) {
|
public MessageBuilder setDate(Date creationDate) {
|
||||||
this.id = id;
|
this.creationDate = creationDate;
|
||||||
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;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user