This is an automated email from the ASF dual-hosted git repository. pauls pushed a commit to branch issues/SLING-10280 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git
commit 2b2d3adf8f71f4de2648b3770642ecde733f2c13 Author: Karl Pauls <[email protected]> AuthorDate: Thu Apr 8 12:30:31 2021 +0200 SLING-10280: use string compareTo to compare mappings --- .../apache/sling/serviceusermapping/Mapping.java | 27 ++++------------------ 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/main/java/org/apache/sling/serviceusermapping/Mapping.java b/src/main/java/org/apache/sling/serviceusermapping/Mapping.java index 87608c0..9139f15 100644 --- a/src/main/java/org/apache/sling/serviceusermapping/Mapping.java +++ b/src/main/java/org/apache/sling/serviceusermapping/Mapping.java @@ -41,6 +41,8 @@ public class Mapping implements Comparable<Mapping> { private final Set<String> principalNames; + private final String identity; + /** * Creates a mapping entry for the entry specification of the form: * @@ -70,9 +72,11 @@ public class Mapping implements Comparable<Mapping> { if (colon < 0 || colon > equals) { this.serviceName = spec.substring(0, equals); this.subServiceName = null; + this.identity = this.serviceName; } else { this.serviceName = spec.substring(0, colon); this.subServiceName = spec.substring(colon + 1, equals); + this.identity = this.serviceName + "-" + this.subServiceName; } String s = spec.substring(equals + 1); @@ -162,27 +166,6 @@ public class Mapping implements Comparable<Mapping> { if (o == null) { return -1; } - - int result = compare(this.serviceName, o.serviceName); - if (result == 0) { - result = compare(this.subServiceName, o.subServiceName); - } - return result; - } - - private int compare(String str1, String str2) { - if (str1 == str2) { - return 0; - } - - if (str1 == null) { - return -1; - } - - if (str2 == null) { - return 1; - } - - return str1.hashCode() - str2.hashCode(); + return this.identity.compareTo(o.identity); } }
