JAL-3070 use object identity equivalence for lists of workers and Cache.log.debug...
authorJim Procter <jprocter@issues.jalview.org>
Thu, 10 Oct 2019 14:13:38 +0000 (15:13 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 10 Oct 2019 14:13:38 +0000 (15:13 +0100)
src/jalview/workers/AlignCalcManager.java

index 3a3dc44..1967375 100644 (file)
@@ -78,6 +78,19 @@ public class AlignCalcManager implements AlignCalcManagerI
     canUpdate = new HashSet<>();
   }
 
+  private static boolean listContains(List<AlignCalcWorkerI> upd,
+          AlignCalcWorkerI worker)
+  {
+    // avoid use of 'Contains' in case
+    for (AlignCalcWorkerI _otherworker : upd)
+    {
+      if (_otherworker == upd)
+      {
+        return true;
+      }
+    }
+    return false;
+  }
   @Override
   public void notifyStart(AlignCalcWorkerI worker)
   {
@@ -91,18 +104,16 @@ public class AlignCalcManager implements AlignCalcManagerI
       }
       synchronized (upd)
       {
-        // avoid use of 'Contains' in case
-        for (AlignCalcWorkerI _otherworker : upd)
+        if (listContains(upd, worker))
         {
-          if (_otherworker == upd)
-          {
-            Cache.log.debug(
+          Cache.log.debug(
                     "Ignoring second call to notifyStart for worker "
                             + worker);
-            return;
-          }
         }
+        else
+        {
           upd.add(worker);
+        }
       }
     }
   }
@@ -139,7 +150,7 @@ public class AlignCalcManager implements AlignCalcManagerI
   {
     synchronized (inProgress)
     {
-      if (inProgress.contains(worker))
+      if (listContains(inProgress, worker))
       {
         return false; // worker is already working, so ask caller to wait around
       }
@@ -156,7 +167,7 @@ public class AlignCalcManager implements AlignCalcManagerI
   {
     synchronized (inProgress)
     {
-      // System.err.println("Worker " + worker + " marked as complete.");
+      Cache.log.debug("Worker " + worker + " marked as complete.");
       inProgress.remove(worker);
       List<AlignCalcWorkerI> upd = updating.get(worker.getClass());
       if (upd != null)
@@ -224,7 +235,7 @@ public class AlignCalcManager implements AlignCalcManagerI
   {
     synchronized (restartable)
     {
-      if (!restartable.contains(worker))
+      if (!listContains(restartable, worker))
       {
         restartable.add(worker);
       }