jhutchison commented on a change in pull request #6493:
URL: https://github.com/apache/geode/pull/6493#discussion_r635356997



##########
File path: 
geode-apis-compatible-with-redis/src/main/java/org/apache/geode/redis/internal/pubsub/Subscriptions.java
##########
@@ -67,6 +67,34 @@ boolean exists(Object channelOrPattern, Client client) {
         .collect(Collectors.toList());
   }
 
+  public List<byte[]> findChannelNames() {
+
+    return findChannels()
+        .stream()
+        .map(subscription -> (ChannelSubscription) subscription)
+        .map(ChannelSubscription::getSubscriptionName)
+        .distinct()
+        .collect(Collectors.toList());
+  }
+
+  public List<byte[]> findChannelNames(byte[] pattern) {
+    GlobPattern globPattern = new GlobPattern(new String(pattern));
+
+    return findChannels()
+        .stream()
+        .map(subscription -> (ChannelSubscription) subscription)
+        .filter(subscription -> globPattern.matches(new 
String(subscription.getSubscriptionName())))
+        .map(ChannelSubscription::getSubscriptionName)
+        .distinct()
+        .collect(Collectors.toList());
+  }
+
+  private List<Subscription> findChannels() {
+    return subscriptions.stream()
+        .filter(subscription -> subscription instanceof ChannelSubscription)
+        .collect(Collectors.toList());

Review comment:
       returning the stream makes sense, thanks. I like the idea of the return 
type of the findChannels method returning a Stream<ChannelSubscription>,  the 
downside is that the compiler makes me add this line to do that : 
`.map(subscription -> (ChannelSubscription) subscription);` 
   
   so the whole thing ends up reading:  `  return subscriptions.stream()
           .filter(subscription -> subscription instanceof ChannelSubscription)
           .map(subscription -> (ChannelSubscription) subscription);`
   
   which then seems a little confusing... not sure which is better?  If you 
don't have a strong opinion, I would lean towards returning the interface and 
not casting after filtering in the stream... 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to