package envoy.event; import static envoy.event.ElementOperation.*; import envoy.data.*; /** * This event is used to communicate changes in the group size between client * and server. *
* Possible actions are adding or removing certain {@link User}s to or from a
* certain {@link Group}.
*
* @author Leon Hofmeister
* @since Envoy Common v0.1-beta
*/
public final class GroupResize extends Event
* 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);
this.operation = operation;
if (group.getContacts().contains(user)) {
if (operation.equals(ADD))
throw new IllegalArgumentException(String.format("Cannot add %s to %s!", user, group));
} else if (operation.equals(REMOVE))
throw new IllegalArgumentException(String.format("Cannot remove %s from %s!", user, group));
groupID = group.getID();
}
/**
* @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; }
/**
* Applies the operation to a group.
*
* @param group the group to resize
* @since Envoy Common v0.2-beta
*/
public void apply(Group group) {
switch (operation) {
case ADD:
group.getContacts().add(value);
break;
case REMOVE:
group.getContacts().remove(value);
break;
}
}
@Override
public String toString() { return String.format("GroupResize[userid=%d,groupid=%d,operation=%s]", get(), groupID, operation); }
}