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:
parent
a4603231ff
commit
3b24d46886
3
.settings/org.eclipse.jdt.ui.prefs
Normal file
3
.settings/org.eclipse.jdt.ui.prefs
Normal file
File diff suppressed because one or more lines are too long
58
src/main/java/envoy/data/Contact.java
Normal file
58
src/main/java/envoy/data/Contact.java
Normal 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); }
|
||||||
|
}
|
68
src/main/java/envoy/data/Group.java
Normal file
68
src/main/java/envoy/data/Group.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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;
|
||||||
|
@ -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,24 +42,20 @@ 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
|
||||||
|
@ -39,7 +39,7 @@ public class ContactOperationEvent extends Event<User> {
|
|||||||
|
|
||||||
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}.
|
||||||
|
@ -12,7 +12,7 @@ package envoy.event;
|
|||||||
*/
|
*/
|
||||||
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}.
|
||||||
|
@ -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}.
|
||||||
|
@ -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); }
|
||||||
|
|
||||||
|
@ -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.
|
||||||
|
@ -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;
|
||||||
}
|
}
|
@ -17,7 +17,7 @@ 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}.
|
||||||
|
@ -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}.
|
||||||
|
Reference in New Issue
Block a user