Skip to content
This repository was archived by the owner on Oct 23, 2021. It is now read-only.

Added equals() and hashCode() to DiscordRichPresence #11

Merged
merged 3 commits into from
Dec 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/main/java/club/minnced/discord/rpc/DiscordEventHandlers.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/*
typedef struct DiscordEventHandlers {
Expand Down Expand Up @@ -105,6 +106,28 @@ public interface OnJoinRequest extends Callback
*/
public OnJoinRequest joinRequest;

@Override
public boolean equals(Object o)
{
if (this == o)
return true;
if (!(o instanceof DiscordEventHandlers))
return false;
DiscordEventHandlers that = (DiscordEventHandlers) o;
return Objects.equals(ready, that.ready)
&& Objects.equals(disconnected, that.disconnected)
&& Objects.equals(errored, that.errored)
&& Objects.equals(joinGame, that.joinGame)
&& Objects.equals(spectateGame, that.spectateGame)
&& Objects.equals(joinRequest, that.joinRequest);
}

@Override
public int hashCode()
{
return Objects.hash(ready, disconnected, errored, joinGame, spectateGame, joinRequest);
}

@Override
protected List<String> getFieldOrder()
{
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/club/minnced/discord/rpc/DiscordJoinRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/*
typedef struct DiscordJoinRequest {
Expand Down Expand Up @@ -61,6 +62,26 @@ public class DiscordJoinRequest extends Structure
*/
public String avatar;

@Override
public boolean equals(Object o)
{
if (this == o)
return true;
if (!(o instanceof DiscordJoinRequest))
return false;
DiscordJoinRequest that = (DiscordJoinRequest) o;
return Objects.equals(userId, that.userId)
&& Objects.equals(username, that.username)
&& Objects.equals(discriminator, that.discriminator)
&& Objects.equals(avatar, that.avatar);
}

@Override
public int hashCode()
{
return Objects.hash(userId, username, discriminator, avatar);
}

@Override
protected List<String> getFieldOrder()
{
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/club/minnced/discord/rpc/DiscordRichPresence.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/*
typedef struct DiscordRichPresence {
Expand Down Expand Up @@ -178,6 +179,38 @@ public class DiscordRichPresence extends Structure
*/
public byte instance;

@Override
public boolean equals(Object o)
{
if (this == o)
return true;
if (!(o instanceof DiscordRichPresence))
return false;
DiscordRichPresence presence = (DiscordRichPresence) o;
return startTimestamp == presence.startTimestamp
&& endTimestamp == presence.endTimestamp
&& partySize == presence.partySize
&& partyMax == presence.partyMax
&& instance == presence.instance
&& Objects.equals(state, presence.state)
&& Objects.equals(details, presence.details)
&& Objects.equals(largeImageKey, presence.largeImageKey)
&& Objects.equals(largeImageText, presence.largeImageText)
&& Objects.equals(smallImageKey, presence.smallImageKey)
&& Objects.equals(smallImageText, presence.smallImageText)
&& Objects.equals(partyId, presence.partyId)
&& Objects.equals(matchSecret, presence.matchSecret)
&& Objects.equals(joinSecret, presence.joinSecret)
&& Objects.equals(spectateSecret, presence.spectateSecret);
}

@Override
public int hashCode()
{
return Objects.hash(state, details, startTimestamp, endTimestamp, largeImageKey, largeImageText, smallImageKey,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the identity hashCode is better for JNA structures as they represent a pointer value

Copy link
Contributor Author

@Almighty-Alpaca Almighty-Alpaca Dec 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would contradict the general contract of hashCode() though.

If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I still want the other structs to get the same treatment ^^

smallImageText, partyId, partySize, partyMax, matchSecret, joinSecret, spectateSecret, instance);
}

@Override
protected List<String> getFieldOrder()
{
Expand Down