alien11689 commented on code in PR #92:
URL: https://github.com/apache/aries-rsa/pull/92#discussion_r3143835508


##########
discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/Interest.java:
##########
@@ -32,67 +30,29 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@SuppressWarnings("deprecation")
 public class Interest {
     private static final Logger LOG = LoggerFactory.getLogger(Interest.class);
 
-    private final ServiceReference<?> sref;
     private final List<String> scopes;
-    private final EndpointEventListener epListener;
+    private final EndpointEventListener listener;
 
-    public Interest(ServiceReference<?> sref) {
-        this(sref, null);
-    }
-
-    public Interest(ServiceReference<?> sref, EndpointEventListener 
epListener) {
-        this.sref = sref;
+    public Interest(ServiceReference<?> sref, EndpointEventListener listener) {
         this.scopes = 
StringPlus.normalize(sref.getProperty(ENDPOINT_LISTENER_SCOPE));
-        this.epListener = epListener;
-    }
-
-    public List<String> getScopes() {
-        return scopes;
+        this.listener = listener;
     }
 
     public void notifyListener(EndpointEvent event) {
         EndpointDescription endpoint = event.getEndpoint();
-        Optional<String> currentScope = getFirstMatch(endpoint);
-        if (currentScope.isPresent()) {
-            LOG.debug("Matched {} against {}", endpoint, currentScope);
-            String scope = currentScope.get();
-            LOG.info("Calling endpointchanged on class {} for filter {}, type 
{}, endpoint {} ",
-                epListener, scope, event.getType(), endpoint);
-            epListener.endpointChanged(event, scope);
+        String scope = 
scopes.stream().filter(endpoint::matches).findFirst().orElse(null);
+        if (scope != null) {
+            LOG.info("Calling endpointChanged on {} for filter {}, type {}, 
endpoint {}",
+                listener, scope, event.getType(), endpoint);
+            listener.endpointChanged(event, scope);
         }
     }
 
-    private Optional<String> getFirstMatch(EndpointDescription endpoint) {
-        return scopes.stream().filter(endpoint::matches).findFirst();
-    }
-
-    @Override
-    public int hashCode() {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ((sref == null) ? 0 : sref.hashCode());
-        return result;
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj)
-            return true;
-        if (obj == null)
-            return false;
-        if (getClass() != obj.getClass())
-            return false;
-        Interest other = (Interest) obj;
-        return Objects.equals(sref, other.sref);
-    }
-
     @Override
     public String toString() {
-        return "Interest [scopes=" + scopes + ", epListener=" + 
epListener.getClass() + "]";
+        return "Interest [scopes=" + scopes + ", epListener=" + 
listener.getClass() + "]";

Review Comment:
   let's rename also epListener in the string



##########
discovery/zookeeper/src/main/java/org/apache/aries/rsa/discovery/zookeeper/Interest.java:
##########
@@ -32,67 +30,29 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-@SuppressWarnings("deprecation")
 public class Interest {
     private static final Logger LOG = LoggerFactory.getLogger(Interest.class);
 
-    private final ServiceReference<?> sref;
     private final List<String> scopes;
-    private final EndpointEventListener epListener;
+    private final EndpointEventListener listener;
 
-    public Interest(ServiceReference<?> sref) {
-        this(sref, null);
-    }
-
-    public Interest(ServiceReference<?> sref, EndpointEventListener 
epListener) {
-        this.sref = sref;
+    public Interest(ServiceReference<?> sref, EndpointEventListener listener) {
         this.scopes = 
StringPlus.normalize(sref.getProperty(ENDPOINT_LISTENER_SCOPE));
-        this.epListener = epListener;
-    }
-
-    public List<String> getScopes() {
-        return scopes;
+        this.listener = listener;
     }
 
     public void notifyListener(EndpointEvent event) {
         EndpointDescription endpoint = event.getEndpoint();
-        Optional<String> currentScope = getFirstMatch(endpoint);
-        if (currentScope.isPresent()) {
-            LOG.debug("Matched {} against {}", endpoint, currentScope);
-            String scope = currentScope.get();
-            LOG.info("Calling endpointchanged on class {} for filter {}, type 
{}, endpoint {} ",
-                epListener, scope, event.getType(), endpoint);
-            epListener.endpointChanged(event, scope);
+        String scope = 
scopes.stream().filter(endpoint::matches).findFirst().orElse(null);

Review Comment:
   let's use optional futher
   ```
   scopes.stream().filter(endpoint::matches).findFirst().ifPresent(scope -> 
{...})
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to