added byte array conversion for message attachment

in addition reformatted variable names as per @CyB3RC0nN0R s request
This commit is contained in:
delvh 2020-01-11 14:17:51 +01:00
parent 86e358591a
commit 3d0b67d6ba
3 changed files with 41 additions and 14 deletions

View File

@ -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;
}
}

View File

@ -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).<br>
@ -14,11 +17,27 @@ import java.io.Serializable;
* @param <T> the type of this message attachment
* @since Envoy Common v0.2-alpha
*/
public interface MessageAttachment<T> extends Serializable {
public class MessageAttachment<T> 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; }
}

View File

@ -14,22 +14,22 @@ import envoy.data.Message;
*/
public class MessageStatusChangeEvent implements Event<Message.MessageStatus> {
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<Message.MessageStatus> {
* @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; }