fix: implemented hashCode that persists for lifetime of object
This commit is contained in:
parent
4ace772be0
commit
f3e3f9f7d7
@ -11,6 +11,9 @@ public class Participant {
|
||||
/** The Websocket to contact the participant with */
|
||||
private WebSocket connection;
|
||||
|
||||
/** The ID of the device that the client provided at connect */
|
||||
public final String deviceID;
|
||||
|
||||
public final String name;
|
||||
|
||||
/** The type (as in role) of participant */
|
||||
@ -20,10 +23,18 @@ public class Participant {
|
||||
// public final boolean AI;
|
||||
|
||||
/** Creates a new {@link Participant} */
|
||||
public Participant (WebSocket connection, ParticipantType type, /* boolean AI,*/ String name) {
|
||||
public Participant(WebSocket connection, ParticipantType type, String deviceID, String name) {
|
||||
this.connection = connection;
|
||||
this.type = type;
|
||||
// this.AI = AI;
|
||||
this.deviceID = deviceID;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/** Creates a new {@link Participant} */
|
||||
public Participant(WebSocket connection, ParticipantType type, String name) {
|
||||
this.connection = connection;
|
||||
this.type = type;
|
||||
this.deviceID = "";
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -33,7 +44,7 @@ public class Participant {
|
||||
}
|
||||
|
||||
/** Sets the connection {@link WebSocket} for the current participant */
|
||||
public void setConnection(WebSocket connection) {
|
||||
void setConnection(WebSocket connection) {
|
||||
if (this.connection != null) {
|
||||
Logger.warn("Overriding connection of active participant {}, which seems invalid", this.name);
|
||||
}
|
||||
@ -47,23 +58,29 @@ public class Participant {
|
||||
this.connection = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Participant that = (Participant) o;
|
||||
return Objects.equals(connection, that.connection) && Objects.equals(name, that.name) && type == that.type;
|
||||
return Objects.equals(connection, that.connection) && Objects.equals(deviceID, that.deviceID) && Objects.equals(name, that.name) && type == that.type;
|
||||
}
|
||||
|
||||
Integer hashCode;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(connection, name, type);
|
||||
if (hashCode == null) hashCode = Objects.hash(connection, deviceID, name, type);
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
public String
|
||||
toString() {
|
||||
return "Participant{" +
|
||||
"connection=" + connection +
|
||||
", deviceID='" + deviceID + '\'' +
|
||||
", name='" + name + '\'' +
|
||||
", type=" + type +
|
||||
'}';
|
||||
|
Loading…
Reference in New Issue
Block a user