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:21:08 UTC
[sling-org-apache-sling-testing-osgi-mock] 01/02: reuse comparator instance for comparing service references
This is an automated email from the ASF dual-hosted git repository.
sseifert pushed a commit to branch experimental/WTES-69-diagnosis
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-osgi-mock.git
commit ffcb027cb7431a3b74f083a1ea0ece7a7688c71f
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Tue Dec 7 12:16:50 2021 +0100
reuse comparator instance for comparing service references
---
.../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 4f4620e..df35c6a 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);
@@ -321,13 +329,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());