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 1d42f57352
commit df9e4dd0c9
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 * @return the date at which this message was created
* @since Envoy Common v0.2-alpha * @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 * @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; } public Date getReceivedDate() { return receivedDate; }
/** /**
*
* @param receivedDate the date at which the message has been received by the * @param receivedDate the date at which the message has been received by the
* sender * sender
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
@ -181,4 +180,13 @@ public class Message implements Serializable {
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public MessageStatus getStatus() { return status; } 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; package envoy.data;
import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import envoy.util.SerializationUtils;
/** /**
* This interface should be used for any type supposed to be a {@link Message} * This interface should be used for any type supposed to be a {@link Message}
* attachment (i.e. images or sound).<br> * attachment (i.e. images or sound).<br>
@ -14,11 +17,27 @@ import java.io.Serializable;
* @param <T> the type of this message attachment * @param <T> the type of this message attachment
* @since Envoy Common v0.2-alpha * @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 * @return the type implementing this interface
* @since Envoy Common v0.2-alpha * @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> { public class MessageStatusChangeEvent implements Event<Message.MessageStatus> {
private final long messageId; private final long id;
private final Message.MessageStatus messageStatus; private final Message.MessageStatus status;
private final Date date; private final Date date;
/** /**
* Initializes a {@link MessageStatusChangeEvent}. * Initializes a {@link MessageStatusChangeEvent}.
* *
* @param messageId the ID of the {@link Message} this event is related to * @param id the ID of the {@link Message} this event is related to
* @param messageStatus the status of the {@link Message} this event is related * @param status the status of the {@link Message} this event is related
* to * to
* @param date the date at which the MessageStatus change occurred * @param date the date at which the MessageStatus change occurred
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public MessageStatusChangeEvent(long messageId, Message.MessageStatus messageStatus, Date date) { public MessageStatusChangeEvent(long id, Message.MessageStatus status, Date date) {
this.messageId = messageId; this.id = id;
this.messageStatus = messageStatus; this.status = status;
this.date = date; this.date = date;
} }
@ -38,16 +38,16 @@ public class MessageStatusChangeEvent implements Event<Message.MessageStatus> {
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
@Override @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 * @return the ID of the {@link Message} this event is related to
* @since Envoy Common v0.2-alpha * @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 * @since Envoy Common v0.2-alpha
*/ */
public Date getDate() { return date; } public Date getDate() { return date; }