diff --git a/src/main/java/org/springframework/data/redis/listener/ChannelTopic.java b/src/main/java/org/springframework/data/redis/listener/ChannelTopic.java index e231521de..aea34f5b0 100644 --- a/src/main/java/org/springframework/data/redis/listener/ChannelTopic.java +++ b/src/main/java/org/springframework/data/redis/listener/ChannelTopic.java @@ -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; + } +} \ No newline at end of file diff --git a/src/main/java/org/springframework/data/redis/listener/PatternTopic.java b/src/main/java/org/springframework/data/redis/listener/PatternTopic.java index 2fb54d00a..618c4e780 100644 --- a/src/main/java/org/springframework/data/redis/listener/PatternTopic.java +++ b/src/main/java/org/springframework/data/redis/listener/PatternTopic.java @@ -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; + } +} \ No newline at end of file