Added groups

additionally added:
* serialVersionUID is now equal to 0L
* Renamed classes with a two-letter initialism according to convention
This commit is contained in:
delvh 2020-03-24 19:06:56 +01:00
parent a4603231ff
commit 3b24d46886
15 changed files with 245 additions and 134 deletions

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,58 @@
package envoy.data;
import java.io.Serializable;
/**
* This class is the superclass for both {@link User} and {@link Group}.<br>
* It provides an id and a name for each user and group.<br>
* <br>
* Project: <strong>envoy-common</strong><br>
* File: <strong>Contact.java</strong><br>
* Created: <strong>24 Mar 2020</strong><br>
*
* @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); }
}

View File

@ -0,0 +1,68 @@
package envoy.data;
import java.util.ArrayList;
import java.util.List;
/**
* Project: <strong>envoy-common</strong><br>
* File: <strong>Group.java</strong><br>
* Created: <strong>24 Mar 2020</strong><br>
*
* @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<Long> 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<Long> memberIDs) {
super(id, name);
this.memberIDs = memberIDs;
}
/**
* @return the IDs of all members of this group
* @since Envoy Common v0.1-beta
*/
public List<Long> getMemberIDs() { return memberIDs; }
/**
* @param memberIDs the member IDs to set
* @since Envoy Common v0.1-beta
*/
public void setMemberIDs(List<Long> 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();
}
}

View File

@ -6,33 +6,33 @@ import java.io.Serializable;
* Generates increasing IDs between two numbers.<br> * Generates increasing IDs between two numbers.<br>
* <br> * <br>
* Project: <strong>envoy-common</strong><br> * Project: <strong>envoy-common</strong><br>
* File: <strong>IdGenerator.java</strong><br> * File: <strong>IDGenerator.java</strong><br>
* Created: <strong>31.12.2019</strong><br> * Created: <strong>31.12.2019</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public class IdGenerator implements Serializable { public class IDGenerator implements Serializable {
private final long end; private final long end;
private long current; 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 begin the first ID
* @param size the amount of IDs to provide * @param size the amount of IDs to provide
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public IdGenerator(long begin, long size) { public IDGenerator(long begin, long size) {
current = begin; current = begin;
end = begin + size; end = begin + size;
} }
@Override @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 * @return {@code true} if there are unused IDs remaining

View File

@ -19,7 +19,7 @@ import envoy.util.SerializationUtils;
*/ */
public class MessageAttachment<T> implements Serializable { public class MessageAttachment<T> implements Serializable {
private static final long serialVersionUID = 262683855157198013L; private static final long serialVersionUID = 0L;
private T value; private T value;
/** /**

View File

@ -33,11 +33,11 @@ public class MessageBuilder {
* *
* @param senderId the ID of the user who sends the {@link Message} * @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 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 * id
* @since Envoy Common v0.2-alpha * @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 * Creates an instance of {@link MessageBuilder} with all mandatory values
@ -61,12 +61,12 @@ public class MessageBuilder {
* *
* @param msg the message to copy * @param msg the message to copy
* @param recipientId the ID of the user who receives 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 * id
* @since Envoy v0.1-beta * @since Envoy v0.1-beta
*/ */
public MessageBuilder(Message msg, long recipientId, IdGenerator idGenerator) { public MessageBuilder(Message msg, long recipientId, IDGenerator iDGenerator) {
this(msg.getRecipientId(), recipientId, idGenerator.next()); this(msg.getRecipientId(), recipientId, iDGenerator.next());
this.attachment = msg.getAttachment(); this.attachment = msg.getAttachment();
this.creationDate = new Date(); this.creationDate = new Date();
this.forwarded = true; this.forwarded = true;

View File

@ -1,7 +1,5 @@
package envoy.data; package envoy.data;
import java.io.Serializable;
/** /**
* Represents a unique user with a unique, numeric ID, a name and a current * Represents a unique user with a unique, numeric ID, a name and a current
* {@link UserStatus}.<br> * {@link UserStatus}.<br>
@ -13,7 +11,7 @@ import java.io.Serializable;
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Common v0.2-alpha * @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. * This enumeration defines all possible statuses a user can have.
@ -44,25 +42,21 @@ public class User implements Serializable {
OFFLINE; OFFLINE;
} }
private final long id;
private final String name;
private UserStatus status; 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 * Initializes a {@link User}. <br>
* {@link UserStatus#ONLINE}. * The {@link UserStatus} is set to {@link UserStatus#ONLINE}.
* *
* @param id unique ID * @param id unique ID
* @param name user name * @param name user name
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public User(long id, String name) { public User(long id, String name) {
this.id = id; super(id, name);
this.name = name; status = UserStatus.ONLINE;
status = UserStatus.ONLINE;
} }
/** /**
@ -74,24 +68,12 @@ public class User implements Serializable {
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public User(long id, String name, UserStatus status) { public User(long id, String name, UserStatus status) {
this(id, name); super(id, name);
this.status = status; this.status = status;
} }
@Override @Override
public String toString() { return String.format("User[id=%d,name=%s,status=%s]", id, name, status); } public String toString() { return String.format("User[id=%d,name=%s,status=%s]", getId(), getName(), 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; }
/** /**
* @return the current status of this user * @return the current status of this user

View File

@ -1,61 +1,61 @@
package envoy.event; package envoy.event;
import envoy.data.User; import envoy.data.User;
/** /**
* Signifies the modification of a contact list.<br> * Signifies the modification of a contact list.<br>
* <br> * <br>
* Project: <strong>envoy-common</strong><br> * Project: <strong>envoy-common</strong><br>
* File: <strong>ContactOperationEvent.java</strong><br> * File: <strong>ContactOperationEvent.java</strong><br>
* Created: <strong>05.02.2020</strong><br> * Created: <strong>05.02.2020</strong><br>
* *
* @author Maximilian K&auml;fer * @author Maximilian K&auml;fer
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public class ContactOperationEvent extends Event<User> { public class ContactOperationEvent extends Event<User> {
/** /**
* Specifies the operation performed on a contact list.<br> * Specifies the operation performed on a contact list.<br>
* <br> * <br>
* Project: <strong>envoy-common</strong><br> * Project: <strong>envoy-common</strong><br>
* File: <strong>ContactOperationEvent.java</strong><br> * File: <strong>ContactOperationEvent.java</strong><br>
* Created: <strong>05.02.2020</strong><br> * Created: <strong>05.02.2020</strong><br>
* *
* @author Maximilian K&auml;fer * @author Maximilian K&auml;fer
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public enum Operation { public enum Operation {
/** /**
* Adds a user to the contact list. * Adds a user to the contact list.
*/ */
ADD, ADD,
/** /**
* Removes a user from the contact list. * Removes a user from the contact list.
*/ */
REMOVE; REMOVE;
} }
private final Operation operationType; private final Operation operationType;
private static final long serialVersionUID = -1166652868189511553L; private static final long serialVersionUID = 0L;
/** /**
* Initializes a {@link ContactOperationEvent}. * Initializes a {@link ContactOperationEvent}.
* *
* @param contact the user on which the operation is performed * @param contact the user on which the operation is performed
* @param operationType the type of operation to perform * @param operationType the type of operation to perform
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public ContactOperationEvent(User contact, Operation operationType) { public ContactOperationEvent(User contact, Operation operationType) {
super(contact); super(contact);
this.operationType = operationType; this.operationType = operationType;
} }
/** /**
* @return the type of operation to perform * @return the type of operation to perform
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public Operation getOperationType() { return operationType; } public Operation getOperationType() { return operationType; }
} }

View File

@ -1,24 +1,24 @@
package envoy.event; package envoy.event;
/** /**
* Requests a contact search from the server.<br> * Requests a contact search from the server.<br>
* <br> * <br>
* Project: <strong>envoy-common</strong><br> * Project: <strong>envoy-common</strong><br>
* File: <strong>ContactSearchRequest.java</strong><br> * File: <strong>ContactSearchRequest.java</strong><br>
* Created: <strong>05.02.2020</strong><br> * Created: <strong>05.02.2020</strong><br>
* *
* @author Maximilian K&auml;fer * @author Maximilian K&auml;fer
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public class ContactSearchRequest extends Event<String> { public class ContactSearchRequest extends Event<String> {
private static final long serialVersionUID = -7969312055630533627L; private static final long serialVersionUID = 0L;
/** /**
* Initializes a {@link ContactSearchRequest}. * Initializes a {@link ContactSearchRequest}.
* *
* @param searchPhrase the search phrase to use in the contact search * @param searchPhrase the search phrase to use in the contact search
* @since Envoy Common v0.2-alpha * @since Envoy Common v0.2-alpha
*/ */
public ContactSearchRequest(String searchPhrase) { super(searchPhrase); } public ContactSearchRequest(String searchPhrase) { super(searchPhrase); }
} }

View File

@ -16,7 +16,7 @@ import envoy.data.User;
*/ */
public class ContactSearchResult extends Event<List<User>> { public class ContactSearchResult extends Event<List<User>> {
private static final long serialVersionUID = -8934154116102031561L; private static final long serialVersionUID = 0L;
/** /**
* Creates an instance of {@link ContactSearchResult}. * Creates an instance of {@link ContactSearchResult}.

View File

@ -15,7 +15,7 @@ public abstract class Event<T> implements Serializable {
protected final T value; protected final T value;
private static final long serialVersionUID = 4673659457380399167L; private static final long serialVersionUID = 0L;
protected Event(T value) { this.value = value; } protected Event(T value) { this.value = value; }
@ -39,7 +39,7 @@ public abstract class Event<T> implements Serializable {
*/ */
public static abstract class Valueless extends Event<Void> { public static abstract class Valueless extends Event<Void> {
private static final long serialVersionUID = -9019362144094097997L; private static final long serialVersionUID = 0L;
protected Valueless() { super(null); } protected Valueless() { super(null); }

View File

@ -44,7 +44,7 @@ public class HandshakeRejectionEvent extends Event<String> {
*/ */
public static final String UNKNOWN_REASON = "cause of failure is unknown"; 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. * Creates an instance of {@link HandshakeRejectionEvent} with an empty reason.

View File

@ -2,16 +2,16 @@ package envoy.event;
/** /**
* Signifies to the server that the client needs a new * Signifies to the server that the client needs a new
* {@link envoy.data.IdGenerator} instance.<br> * {@link envoy.data.IDGenerator} instance.<br>
* <br> * <br>
* Project: <strong>envoy-common</strong><br> * Project: <strong>envoy-common</strong><br>
* File: <strong>IdGeneratorRequest.java</strong><br> * File: <strong>IDGeneratorRequest.java</strong><br>
* Created: <strong>28 Jan 2020</strong><br> * Created: <strong>28 Jan 2020</strong><br>
* *
* @author Kai S. K. Engelbart * @author Kai S. K. Engelbart
* @since Envoy Common v0.3-alpha * @since Envoy Common v0.3-alpha
*/ */
public class IdGeneratorRequest extends Event.Valueless { public class IDGeneratorRequest extends Event.Valueless {
private static final long serialVersionUID = 1431107413883364583L; private static final long serialVersionUID = 1431107413883364583L;
} }

View File

@ -14,10 +14,10 @@ import envoy.data.Message;
*/ */
public class MessageStatusChangeEvent extends Event<Message.MessageStatus> { public class MessageStatusChangeEvent extends Event<Message.MessageStatus> {
private final long id; private final long id;
private final Date date; private final Date date;
private static final long serialVersionUID = 4566145392192761313L; private static final long serialVersionUID = 0L;
/** /**
* Initializes a {@link MessageStatusChangeEvent}. * Initializes a {@link MessageStatusChangeEvent}.

View File

@ -15,7 +15,7 @@ public class UserStatusChangeEvent extends Event<UserStatus> {
private final long id; private final long id;
private static final long serialVersionUID = 4566145392192761313L; private static final long serialVersionUID = 0L;
/** /**
* Initializes a {@link UserStatusChangeEvent}. * Initializes a {@link UserStatusChangeEvent}.