From df9e4dd0c94982530de718eebabbb119c909b31c Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 11 Jan 2020 14:17:51 +0100 Subject: [PATCH] added byte array conversion for message attachment in addition reformatted variable names as per @CyB3RC0nN0R s request --- src/main/java/envoy/data/Message.java | 12 ++++++++-- .../java/envoy/data/MessageAttachment.java | 23 +++++++++++++++++-- .../envoy/event/MessageStatusChangeEvent.java | 20 ++++++++-------- 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/main/java/envoy/data/Message.java b/src/main/java/envoy/data/Message.java index ff0414c..5d7ee33 100644 --- a/src/main/java/envoy/data/Message.java +++ b/src/main/java/envoy/data/Message.java @@ -136,7 +136,7 @@ public class Message implements Serializable { * @return the date at which this message was created * @since Envoy Common v0.2-alpha */ - public Date getDate() { return creationDate; } + public Date getCreationDate() { return creationDate; } /** * @return the date at which the message has been received by the sender @@ -145,7 +145,6 @@ public class Message implements Serializable { public Date getReceivedDate() { return receivedDate; } /** - * * @param receivedDate the date at which the message has been received by the * sender * @since Envoy Common v0.2-alpha @@ -181,4 +180,13 @@ public class Message implements Serializable { * @since Envoy Common v0.2-alpha */ public MessageStatus getStatus() { return status; } + + /** + * @param status the new {@link MessageStatus}, if permitted + * @since Envoy Common v0.2-alpha + */ + public void setStatus(MessageStatus status) { + if (status.ordinal() < this.status.ordinal()) throw new IllegalStateException("This message is moving backwards in time"); + else this.status = status; + } } \ No newline at end of file diff --git a/src/main/java/envoy/data/MessageAttachment.java b/src/main/java/envoy/data/MessageAttachment.java index ee4db64..23a2c2e 100644 --- a/src/main/java/envoy/data/MessageAttachment.java +++ b/src/main/java/envoy/data/MessageAttachment.java @@ -1,7 +1,10 @@ package envoy.data; +import java.io.IOException; import java.io.Serializable; +import envoy.util.SerializationUtils; + /** * This interface should be used for any type supposed to be a {@link Message} * attachment (i.e. images or sound).
@@ -14,11 +17,27 @@ import java.io.Serializable; * @param the type of this message attachment * @since Envoy Common v0.2-alpha */ -public interface MessageAttachment extends Serializable { +public class MessageAttachment implements Serializable { + + private static final long serialVersionUID = 262683855157198013L; + private T value; /** * @return the type implementing this interface * @since Envoy Common v0.2-alpha */ - T get(); + T getValue() { return value; } + + /** + * @return the {@link MessageAttachment} as a byte array + * @throws IOException if the serialization failed + * @since Envoy Common v0.2-alpha + */ + byte[] toByteArray() throws IOException { return SerializationUtils.writeToByteArray(this); } + + /** + * @param value the value to set + * @since Envoy Common v0.2-alpha + */ + public void setValue(T value) { this.value = value; } } diff --git a/src/main/java/envoy/event/MessageStatusChangeEvent.java b/src/main/java/envoy/event/MessageStatusChangeEvent.java index ac532fa..b0aea1f 100644 --- a/src/main/java/envoy/event/MessageStatusChangeEvent.java +++ b/src/main/java/envoy/event/MessageStatusChangeEvent.java @@ -14,22 +14,22 @@ import envoy.data.Message; */ public class MessageStatusChangeEvent implements Event { - private final long messageId; - private final Message.MessageStatus messageStatus; + private final long id; + private final Message.MessageStatus status; private final Date date; /** * Initializes a {@link MessageStatusChangeEvent}. * - * @param messageId the ID of the {@link Message} this event is related to - * @param messageStatus the status of the {@link Message} this event is related + * @param id the ID of the {@link Message} this event is related to + * @param status the status of the {@link Message} this event is related * to * @param date the date at which the MessageStatus change occurred * @since Envoy Common v0.2-alpha */ - public MessageStatusChangeEvent(long messageId, Message.MessageStatus messageStatus, Date date) { - this.messageId = messageId; - this.messageStatus = messageStatus; + public MessageStatusChangeEvent(long id, Message.MessageStatus status, Date date) { + this.id = id; + this.status = status; this.date = date; } @@ -38,16 +38,16 @@ public class MessageStatusChangeEvent implements Event { * @since Envoy Common v0.2-alpha */ @Override - public Message.MessageStatus get() { return messageStatus; } + public Message.MessageStatus get() { return status; } /** * @return the ID of the {@link Message} this event is related to * @since Envoy Common v0.2-alpha */ - public long getMessageId() { return messageId; } + public long getId() { return id; } /** - * @return the date at which the messageStatus change occurred + * @return the date at which the status change occurred * @since Envoy Common v0.2-alpha */ public Date getDate() { return date; }