97 lines
2.9 KiB
Java
97 lines
2.9 KiB
Java
package envoy.event;
|
|
|
|
import envoy.data.Contact;
|
|
import envoy.data.Group;
|
|
import envoy.data.User;
|
|
|
|
/**
|
|
* This event is used to communicate changes in the group size between client
|
|
* and server.<br>
|
|
* Possible actions are adding or removing certain {@link User}s to or from a
|
|
* certain {@link Group}
|
|
* <br>
|
|
* 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 Operation operation;
|
|
|
|
private static final long serialVersionUID = 0L;
|
|
|
|
/**
|
|
* This enum defines all possibilities for handling
|
|
* {@link GroupResizeEvent}s.<br>
|
|
* These can be: {@link Operation#ADD} or {@link Operation#REMOVE}.<br>
|
|
* <br>
|
|
* 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 Operation {
|
|
/**
|
|
* Select this element, if the given {@link User} should be added to the given
|
|
* {@link Group}
|
|
*/
|
|
ADD,
|
|
/**
|
|
* Select this element, if the given {@link User} should be removed from the
|
|
* given {@link Group}
|
|
*/
|
|
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 operation 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, Operation operation) {
|
|
super(user.getID());
|
|
if (group.getMemberIDs().contains(user.getID())) {
|
|
if (operation.equals(Operation.ADD)) throw new IllegalStateException(
|
|
"Cannot add " + user + " to group " + group.getID() + " because he is already a member of this group");
|
|
} else if (operation.equals(Operation.REMOVE))
|
|
throw new IllegalStateException("Cannot remove " + user + " from group " + group.getID() + " because he is no part of this group");
|
|
groupID = group.getID();
|
|
this.operation = operation;
|
|
}
|
|
|
|
/**
|
|
* @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 Operation getOperationType() { return operation; }
|
|
|
|
/**
|
|
* @param operation the operationType to set
|
|
* @since Envoy Common v0.1-beta
|
|
*/
|
|
public void setOperationType(Operation operation) { this.operation = operation; }
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
@Override
|
|
public String toString() { return String.format("GroupResizeEvent[userid=%d,groupid=%d,operation=%b]", get(), groupID, operation); }
|
|
}
|