Skip to content

Commit

Permalink
equals/hashcode for modes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbax committed Sep 26, 2016
1 parent 91753b3 commit 9970b24
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import javax.annotation.Nonnull;
import java.time.Instant;
import java.util.Objects;
import java.util.Optional;

final class ModeData {
Expand Down Expand Up @@ -64,11 +65,25 @@ static class IRCChannelUserMode extends IRCModeBase implements ChannelUserMode {
this.prefix = prefix;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof IRCChannelUserMode)) {
return false;
}
IRCChannelUserMode other = (IRCChannelUserMode) o;
return (other.getNickPrefix() == this.getNickPrefix()) && (other.getType() == this.getType()) && (other.getClient().equals(this.getClient())) && (other.getChar() == this.getChar());
}

@Override
public char getNickPrefix() {
return this.prefix;
}

@Override
public int hashCode() {
return Objects.hash(this.getClient(), this.getChar(), this.getType(), this.getNickPrefix());
}

@Nonnull
@Override
public String toString() {
Expand All @@ -84,12 +99,26 @@ static class IRCChannelMode extends IRCModeBase implements ChannelMode {
this.type = type;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof IRCChannelMode)) {
return false;
}
IRCChannelMode other = (IRCChannelMode) o;
return (other.getType() == this.getType()) && (other.getClient().equals(this.getClient())) && (other.getChar() == this.getChar());
}

@Nonnull
@Override
public Type getType() {
return this.type;
}

@Override
public int hashCode() {
return Objects.hash(this.getClient(), this.getChar(), this.type);
}

@Nonnull
@Override
public String toString() {
Expand All @@ -102,6 +131,20 @@ static class IRCUserMode extends IRCModeBase implements UserMode {
super(client, mode);
}

@Override
public boolean equals(Object o) {
if (!(o instanceof IRCUserMode)) {
return false;
}
IRCUserMode other = (IRCUserMode) o;
return (other.getClient().equals(this.getClient())) && (other.getChar() == this.getChar());
}

@Override
public int hashCode() {
return Objects.hash(this.getClient(), this.getChar());
}

@Nonnull
@Override
public String toString() {
Expand Down

0 comments on commit 9970b24

Please sign in to comment.