66 lines
2.1 KiB
Java
66 lines
2.1 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>GroupResize.java</strong><br>
|
|
* Created: <strong>25 Mar 2020</strong><br>
|
|
*
|
|
* @author Leon Hofmeister
|
|
* @since Envoy Common v0.1-beta
|
|
*/
|
|
public class GroupResize extends Event<User> {
|
|
|
|
private final long groupID;
|
|
private final ElementOperation operation;
|
|
|
|
private static final long serialVersionUID = 0L;
|
|
|
|
/**
|
|
* Initializes a {@link GroupResize} 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 describes what to do with the given user:<br>
|
|
* add him to this group or remove him from it
|
|
* @since Envoy Common v0.2-alpha
|
|
*/
|
|
public GroupResize(User user, Group group, ElementOperation operation) {
|
|
super(user);
|
|
if (group.getContacts().contains(user)) {
|
|
if (operation.equals(ElementOperation.ADD)) throw new IllegalArgumentException(
|
|
"Cannot add " + user + " to group " + group.getID() + " because he is already a member of this group");
|
|
} else if (operation.equals(ElementOperation.REMOVE))
|
|
throw new IllegalArgumentException("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 ElementOperation getOperation() { return operation; }
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
@Override
|
|
public String toString() { return String.format("GroupResize[userid=%d,groupid=%d,operation=%s]", get(), groupID, operation); }
|
|
}
|