*/
package jalview.util;
+import java.util.Objects;
+
public class ArrayUtils
{
/**
}
}
}
+
+ /**
+ * Return the index of the first occurrence of the item in the array or -1 if
+ * the array doesn't contain the item.
+ *
+ * @param arr
+ * array to be searched
+ * @param item
+ * item to search for
+ * @return index of the first occurrence of the item or -1 if not found
+ */
+ public static int indexOf(Object[] arr, Object item)
+ {
+ for (int i = 0; i < arr.length; i++)
+ {
+ if (Objects.equals(arr[i], item))
+ return i;
+ }
+ return -1;
+ }
}
import java.util.concurrent.TimeUnit;
import jalview.bin.Cache;
+import jalview.util.ArrayUtils;
import jalview.ws.params.ArgumentI;
import jalview.ws2.actions.api.TaskEventListener;
import jalview.ws2.actions.api.TaskI;
private void updateGlobalStatus()
{
JobStatus newStatus = taskStatus;
- int currentPrecedence = getPrecedenceOf(newStatus);
+ int currentPrecedence = ArrayUtils.indexOf(statusPrecedence, newStatus);
for (BaseJob job : jobs)
{
JobStatus status = job.getStatus();
- int jobPrecedence = getPrecedenceOf(status);
+ int jobPrecedence = ArrayUtils.indexOf(statusPrecedence, status);
if (currentPrecedence < jobPrecedence)
{
currentPrecedence = jobPrecedence;
JobStatus.SERVER_ERROR
};
- /**
- * @param status
- * status to find the precedence of
- * @return precedence of the status
- */
- private static int getPrecedenceOf(JobStatus status)
- {
- final int len = statusPrecedence.length;
- for (int i = 0; i < len; i++)
- {
- if (statusPrecedence[i] == status)
- {
- return i;
- }
- }
- return -1;
- }
-
@Override
public void cancel()
{