From: Mateusz Warowny Date: Tue, 23 Nov 2021 13:50:59 +0000 (+0100) Subject: JAL-3878 Add methods to get and remove workers by their calc name. X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=973b8dca30c72d52f3ed4542b88c378a5ef52ffa;p=jalview.git JAL-3878 Add methods to get and remove workers by their calc name. --- diff --git a/src/jalview/api/AlignCalcManagerI2.java b/src/jalview/api/AlignCalcManagerI2.java index 0bd6c3c..36bcda2 100644 --- a/src/jalview/api/AlignCalcManagerI2.java +++ b/src/jalview/api/AlignCalcManagerI2.java @@ -32,7 +32,13 @@ public interface AlignCalcManagerI2 * {@ink Class#equals(Object)} rather than {@code instanceof}. */ List getWorkersOfClass(Class cls); - + + /** + * Returns the list of all workers for the given name or an empty list + * if there are none. + */ + List getWorkersForName(String name); + /** * Removes the worker from the scheduler. It does not cancel workers * already scheduled for execution. @@ -50,7 +56,12 @@ public interface AlignCalcManagerI2 default void removeWorkersForAnnotation(AlignmentAnnotation annot) { removeWorkerForAnnotation(annot); } - + + /** + * Removes all workers with matching name. + */ + void removeWorkersForName(String name); + /** * Removes all workers of a given class. The classes are compared using * {@link Class#equals(Object)}. diff --git a/src/jalview/workers/AlignCalcManager2.java b/src/jalview/workers/AlignCalcManager2.java index 8d4796d..5c25668 100644 --- a/src/jalview/workers/AlignCalcManager2.java +++ b/src/jalview/workers/AlignCalcManager2.java @@ -312,6 +312,20 @@ public class AlignCalcManager2 implements AlignCalcManagerI2 } @Override + public List getWorkersForName(String name) + { + List collected = new ArrayList<>(); + for (var worker : getWorkers()) + { + if (worker.getCalcName().equals(name)) + { + collected.add(worker); + } + } + return collected; + } + + @Override public void removeWorker(AlignCalcWorkerI worker) { if (worker.isDeletable()) @@ -351,6 +365,21 @@ public class AlignCalcManager2 implements AlignCalcManagerI2 } @Override + public void removeWorkersForName(String name) + { + synchronized (registered) + { + for (var worker : getWorkers()) + { + if (worker.getCalcName().equals(name)) + { + removeWorker(worker); + } + } + } + } + + @Override public void disableWorker(AlignCalcWorkerI worker) { // Null pointer check might be needed