added GroupResizeEvent and NameChangeEvent
additionally refactored `getId()` method of Contact to `getID()`
This commit is contained in:
parent
60fbd2a000
commit
e201ddb30d
@ -36,7 +36,7 @@ public abstract class Contact implements Serializable {
|
||||
* @return the ID of this {@link Contact}
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public long getId() { return id; }
|
||||
public long getID() { return id; }
|
||||
|
||||
/**
|
||||
* @return the name of this {@link Contact}
|
||||
|
@ -59,7 +59,7 @@ public class Group extends Contact {
|
||||
@Override
|
||||
public String toString() {
|
||||
var joiner = new StringJoiner(",", "Group[id=", "]");
|
||||
joiner.add("id=" + getId());
|
||||
joiner.add("id=" + getID());
|
||||
joiner.add("name=" + getName());
|
||||
joiner.add("memberIDs=" + getMemberIDs());
|
||||
return joiner.toString();
|
||||
|
@ -73,7 +73,7 @@ public class User extends Contact {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() { return String.format("User[id=%d,name=%s,status=%s]", getId(), getName(), status); }
|
||||
public String toString() { return String.format("User[id=%d,name=%s,status=%s]", getID(), getName(), status); }
|
||||
|
||||
/**
|
||||
* @return the current status of this user
|
||||
|
86
src/main/java/envoy/event/GroupResizeEvent.java
Normal file
86
src/main/java/envoy/event/GroupResizeEvent.java
Normal file
@ -0,0 +1,86 @@
|
||||
package envoy.event;
|
||||
|
||||
import envoy.data.Contact;
|
||||
import envoy.data.Group;
|
||||
import envoy.data.User;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-common</strong><br>
|
||||
* File: <strong>GroupResizeEvent.java</strong><br>
|
||||
* Created: <strong>25 Mar 2020</strong><br>
|
||||
*
|
||||
* @author Leon Hofmeister
|
||||
* @since Envoy Common v0.1-beta
|
||||
*/
|
||||
public class GroupResizeEvent extends Event<Long> {
|
||||
|
||||
private final long groupID;
|
||||
private OperationType operationType;
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
/**
|
||||
* Project: <strong>envoy-common</strong><br>
|
||||
* File: <strong>GroupResizeEvent.java</strong><br>
|
||||
* Created: <strong>25 Mar 2020</strong><br>
|
||||
*
|
||||
* @author Leon Hofmeister
|
||||
* @since Envoy Common v0.1-beta
|
||||
*/
|
||||
public enum OperationType {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
ADD,
|
||||
/**
|
||||
*
|
||||
*/
|
||||
REMOVE
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a {@link GroupResizeEvent} through a Contact where the name has
|
||||
* already been set.
|
||||
*
|
||||
* @param user the {@link User} who wants to join or leave a group
|
||||
* @param group the {@link Group} he wants to join or leave
|
||||
* @param operationType whether the user should be removed from this group. If
|
||||
* false,
|
||||
* this user will be added
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public GroupResizeEvent(User user, Group group, OperationType operationType) {
|
||||
super(user.getID());
|
||||
if (group.getMemberIDs().contains(user.getID())) {
|
||||
if (operationType.equals(OperationType.ADD)) throw new IllegalStateException(
|
||||
"Cannot add " + user + " to group " + group.getID() + " because he is already a member of this group");
|
||||
} else if (operationType.equals(OperationType.REMOVE))
|
||||
throw new IllegalStateException("Cannot remove " + user + " from group " + group.getID() + " because he is no part of this group");
|
||||
groupID = group.getID();
|
||||
this.operationType = operationType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ID of the {@link Contact} this event is related to
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public long getGroupId() { return groupID; }
|
||||
|
||||
/**
|
||||
* @return the operationType
|
||||
* @since Envoy Common v0.1-beta
|
||||
*/
|
||||
public OperationType getOperationType() { return operationType; }
|
||||
|
||||
/**
|
||||
* @param operationType the operationType to set
|
||||
* @since Envoy Common v0.1-beta
|
||||
*/
|
||||
public void setOperationType(OperationType operationType) { this.operationType = operationType; }
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public String toString() { return String.format("GroupResizeEvent[userid=%d,groupid=%d,operationType=%b]", get(), groupID, operationType); }
|
||||
}
|
52
src/main/java/envoy/event/NameChangeEvent.java
Normal file
52
src/main/java/envoy/event/NameChangeEvent.java
Normal file
@ -0,0 +1,52 @@
|
||||
package envoy.event;
|
||||
|
||||
import envoy.data.Contact;
|
||||
|
||||
/**
|
||||
* This event informs<br>
|
||||
* a) the server of the name change of a user or a group.
|
||||
* b) another user of this users name change.
|
||||
*
|
||||
* Project: <strong>envoy-common</strong><br>
|
||||
* File: <strong>NameChangeEvent.java</strong><br>
|
||||
* Created: <strong>25 Mar 2020</strong><br>
|
||||
*
|
||||
* @author Leon Hofmeister
|
||||
* @since Envoy Common v0.1-beta
|
||||
*/
|
||||
public class NameChangeEvent extends Event<String> {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
private final long id;
|
||||
|
||||
/**
|
||||
* Creates a new {@link NameChangeEvent} for a user or a group.
|
||||
*
|
||||
* @param contactID the id of the {@link Contact} who wishes to change his name
|
||||
* @param newName the new name of this contact
|
||||
* @since Envoy Common v0.1-beta
|
||||
*/
|
||||
public NameChangeEvent(long contactID, String newName) {
|
||||
super(newName);
|
||||
id = contactID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a {@link NameChangeEvent} through a Contact where the name has
|
||||
* already been set.
|
||||
*
|
||||
* @param contact the contact whose name was updated
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public NameChangeEvent(Contact contact) { this(contact.getID(), contact.getName()); }
|
||||
|
||||
/**
|
||||
* @return the ID of the {@link Contact} this event is related to
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public long getId() { return id; }
|
||||
|
||||
@Override
|
||||
public String toString() { return String.format("NameChangeEvent[id=%d,name=%s]", id, value); }
|
||||
|
||||
}
|
@ -36,7 +36,7 @@ public class UserStatusChangeEvent extends Event<UserStatus> {
|
||||
* @param user the User from which to build the event
|
||||
* @since Envoy Common v0.2-alpha
|
||||
*/
|
||||
public UserStatusChangeEvent(User user) { this(user.getId(), user.getStatus()); }
|
||||
public UserStatusChangeEvent(User user) { this(user.getID(), user.getStatus()); }
|
||||
|
||||
/**
|
||||
* @return the ID of the {@link User} this event is related to
|
||||
|
Reference in New Issue
Block a user