add hash/equals impl to Topic impl
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.redis.listener;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Channel topic implementation (maps to a Redis channel).
|
||||
*
|
||||
@@ -30,6 +32,7 @@ public class ChannelTopic implements Topic {
|
||||
* @param name
|
||||
*/
|
||||
public ChannelTopic(String name) {
|
||||
Assert.notNull(name, "a valid topic is required");
|
||||
this.channelName = name;
|
||||
}
|
||||
|
||||
@@ -41,4 +44,32 @@ public class ChannelTopic implements Topic {
|
||||
public String getTopic() {
|
||||
return channelName;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return channelName.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof ChannelTopic)) {
|
||||
return false;
|
||||
}
|
||||
ChannelTopic other = (ChannelTopic) obj;
|
||||
if (channelName == null) {
|
||||
if (other.channelName != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!channelName.equals(other.channelName)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.redis.listener;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Pattern topic (matching multiple channels).
|
||||
*
|
||||
@@ -25,10 +27,39 @@ public class PatternTopic implements Topic {
|
||||
private final String channelPattern;
|
||||
|
||||
public PatternTopic(String pattern) {
|
||||
Assert.notNull(pattern, "a valid topic is required");
|
||||
this.channelPattern = pattern;
|
||||
}
|
||||
|
||||
public String getTopic() {
|
||||
return channelPattern;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return channelPattern.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof PatternTopic)) {
|
||||
return false;
|
||||
}
|
||||
PatternTopic other = (PatternTopic) obj;
|
||||
if (channelPattern == null) {
|
||||
if (other.channelPattern != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!channelPattern.equals(other.channelPattern)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user