You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2021/12/07 11:48:29 UTC

[sling-org-apache-sling-testing-osgi-mock] branch master updated: cosmetic: re-use Comparator instance

This is an automated email from the ASF dual-hosted git repository.

sseifert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git


The following commit(s) were added to refs/heads/master by this push:
     new 705a05c  cosmetic: re-use Comparator<ServiceReference> instance
705a05c is described below

commit 705a05c7b082532dbdf5350fe2093d9ce001d3b9
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Tue Dec 7 12:46:57 2021 +0100

    cosmetic: re-use Comparator<ServiceReference> instance
---
 .../sling/testing/mock/osgi/MockBundleContext.java       | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
index f2b5e41..d7867c9 100644
--- a/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
+++ b/core/src/main/java/org/apache/sling/testing/mock/osgi/MockBundleContext.java
@@ -82,6 +82,14 @@ class MockBundleContext implements BundleContext {
 
     private static final Logger log = LoggerFactory.getLogger(MockBundleContext.class);
 
+    private static final Comparator<ServiceReference> SR_COMPARATOR_HIGHEST_RANKING_FIRST = new Comparator<ServiceReference>() {
+        @Override
+        public int compare(ServiceReference o1, ServiceReference o2) {
+            // reverse sort order to get highest ranking first
+            return o2.compareTo(o1);
+        }
+    };
+
     public MockBundleContext() {
         log.debug("Creating MockBundleContext, bundleContext={}", this);
 
@@ -315,13 +323,7 @@ class MockBundleContext implements BundleContext {
          * https://docs.osgi.org/specification/osgi.core/7.0.0/framework.api.html#org.osgi.framework.BundleContext.getServiceReferences-String-String-
          * for backward compatibility with previous implementation of osgi-mock we stick with highest-ranking first here
          */
-        Set<ServiceReference> result = new TreeSet<>(new Comparator<ServiceReference>() {
-            @Override
-            public int compare(ServiceReference o1, ServiceReference o2) {
-                // reverse sort order to get highest ranking first
-                return o2.compareTo(o1);
-            }
-        });
+        Set<ServiceReference> result = new TreeSet<>(SR_COMPARATOR_HIGHEST_RANKING_FIRST);
         for (MockServiceRegistration serviceRegistration : this.registeredServices) {
             if (serviceRegistration.matches(clazz, filter)) {
                 result.add(serviceRegistration.getReference());