You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2021/04/08 10:41:54 UTC

[sling-org-apache-sling-serviceusermapper] branch master updated: SLING-10280: use string compareTo to compare mappings (#4)

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

pauls pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-serviceusermapper.git


The following commit(s) were added to refs/heads/master by this push:
     new eb1a3e2  SLING-10280: use string compareTo to compare mappings (#4)
eb1a3e2 is described below

commit eb1a3e239de08356b3bee8da4effd9f5bd6a742d
Author: Karl Pauls <pa...@apache.org>
AuthorDate: Thu Apr 8 12:41:48 2021 +0200

    SLING-10280: use string compareTo to compare mappings (#4)
---
 .../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);
     }
 }