From 601ee2c53cc6432f93bdbe5a13e26aba98406a06 Mon Sep 17 00:00:00 2001 From: DieGurke <55625494+DieGurke@users.noreply.github.com> Date: Thu, 26 Mar 2020 12:45:10 +0100 Subject: [PATCH] Formatting and Refactoring --- src/main/java/envoy/data/Contact.java | 7 ++-- src/main/java/envoy/data/Group.java | 10 +++--- .../java/envoy/event/GroupCreationEvent.java | 1 - .../java/envoy/event/GroupResizeEvent.java | 33 +++++++++---------- .../java/envoy/event/NameChangeEvent.java | 4 +-- 5 files changed, 27 insertions(+), 28 deletions(-) diff --git a/src/main/java/envoy/data/Contact.java b/src/main/java/envoy/data/Contact.java index e7a22ed..870aec8 100644 --- a/src/main/java/envoy/data/Contact.java +++ b/src/main/java/envoy/data/Contact.java @@ -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 diff --git a/src/main/java/envoy/data/Group.java b/src/main/java/envoy/data/Group.java index 44f91d4..abc51d0 100644 --- a/src/main/java/envoy/data/Group.java +++ b/src/main/java/envoy/data/Group.java @@ -14,15 +14,15 @@ import java.util.StringJoiner; */ public class Group extends Contact { - private static final long serialVersionUID = 0L; - // TODO add admins private List 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(); } } diff --git a/src/main/java/envoy/event/GroupCreationEvent.java b/src/main/java/envoy/event/GroupCreationEvent.java index a2d393c..17810e9 100644 --- a/src/main/java/envoy/event/GroupCreationEvent.java +++ b/src/main/java/envoy/event/GroupCreationEvent.java @@ -19,5 +19,4 @@ public class GroupCreationEvent extends Event { * @since Envoy Common v0.1-beta */ public GroupCreationEvent(String value) { super(value); } - } diff --git a/src/main/java/envoy/event/GroupResizeEvent.java b/src/main/java/envoy/event/GroupResizeEvent.java index 8ad2ce5..af09c35 100644 --- a/src/main/java/envoy/event/GroupResizeEvent.java +++ b/src/main/java/envoy/event/GroupResizeEvent.java @@ -20,14 +20,14 @@ import envoy.data.User; public class GroupResizeEvent extends Event { 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.
- * These can be: {@link OperationType#ADD} or {@link OperationType#REMOVE}.
+ * These can be: {@link Operation#ADD} or {@link Operation#REMOVE}.
*
* Project: envoy-common
* File: GroupResizeEvent.java
@@ -36,7 +36,7 @@ public class GroupResizeEvent extends Event { * @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 { * 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); } } diff --git a/src/main/java/envoy/event/NameChangeEvent.java b/src/main/java/envoy/event/NameChangeEvent.java index 4cfa640..76f6e46 100644 --- a/src/main/java/envoy/event/NameChangeEvent.java +++ b/src/main/java/envoy/event/NameChangeEvent.java @@ -16,8 +16,9 @@ import envoy.data.Contact; */ public class NameChangeEvent extends Event { + 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 { @Override public String toString() { return String.format("NameChangeEvent[id=%d,name=%s]", id, value); } - }