Made Event<T> an abstract class, added ContactSearchResult
This commit is contained in:
parent
15b5289267
commit
189432e798
@ -12,7 +12,7 @@ import envoy.data.User;
|
||||
* @author Maximilian Käfer
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public class ContactOperationEvent implements Event<User> {
|
||||
public class ContactOperationEvent extends Event<User> {
|
||||
|
||||
/**
|
||||
* Specifies the operation performed on a contact list.<br>
|
||||
@ -37,7 +37,6 @@ public class ContactOperationEvent implements Event<User> {
|
||||
REMOVE;
|
||||
}
|
||||
|
||||
private final User contact;
|
||||
private final Operation operationType;
|
||||
|
||||
private static final long serialVersionUID = -1166652868189511553L;
|
||||
@ -50,17 +49,10 @@ public class ContactOperationEvent implements Event<User> {
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public ContactOperationEvent(User contact, Operation operationType) {
|
||||
this.contact = contact;
|
||||
super(contact);
|
||||
this.operationType = operationType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the user to perform an operation on
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
@Override
|
||||
public User get() { return contact; }
|
||||
|
||||
/**
|
||||
* @return the type of operation to perform
|
||||
* @since Envoy Common v0.2-alpha
|
||||
|
@ -10,9 +10,7 @@ package envoy.event;
|
||||
* @author Maximilian Käfer
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public class ContactSearchRequest implements Event<String> {
|
||||
|
||||
private final String searchPhrase;
|
||||
public class ContactSearchRequest extends Event<String> {
|
||||
|
||||
private static final long serialVersionUID = -7969312055630533627L;
|
||||
|
||||
@ -22,12 +20,5 @@ public class ContactSearchRequest implements Event<String> {
|
||||
* @param searchPhrase the search phrase to use in the contact search
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public ContactSearchRequest(String searchPhrase) { this.searchPhrase = searchPhrase; }
|
||||
|
||||
/**
|
||||
* @return the search phrase
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
@Override
|
||||
public String get() { return searchPhrase; }
|
||||
public ContactSearchRequest(String searchPhrase) { super(searchPhrase); }
|
||||
}
|
||||
|
28
src/main/java/envoy/event/ContactSearchResult.java
Normal file
28
src/main/java/envoy/event/ContactSearchResult.java
Normal file
@ -0,0 +1,28 @@
|
||||
package envoy.event;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import envoy.data.User;
|
||||
|
||||
/**
|
||||
* Contains a list of {@link User}s for which a search was performed.<br>
|
||||
* <br>
|
||||
* Project: <strong>envoy-common</strong><br>
|
||||
* File: <strong>ContactSearchResult.java</strong><br>
|
||||
* Created: <strong>11 Feb 2020</strong><br>
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public class ContactSearchResult extends Event<List<User>> {
|
||||
|
||||
private static final long serialVersionUID = -8934154116102031561L;
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link ContactSearchResult}.
|
||||
*
|
||||
* @param users the users found during the search
|
||||
*/
|
||||
public ContactSearchResult(List<User> users) { super(users); }
|
||||
|
||||
}
|
@ -11,10 +11,36 @@ import java.io.Serializable;
|
||||
* @param <T> the type of the Event
|
||||
* @since Envoy v0.2-alpha
|
||||
*/
|
||||
public interface Event<T> extends Serializable {
|
||||
public abstract class Event<T> implements Serializable {
|
||||
|
||||
protected final T value;
|
||||
|
||||
private static final long serialVersionUID = 4673659457380399167L;
|
||||
|
||||
protected Event(T value) { this.value = value; }
|
||||
|
||||
/**
|
||||
* @return the data associated with this event
|
||||
*/
|
||||
default T get() { return null; }
|
||||
public T get() { return value; }
|
||||
|
||||
@Override
|
||||
public String toString() { return String.format("%s[value=%s]%n", this.getClass().getSimpleName(), value); }
|
||||
|
||||
/**
|
||||
* Serves as a super class for events that do not carry a value.<br>
|
||||
* <br>
|
||||
* Project: <strong>envoy-common</strong><br>
|
||||
* File: <strong>Event.java</strong><br>
|
||||
* Created: <strong>11 Feb 2020</strong><br>
|
||||
*
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public static abstract class Valueless extends Event<Void> {
|
||||
|
||||
private static final long serialVersionUID = -9019362144094097997L;
|
||||
|
||||
protected Valueless() { super(null); }
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,7 @@ package envoy.event;
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since Envoy Common v0.3-alpha
|
||||
*/
|
||||
public class HandshakeRejectionEvent implements Event<String> {
|
||||
|
||||
private final String reason;
|
||||
public class HandshakeRejectionEvent extends Event<String> {
|
||||
|
||||
private static final long serialVersionUID = -8723270093452609197L;
|
||||
|
||||
@ -22,7 +20,7 @@ public class HandshakeRejectionEvent implements Event<String> {
|
||||
*
|
||||
* @since Envoy Common v0.3-alpha
|
||||
*/
|
||||
public HandshakeRejectionEvent() { this(""); }
|
||||
public HandshakeRejectionEvent() { super(""); }
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link HandshakeRejectionEvent}.
|
||||
@ -30,12 +28,5 @@ public class HandshakeRejectionEvent implements Event<String> {
|
||||
* @param reason the reason why the handshake was rejected
|
||||
* @since Envoy Common v0.3-alpha
|
||||
*/
|
||||
public HandshakeRejectionEvent(String reason) { this.reason = reason; }
|
||||
|
||||
/**
|
||||
* @return the reason why the handshake was rejected
|
||||
* @since Envoy Common v0.3-alpha
|
||||
*/
|
||||
@Override
|
||||
public String get() { return reason; }
|
||||
public HandshakeRejectionEvent(String reason) { super(""); }
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ package envoy.event;
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since Envoy Common v0.3-alpha
|
||||
*/
|
||||
public class IdGeneratorRequest implements Event<Void> {
|
||||
public class IdGeneratorRequest extends Event.Valueless {
|
||||
|
||||
private static final long serialVersionUID = 1431107413883364583L;
|
||||
}
|
||||
|
@ -12,10 +12,9 @@ import envoy.data.Message;
|
||||
* @author Kai S. K. Engelbart
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public class MessageStatusChangeEvent implements Event<Message.MessageStatus> {
|
||||
public class MessageStatusChangeEvent extends Event<Message.MessageStatus> {
|
||||
|
||||
private final long id;
|
||||
private final Message.MessageStatus status;
|
||||
private final Date date;
|
||||
|
||||
private static final long serialVersionUID = 4566145392192761313L;
|
||||
@ -30,8 +29,8 @@ public class MessageStatusChangeEvent implements Event<Message.MessageStatus> {
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public MessageStatusChangeEvent(long id, Message.MessageStatus status, Date date) {
|
||||
super(status);
|
||||
this.id = id;
|
||||
this.status = status;
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
@ -43,13 +42,6 @@ public class MessageStatusChangeEvent implements Event<Message.MessageStatus> {
|
||||
*/
|
||||
public MessageStatusChangeEvent(Message message) { this(message.getId(), message.getStatus(), new Date()); }
|
||||
|
||||
/**
|
||||
* @return the status of the {@link Message} this event is related to
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
@Override
|
||||
public Message.MessageStatus get() { return status; }
|
||||
|
||||
/**
|
||||
* @return the ID of the {@link Message} this event is related to
|
||||
* @since Envoy Common v0.2-alpha
|
||||
@ -63,5 +55,5 @@ public class MessageStatusChangeEvent implements Event<Message.MessageStatus> {
|
||||
public Date getDate() { return date; }
|
||||
|
||||
@Override
|
||||
public String toString() { return String.format("MessageStatusChangeEvent[id=%d,status=%s,date=%s]", id, status, date); }
|
||||
public String toString() { return String.format("MessageStatusChangeEvent[id=%d,status=%s,date=%s]", id, value, date); }
|
||||
}
|
||||
|
@ -11,10 +11,9 @@ import envoy.data.User.UserStatus;
|
||||
* @author Leon Hofmeister
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public class UserStatusChangeEvent implements Event<UserStatus> {
|
||||
public class UserStatusChangeEvent extends Event<UserStatus> {
|
||||
|
||||
private final long id;
|
||||
private final User.UserStatus status;
|
||||
|
||||
private static final long serialVersionUID = 4566145392192761313L;
|
||||
|
||||
@ -27,8 +26,8 @@ public class UserStatusChangeEvent implements Event<UserStatus> {
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public UserStatusChangeEvent(long id, User.UserStatus status) {
|
||||
super(status);
|
||||
this.id = id;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,13 +38,6 @@ public class UserStatusChangeEvent implements Event<UserStatus> {
|
||||
*/
|
||||
public UserStatusChangeEvent(User user) { this(user.getId(), user.getStatus()); }
|
||||
|
||||
/**
|
||||
* @return the status of the {@link User} this event is related to
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
@Override
|
||||
public User.UserStatus get() { return status; }
|
||||
|
||||
/**
|
||||
* @return the ID of the {@link User} this event is related to
|
||||
* @since Envoy Common v0.2-alpha
|
||||
@ -53,5 +45,5 @@ public class UserStatusChangeEvent implements Event<UserStatus> {
|
||||
public long getId() { return id; }
|
||||
|
||||
@Override
|
||||
public String toString() { return String.format("UserStatusChangeEvent[id=%d,status=%s]", id, status); }
|
||||
public String toString() { return String.format("UserStatusChangeEvent[id=%d,status=%s]", id, value); }
|
||||
}
|
||||
|
Reference in New Issue
Block a user