JAL-4130 Avoid using thenComparing of the Comparator interface
authorMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 22 Feb 2023 13:27:43 +0000 (14:27 +0100)
committerMateusz Warowny <mmzwarowny@dundee.ac.uk>
Wed, 22 Feb 2023 13:27:43 +0000 (14:27 +0100)
src/jalview/ws2/gui/WebServicesMenuManager.java

index c9b53a9..592a370 100644 (file)
@@ -120,9 +120,13 @@ public class WebServicesMenuManager
 
   private void addOneshotEntries(List<WebService<?>> services, JMenu menu)
   {
-    services.sort(Comparator
-        .<WebService<?>, String> comparing(s -> s.getUrl().toString())
-        .thenComparing(WebService::getName));
+    // Workaround. Comparator methods not working in j2s
+    services.sort((ws1, ws2) -> {
+      var res = ws1.getUrl().toString().compareTo(ws2.getUrl().toString());
+      if (res == 0)
+        res = ws1.getName().compareTo(ws2.getName());
+      return res;
+    });
     URL lastHost = null;
     for (WebService<?> service : services)
     {
@@ -291,9 +295,12 @@ public class WebServicesMenuManager
     private void buildAlternativesMenu(List<WebService<?>> services)
     {
       var menu = alternativesMenu;
-      services.sort(Comparator
-          .<WebService<?>, String> comparing(s -> s.getUrl().toString())
-          .thenComparing(s -> s.getName()));
+      services.sort((ws1, ws2) -> {
+        var res = ws1.getUrl().toString().compareTo(ws2.getUrl().toString());
+        if (res == 0)
+          res = ws1.getName().compareTo(ws2.getName());
+        return res;
+      });
       URL lastHost = null;
       for (var service : services)
       {