diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs
new file mode 100644
index 0000000..f2ac36a
--- /dev/null
+++ b/.settings/org.eclipse.jdt.ui.prefs
@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.ui.javadoc=true
+org.eclipse.jdt.ui.text.custom_code_templates=/**\n * @return the ${bare_field_name}\n * @since Envoy Common v0.1-beta\n *//**\n * @param ${param} the ${bare_field_name} to set\n * @since Envoy Common v0.1-beta\n *//**\n * @since Envoy Common v0.1-beta\n *//**\n * Project\: <strong>${project_name}</strong><br>\n * File\: <strong>${file_name}</strong><br>\n * Created\: <strong>${date}</strong><br>\n * \n * @author ${user}\n * @since Envoy Common v0.1-beta\n *//**\n * ${tags}\n * @since Envoy Common v0.1-beta\n *//**\n * @author ${user}\n *\n * ${tags}\n * @since Envoy Common v0.1-beta\n *//**\n * {@inheritDoc}\n *//**\n * ${tags}\n * ${see_to_target}\n * @since Envoy Common v0.1-beta\n */${filecomment}\n${package_declaration}\n\n${typecomment}\n${type_declaration}\n\n\n\n${exception_var}.printStackTrace();${body_statement}${body_statement}return ${field};${field} \= ${param};
diff --git a/src/main/java/envoy/data/Contact.java b/src/main/java/envoy/data/Contact.java
new file mode 100644
index 0000000..3e830f1
--- /dev/null
+++ b/src/main/java/envoy/data/Contact.java
@@ -0,0 +1,58 @@
+package envoy.data;
+
+import java.io.Serializable;
+
+/**
+ * This class is the superclass for both {@link User} and {@link Group}.
+ * It provides an id and a name for each user and group.
+ *
+ * Project: envoy-common
+ * File: Contact.java
+ * Created: 24 Mar 2020
+ *
+ * @author Leon Hofmeister
+ * @since Envoy v0.1-beta
+ */
+public abstract class Contact implements Serializable {
+
+ private long id;
+ private String name;
+
+ private static final long serialVersionUID = 0L;
+
+ /**
+ * Creates a new instance of a {@link Contact}.
+ *
+ * @param id the id of this contact
+ * @param name the name of this contact
+ * @since Envoy Common v0.1-beta
+ */
+ public Contact(long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ /**
+ * @return the ID of this {@link Contact}
+ * @since Envoy Common v0.2-alpha
+ */
+ public long getId() { return id; }
+
+ /**
+ * @return the name of this {@link Contact}
+ * @since Envoy Common v0.2-alpha
+ */
+ public String getName() { return name; }
+
+ /**
+ * @param newName the new name of this {@link Contact}
+ * @since Envoy Common v0.1-beta
+ */
+ public void setName(String newName) { name = newName; }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() { return String.format("Contact[id=%d,name=%s]", id, name); }
+}
diff --git a/src/main/java/envoy/data/Group.java b/src/main/java/envoy/data/Group.java
new file mode 100644
index 0000000..7de0f20
--- /dev/null
+++ b/src/main/java/envoy/data/Group.java
@@ -0,0 +1,68 @@
+package envoy.data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Project: envoy-common
+ * File: Group.java
+ * Created: 24 Mar 2020
+ *
+ * @author Leon Hofmeister
+ * @since Envoy Common v0.1-beta
+ */
+public class Group extends Contact {
+
+ private static final long serialVersionUID = 0L;
+
+ // TODO add admins
+ private List memberIDs = new ArrayList<>();
+
+ /**
+ * Creates a new instance of a {@link Group}.
+ *
+ * @param id the id of this group
+ * @param name the name of this group
+ * @since Envoy Common v0.1-beta
+ */
+ public Group(long id, String name) { super(id, name); }
+
+ /**
+ * Creates a new instance of a {@link 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
+ */
+ public Group(long id, String name, List memberIDs) {
+ super(id, name);
+ this.memberIDs = memberIDs;
+ }
+
+ /**
+ * @return the IDs of all members of this group
+ * @since Envoy Common v0.1-beta
+ */
+ public List getMemberIDs() { return memberIDs; }
+
+ /**
+ * @param memberIDs the member IDs to set
+ * @since Envoy Common v0.1-beta
+ */
+ public void setMemberIDs(List memberIDs) { this.memberIDs = memberIDs; }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Group[id=" + getId() + ",name=" + getName() + ",memberIDs=[");
+ memberIDs.forEach(id -> { sb.append(id); sb.append(", "); });
+ // deleting the final ", "
+ sb.delete(sb.length() - 2, sb.length());
+ sb.append("]]");
+ return sb.toString();
+ }
+}
diff --git a/src/main/java/envoy/data/IdGenerator.java b/src/main/java/envoy/data/IDGenerator.java
similarity index 73%
rename from src/main/java/envoy/data/IdGenerator.java
rename to src/main/java/envoy/data/IDGenerator.java
index 26b7131..91681e0 100644
--- a/src/main/java/envoy/data/IdGenerator.java
+++ b/src/main/java/envoy/data/IDGenerator.java
@@ -6,33 +6,33 @@ import java.io.Serializable;
* Generates increasing IDs between two numbers.
*
* Project: envoy-common
- * File: IdGenerator.java
+ * File: IDGenerator.java
* Created: 31.12.2019
*
* @author Kai S. K. Engelbart
* @since Envoy Common v0.2-alpha
*/
-public class IdGenerator implements Serializable {
+public class IDGenerator implements Serializable {
private final long end;
private long current;
- private static final long serialVersionUID = -1517378307055845147L;
+ private static final long serialVersionUID = 0L;
/**
- * Creates an instance of {@link IdGenerator}.
+ * Creates an instance of {@link IDGenerator}.
*
* @param begin the first ID
* @param size the amount of IDs to provide
* @since Envoy Common v0.2-alpha
*/
- public IdGenerator(long begin, long size) {
+ public IDGenerator(long begin, long size) {
current = begin;
end = begin + size;
}
@Override
- public String toString() { return String.format("IdGenerator[current=%d,end=%d]", current, end); }
+ public String toString() { return String.format("IDGenerator[current=%d,end=%d]", current, end); }
/**
* @return {@code true} if there are unused IDs remaining
diff --git a/src/main/java/envoy/data/MessageAttachment.java b/src/main/java/envoy/data/MessageAttachment.java
index 23a2c2e..3d04eab 100644
--- a/src/main/java/envoy/data/MessageAttachment.java
+++ b/src/main/java/envoy/data/MessageAttachment.java
@@ -19,7 +19,7 @@ import envoy.util.SerializationUtils;
*/
public class MessageAttachment implements Serializable {
- private static final long serialVersionUID = 262683855157198013L;
+ private static final long serialVersionUID = 0L;
private T value;
/**
diff --git a/src/main/java/envoy/data/MessageBuilder.java b/src/main/java/envoy/data/MessageBuilder.java
index 9129357..3ee6ec5 100644
--- a/src/main/java/envoy/data/MessageBuilder.java
+++ b/src/main/java/envoy/data/MessageBuilder.java
@@ -33,11 +33,11 @@ public class MessageBuilder {
*
* @param senderId the ID of the user who sends the {@link Message}
* @param recipientId the ID of the user who receives the {@link Message}
- * @param idGenerator the ID generator used to generate a unique {@link Message}
+ * @param iDGenerator the ID generator used to generate a unique {@link Message}
* id
* @since Envoy Common v0.2-alpha
*/
- public MessageBuilder(long senderId, long recipientId, IdGenerator idGenerator) { this(senderId, recipientId, idGenerator.next()); }
+ public MessageBuilder(long senderId, long recipientId, IDGenerator iDGenerator) { this(senderId, recipientId, iDGenerator.next()); }
/**
* Creates an instance of {@link MessageBuilder} with all mandatory values
@@ -61,12 +61,12 @@ public class MessageBuilder {
*
* @param msg the message to copy
* @param recipientId the ID of the user who receives the {@link Message}
- * @param idGenerator the ID generator used to generate a unique {@link Message}
+ * @param iDGenerator the ID generator used to generate a unique {@link Message}
* id
* @since Envoy v0.1-beta
*/
- public MessageBuilder(Message msg, long recipientId, IdGenerator idGenerator) {
- this(msg.getRecipientId(), recipientId, idGenerator.next());
+ public MessageBuilder(Message msg, long recipientId, IDGenerator iDGenerator) {
+ this(msg.getRecipientId(), recipientId, iDGenerator.next());
this.attachment = msg.getAttachment();
this.creationDate = new Date();
this.forwarded = true;
diff --git a/src/main/java/envoy/data/User.java b/src/main/java/envoy/data/User.java
index bf20fdf..be3881e 100644
--- a/src/main/java/envoy/data/User.java
+++ b/src/main/java/envoy/data/User.java
@@ -1,7 +1,5 @@
package envoy.data;
-import java.io.Serializable;
-
/**
* Represents a unique user with a unique, numeric ID, a name and a current
* {@link UserStatus}.
@@ -13,7 +11,7 @@ import java.io.Serializable;
* @author Kai S. K. Engelbart
* @since Envoy Common v0.2-alpha
*/
-public class User implements Serializable {
+public class User extends Contact {
/**
* This enumeration defines all possible statuses a user can have.
@@ -44,25 +42,21 @@ public class User implements Serializable {
OFFLINE;
}
- private final long id;
- private final String name;
-
private UserStatus status;
- private static final long serialVersionUID = 0L;
+ private static final long serialVersionUID = 1L;
/**
- * Initializes a {@link User}. The {@link UserStatus} is set to
- * {@link UserStatus#ONLINE}.
+ * Initializes a {@link User}.
+ * The {@link UserStatus} is set to {@link UserStatus#ONLINE}.
*
* @param id unique ID
* @param name user name
* @since Envoy Common v0.2-alpha
*/
public User(long id, String name) {
- this.id = id;
- this.name = name;
- status = UserStatus.ONLINE;
+ super(id, name);
+ status = UserStatus.ONLINE;
}
/**
@@ -74,24 +68,12 @@ public class User implements Serializable {
* @since Envoy Common v0.2-alpha
*/
public User(long id, String name, UserStatus status) {
- this(id, name);
+ super(id, name);
this.status = status;
}
@Override
- public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); }
-
- /**
- * @return the ID of this {@link User}
- * @since Envoy Common v0.2-alpha
- */
- public long getId() { return id; }
-
- /**
- * @return the name of this {@link User}
- * @since Envoy Common v0.2-alpha
- */
- public String getName() { return name; }
+ public String toString() { return String.format("User[id=%d,name=%s,status=%s]", getId(), getName(), status); }
/**
* @return the current status of this user
diff --git a/src/main/java/envoy/event/ContactOperationEvent.java b/src/main/java/envoy/event/ContactOperationEvent.java
index 7410e65..9fe505d 100644
--- a/src/main/java/envoy/event/ContactOperationEvent.java
+++ b/src/main/java/envoy/event/ContactOperationEvent.java
@@ -1,61 +1,61 @@
-package envoy.event;
-
-import envoy.data.User;
-
-/**
- * Signifies the modification of a contact list.
- *
- * Project: envoy-common
- * File: ContactOperationEvent.java
- * Created: 05.02.2020
- *
- * @author Maximilian Käfer
- * @since Envoy Common v0.2-alpha
- */
-public class ContactOperationEvent extends Event {
-
- /**
- * Specifies the operation performed on a contact list.
- *
- * Project: envoy-common
- * File: ContactOperationEvent.java
- * Created: 05.02.2020
- *
- * @author Maximilian Käfer
- * @since Envoy Common v0.2-alpha
- */
- public enum Operation {
-
- /**
- * Adds a user to the contact list.
- */
- ADD,
-
- /**
- * Removes a user from the contact list.
- */
- REMOVE;
- }
-
- private final Operation operationType;
-
- private static final long serialVersionUID = -1166652868189511553L;
-
- /**
- * Initializes a {@link ContactOperationEvent}.
- *
- * @param contact the user on which the operation is performed
- * @param operationType the type of operation to perform
- * @since Envoy Common v0.2-alpha
- */
- public ContactOperationEvent(User contact, Operation operationType) {
- super(contact);
- this.operationType = operationType;
- }
-
- /**
- * @return the type of operation to perform
- * @since Envoy Common v0.2-alpha
- */
- public Operation getOperationType() { return operationType; }
-}
+package envoy.event;
+
+import envoy.data.User;
+
+/**
+ * Signifies the modification of a contact list.
+ *
+ * Project: envoy-common
+ * File: ContactOperationEvent.java
+ * Created: 05.02.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Common v0.2-alpha
+ */
+public class ContactOperationEvent extends Event {
+
+ /**
+ * Specifies the operation performed on a contact list.
+ *
+ * Project: envoy-common
+ * File: ContactOperationEvent.java
+ * Created: 05.02.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Common v0.2-alpha
+ */
+ public enum Operation {
+
+ /**
+ * Adds a user to the contact list.
+ */
+ ADD,
+
+ /**
+ * Removes a user from the contact list.
+ */
+ REMOVE;
+ }
+
+ private final Operation operationType;
+
+ private static final long serialVersionUID = 0L;
+
+ /**
+ * Initializes a {@link ContactOperationEvent}.
+ *
+ * @param contact the user on which the operation is performed
+ * @param operationType the type of operation to perform
+ * @since Envoy Common v0.2-alpha
+ */
+ public ContactOperationEvent(User contact, Operation operationType) {
+ super(contact);
+ this.operationType = operationType;
+ }
+
+ /**
+ * @return the type of operation to perform
+ * @since Envoy Common v0.2-alpha
+ */
+ public Operation getOperationType() { return operationType; }
+}
diff --git a/src/main/java/envoy/event/ContactSearchRequest.java b/src/main/java/envoy/event/ContactSearchRequest.java
index 4076265..bd13812 100644
--- a/src/main/java/envoy/event/ContactSearchRequest.java
+++ b/src/main/java/envoy/event/ContactSearchRequest.java
@@ -1,24 +1,24 @@
-package envoy.event;
-
-/**
- * Requests a contact search from the server.
- *
- * Project: envoy-common
- * File: ContactSearchRequest.java
- * Created: 05.02.2020
- *
- * @author Maximilian Käfer
- * @since Envoy Common v0.2-alpha
- */
-public class ContactSearchRequest extends Event {
-
- private static final long serialVersionUID = -7969312055630533627L;
-
- /**
- * Initializes a {@link ContactSearchRequest}.
- *
- * @param searchPhrase the search phrase to use in the contact search
- * @since Envoy Common v0.2-alpha
- */
- public ContactSearchRequest(String searchPhrase) { super(searchPhrase); }
-}
+package envoy.event;
+
+/**
+ * Requests a contact search from the server.
+ *
+ * Project: envoy-common
+ * File: ContactSearchRequest.java
+ * Created: 05.02.2020
+ *
+ * @author Maximilian Käfer
+ * @since Envoy Common v0.2-alpha
+ */
+public class ContactSearchRequest extends Event {
+
+ private static final long serialVersionUID = 0L;
+
+ /**
+ * Initializes a {@link ContactSearchRequest}.
+ *
+ * @param searchPhrase the search phrase to use in the contact search
+ * @since Envoy Common v0.2-alpha
+ */
+ public ContactSearchRequest(String searchPhrase) { super(searchPhrase); }
+}
diff --git a/src/main/java/envoy/event/ContactSearchResult.java b/src/main/java/envoy/event/ContactSearchResult.java
index 929ee30..5f1691e 100644
--- a/src/main/java/envoy/event/ContactSearchResult.java
+++ b/src/main/java/envoy/event/ContactSearchResult.java
@@ -16,7 +16,7 @@ import envoy.data.User;
*/
public class ContactSearchResult extends Event> {
- private static final long serialVersionUID = -8934154116102031561L;
+ private static final long serialVersionUID = 0L;
/**
* Creates an instance of {@link ContactSearchResult}.
diff --git a/src/main/java/envoy/event/Event.java b/src/main/java/envoy/event/Event.java
index 5b13306..809c5ec 100644
--- a/src/main/java/envoy/event/Event.java
+++ b/src/main/java/envoy/event/Event.java
@@ -15,7 +15,7 @@ public abstract class Event implements Serializable {
protected final T value;
- private static final long serialVersionUID = 4673659457380399167L;
+ private static final long serialVersionUID = 0L;
protected Event(T value) { this.value = value; }
@@ -39,7 +39,7 @@ public abstract class Event implements Serializable {
*/
public static abstract class Valueless extends Event {
- private static final long serialVersionUID = -9019362144094097997L;
+ private static final long serialVersionUID = 0L;
protected Valueless() { super(null); }
diff --git a/src/main/java/envoy/event/HandshakeRejectionEvent.java b/src/main/java/envoy/event/HandshakeRejectionEvent.java
index c89405d..b6efb38 100644
--- a/src/main/java/envoy/event/HandshakeRejectionEvent.java
+++ b/src/main/java/envoy/event/HandshakeRejectionEvent.java
@@ -44,7 +44,7 @@ public class HandshakeRejectionEvent extends Event {
*/
public static final String UNKNOWN_REASON = "cause of failure is unknown";
- private static final long serialVersionUID = -8723270093452609197L;
+ private static final long serialVersionUID = 0L;
/**
* Creates an instance of {@link HandshakeRejectionEvent} with an empty reason.
diff --git a/src/main/java/envoy/event/IdGeneratorRequest.java b/src/main/java/envoy/event/IDGeneratorRequest.java
similarity index 66%
rename from src/main/java/envoy/event/IdGeneratorRequest.java
rename to src/main/java/envoy/event/IDGeneratorRequest.java
index fe7871d..2994c75 100644
--- a/src/main/java/envoy/event/IdGeneratorRequest.java
+++ b/src/main/java/envoy/event/IDGeneratorRequest.java
@@ -2,16 +2,16 @@ package envoy.event;
/**
* Signifies to the server that the client needs a new
- * {@link envoy.data.IdGenerator} instance.
+ * {@link envoy.data.IDGenerator} instance.
*
* Project: envoy-common
- * File: IdGeneratorRequest.java
+ * File: IDGeneratorRequest.java
* Created: 28 Jan 2020
*
* @author Kai S. K. Engelbart
* @since Envoy Common v0.3-alpha
*/
-public class IdGeneratorRequest extends Event.Valueless {
+public class IDGeneratorRequest extends Event.Valueless {
private static final long serialVersionUID = 1431107413883364583L;
}
diff --git a/src/main/java/envoy/event/MessageStatusChangeEvent.java b/src/main/java/envoy/event/MessageStatusChangeEvent.java
index d7e7e4a..0307e6e 100644
--- a/src/main/java/envoy/event/MessageStatusChangeEvent.java
+++ b/src/main/java/envoy/event/MessageStatusChangeEvent.java
@@ -14,10 +14,10 @@ import envoy.data.Message;
*/
public class MessageStatusChangeEvent extends Event {
- private final long id;
- private final Date date;
+ private final long id;
+ private final Date date;
- private static final long serialVersionUID = 4566145392192761313L;
+ private static final long serialVersionUID = 0L;
/**
* Initializes a {@link MessageStatusChangeEvent}.
diff --git a/src/main/java/envoy/event/UserStatusChangeEvent.java b/src/main/java/envoy/event/UserStatusChangeEvent.java
index ed6e79f..8349653 100644
--- a/src/main/java/envoy/event/UserStatusChangeEvent.java
+++ b/src/main/java/envoy/event/UserStatusChangeEvent.java
@@ -15,7 +15,7 @@ public class UserStatusChangeEvent extends Event {
private final long id;
- private static final long serialVersionUID = 4566145392192761313L;
+ private static final long serialVersionUID = 0L;
/**
* Initializes a {@link UserStatusChangeEvent}.