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>
|
||||
* <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>
|
||||
*
|
||||
* @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
|
@ -19,7 +19,7 @@ import envoy.util.SerializationUtils;
|
||||
*/
|
||||
public class MessageAttachment<T> implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 262683855157198013L;
|
||||
private static final long serialVersionUID = 0L;
|
||||
private T value;
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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}.<br>
|
||||
@ -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,24 +42,20 @@ 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}. <br>
|
||||
* 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;
|
||||
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
|
||||
|
@ -39,7 +39,7 @@ public class ContactOperationEvent extends Event<User> {
|
||||
|
||||
private final Operation operationType;
|
||||
|
||||
private static final long serialVersionUID = -1166652868189511553L;
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
/**
|
||||
* Initializes a {@link ContactOperationEvent}.
|
||||
|
@ -12,7 +12,7 @@ package envoy.event;
|
||||
*/
|
||||
public class ContactSearchRequest extends Event<String> {
|
||||
|
||||
private static final long serialVersionUID = -7969312055630533627L;
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
/**
|
||||
* Initializes a {@link ContactSearchRequest}.
|
||||
|
@ -16,7 +16,7 @@ import envoy.data.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}.
|
||||
|
@ -15,7 +15,7 @@ public abstract class Event<T> 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<T> implements Serializable {
|
||||
*/
|
||||
public static abstract class Valueless extends Event<Void> {
|
||||
|
||||
private static final long serialVersionUID = -9019362144094097997L;
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
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";
|
||||
|
||||
private static final long serialVersionUID = -8723270093452609197L;
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* {@link envoy.data.IdGenerator} instance.<br>
|
||||
* {@link envoy.data.IDGenerator} instance.<br>
|
||||
* <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>
|
||||
*
|
||||
* @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;
|
||||
}
|
@ -17,7 +17,7 @@ public class MessageStatusChangeEvent extends Event<Message.MessageStatus> {
|
||||
private final long id;
|
||||
private final Date date;
|
||||
|
||||
private static final long serialVersionUID = 4566145392192761313L;
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
/**
|
||||
* Initializes a {@link MessageStatusChangeEvent}.
|
||||
|
@ -15,7 +15,7 @@ public class UserStatusChangeEvent extends Event<UserStatus> {
|
||||
|
||||
private final long id;
|
||||
|
||||
private static final long serialVersionUID = 4566145392192761313L;
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
/**
|
||||
* Initializes a {@link UserStatusChangeEvent}.
|
||||
|
Reference in New Issue
Block a user