Index: core/src/main/java/org/springframework/osgi/service/importer/support/ServiceReferenceDelegate.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/ServiceReferenceDelegate.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/ServiceReferenceDelegate.java (working copy) @@ -58,4 +58,9 @@ public String toString() { return "ServiceReference wrapper for " + delegate.getServiceReference(); } + + public int compareTo(Object reference) { + return this.delegate.getServiceReference().compareTo( + (((ServiceReferenceDelegate) reference).delegate.getServiceReference())); + } } Index: core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/SwappingServiceReferenceProxy.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/SwappingServiceReferenceProxy.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/SwappingServiceReferenceProxy.java (working copy) @@ -80,4 +80,8 @@ public int hashCode() { return HASH_CODE + delegate.hashCode(); } + + public int compareTo(Object reference) { + return this.delegate.compareTo(((SwappingServiceReferenceProxy) reference).delegate); + } } Index: core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/StaticServiceReferenceProxy.java =================================================================== --- core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/StaticServiceReferenceProxy.java (revision 13141) +++ core/src/main/java/org/springframework/osgi/service/importer/support/internal/aop/StaticServiceReferenceProxy.java (working copy) @@ -81,4 +81,8 @@ public int hashCode() { return HASH_CODE + target.hashCode(); } + + public int compareTo(Object reference) { + return this.target.compareTo(((StaticServiceReferenceProxy) reference).target); + } } Index: mock/src/main/java/org/springframework/osgi/mock/MockServiceReference.java =================================================================== --- mock/src/main/java/org/springframework/osgi/mock/MockServiceReference.java (revision 13141) +++ mock/src/main/java/org/springframework/osgi/mock/MockServiceReference.java (working copy) @@ -203,4 +203,35 @@ return "mock service reference [owning bundle id=" + bundle.hashCode() + "|props : " + properties + "]"; } + public int compareTo(Object reference) { + ServiceReference other = (ServiceReference)reference; + + Integer thisRankingInteger = (Integer)this.properties.get(Constants.SERVICE_RANKING); + int thisRanking = (thisRankingInteger instanceof Integer)?((Integer)thisRankingInteger).intValue() : 0; + + Integer otherRankingInteger = (Integer)other.getProperty(Constants.SERVICE_RANKING); + int otherRanking = (otherRankingInteger instanceof Integer)?((Integer)otherRankingInteger).intValue() : 0; + + int result = otherRanking - thisRanking; + if(result == 0) { + Long thisIdLong = (Long)this.properties.get(Constants.SERVICE_RANKING); + long thisId = (thisIdLong instanceof Long)?((Long)thisIdLong).longValue() : 0; + + Long otherIdLong = (Long)other.getProperty(Constants.SERVICE_RANKING); + long otherId = (otherIdLong instanceof Long)?((Long)otherIdLong).longValue() : 0; + + if(thisId < otherId) { + result = -1; + } + else if(otherId < thisId) { + result = 1; + } + else { + result = 0; + } + } + + return result; + } + }