Formatting and Refactoring

This commit is contained in:
DieGurke 2020-03-26 12:45:10 +01:00
parent 8056624249
commit 601ee2c53c
5 changed files with 27 additions and 28 deletions

View File

@ -23,7 +23,7 @@ public abstract class Contact implements Serializable {
/**
* Creates a new instance of a {@link Contact}.
*
* @param id the id of this contact
* @param id the ID of this contact
* @param name the name of this contact
* @since Envoy Common v0.1-beta
*/
@ -45,12 +45,13 @@ public abstract class Contact implements Serializable {
public String getName() { return name; }
/**
* @param newName the new name of this {@link Contact}
* @param name the new name of this {@link Contact}
* @since Envoy Common v0.1-beta
*/
public void setName(String newName) { name = newName; }
public void setName(String name) { this.name = name; }
/**
*
* {@inheritDoc}
*/
@Override

View File

@ -14,15 +14,15 @@ import java.util.StringJoiner;
*/
public class Group extends Contact {
private static final long serialVersionUID = 0L;
// TODO add admins
private List<Long> memberIDs;
private static final long serialVersionUID = 0L;
/**
* Creates a new instance of a {@link Group}.
*
* @param id the id of this group
* @param id the ID of this group
* @param name the name of this group
* @since Envoy Common v0.1-beta
*/
@ -31,7 +31,7 @@ public class Group extends Contact {
/**
* Creates a new instance of a {@link Group}.
*
* @param id the id of this group
* @param id the ID of this group
* @param name the name of this group
* @param memberIDs the IDs of all members that should be preinitialized
* @since Envoy Common v0.1-beta
@ -61,7 +61,7 @@ public class Group extends Contact {
var joiner = new StringJoiner(",", "Group[id=", "]");
joiner.add("id=" + getID());
joiner.add("name=" + getName());
joiner.add("memberIDs=" + getMemberIDs());
joiner.add("members=" + getMemberIDs().size());
return joiner.toString();
}
}

View File

@ -19,5 +19,4 @@ public class GroupCreationEvent extends Event<String> {
* @since Envoy Common v0.1-beta
*/
public GroupCreationEvent(String value) { super(value); }
}

View File

@ -20,14 +20,14 @@ import envoy.data.User;
public class GroupResizeEvent extends Event<Long> {
private final long groupID;
private OperationType operationType;
private Operation operation;
private static final long serialVersionUID = 0L;
/**
* This enum defines all possibilities for handling
* {@link GroupResizeEvent}s.<br>
* These can be: {@link OperationType#ADD} or {@link OperationType#REMOVE}.<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>
@ -36,7 +36,7 @@ public class GroupResizeEvent extends Event<Long> {
* @author Leon Hofmeister
* @since Envoy Common v0.1-beta
*/
public enum OperationType {
public enum Operation {
/**
* Select this element, if the given {@link User} should be added to the given
* {@link Group}
@ -53,45 +53,44 @@ public class GroupResizeEvent extends Event<Long> {
* 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
* @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, OperationType operationType) {
public GroupResizeEvent(User user, Group group, Operation operation) {
super(user.getID());
if (group.getMemberIDs().contains(user.getID())) {
if (operationType.equals(OperationType.ADD)) throw new IllegalStateException(
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 (operationType.equals(OperationType.REMOVE))
} 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.operationType = operationType;
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; }
public long getGroupID() { return groupID; }
/**
* @return the operationType
* @since Envoy Common v0.1-beta
*/
public OperationType getOperationType() { return operationType; }
public Operation getOperationType() { return operation; }
/**
* @param operationType the operationType to set
* @param operation the operationType to set
* @since Envoy Common v0.1-beta
*/
public void setOperationType(OperationType operationType) { this.operationType = operationType; }
public void setOperationType(Operation operation) { this.operation = operation; }
/**
* {@inheritDoc}
*/
@Override
public String toString() { return String.format("GroupResizeEvent[userid=%d,groupid=%d,operationType=%b]", get(), groupID, operationType); }
public String toString() { return String.format("GroupResizeEvent[userid=%d,groupid=%d,operation=%b]", get(), groupID, operation); }
}

View File

@ -16,8 +16,9 @@ import envoy.data.Contact;
*/
public class NameChangeEvent extends Event<String> {
private final long id;
private static final long serialVersionUID = 0L;
private final long id;
/**
* Creates a new {@link NameChangeEvent} for a user or a group.
@ -48,5 +49,4 @@ public class NameChangeEvent extends Event<String> {
@Override
public String toString() { return String.format("NameChangeEvent[id=%d,name=%s]", id, value); }
}