This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/common/src/main/java/envoy/event/GroupResize.java

66 lines
2.1 KiB
Java
Raw Normal View History

package envoy.event;
import envoy.data.Contact;
import envoy.data.Group;
import envoy.data.User;
/**
2020-03-25 17:12:55 +01:00
* 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
2020-06-11 14:00:07 +02:00
* certain {@link Group}.
2020-03-25 17:12:55 +01:00
* <br>
* Project: <strong>envoy-common</strong><br>
2020-06-20 09:19:39 +02:00
* File: <strong>GroupResize.java</strong><br>
* Created: <strong>25 Mar 2020</strong><br>
*
* @author Leon Hofmeister
* @since Envoy Common v0.1-beta
*/
2020-06-20 09:19:39 +02:00
public class GroupResize extends Event<User> {
private final long groupID;
private final ElementOperation operation;
private static final long serialVersionUID = 0L;
/**
2020-06-20 09:19:39 +02:00
* Initializes a {@link GroupResize} through a Contact where the name has
* already been set.
*
2020-03-26 12:45:10 +01:00
* @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
*/
2020-06-20 09:19:39 +02:00
public GroupResize(User user, Group group, ElementOperation operation) {
2020-04-02 20:32:54 +02:00
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();
2020-03-26 12:45:10 +01:00
this.operation = operation;
}
/**
* @return the ID of the {@link Contact} this event is related to
* @since Envoy Common v0.2-alpha
*/
2020-03-26 12:45:10 +01:00
public long getGroupID() { return groupID; }
/**
* @return the operationType
* @since Envoy Common v0.1-beta
*/
public ElementOperation getOperation() { return operation; }
/**
* {@inheritDoc}
*/
@Override
2020-06-20 09:19:39 +02:00
public String toString() { return String.format("GroupResize[userid=%d,groupid=%d,operation=%s]", get(), groupID, operation); }
}