JAL-2674 Removing most calls to getHiddenColumnsCopy
[jalview.git] / src / jalview / datamodel / HiddenColumns.java
index a704b3c..eda8850 100644 (file)
@@ -186,6 +186,28 @@ public class HiddenColumns
     }
   }
 
+  /**
+   * Get the number of distinct hidden regions
+   * 
+   * @return number of regions
+   */
+  public int getNumberOfRegions()
+  {
+    try
+    {
+      LOCK.readLock().lock();
+      int num = 0;
+      if (hasHiddenColumns())
+      {
+        num = hiddenColumns.size();
+      }
+      return num;
+    } finally
+    {
+      LOCK.readLock().unlock();
+    }
+  }
+
   @Override
   public boolean equals(Object obj)
   {
@@ -1240,16 +1262,17 @@ public class HiddenColumns
     // but where each hidden column region is shifted backwards by the number of
     // preceding visible gaps
     // update hidden columns at the same time
-    ArrayList<int[]> regions = getHiddenColumnsCopy();
+    Iterator<int[]> regions = iterator();
     ArrayList<int[]> newhidden = new ArrayList<>();
 
     int numGapsBefore = 0;
     int gapPosition = 0;
-    for (int[] region : regions)
+    while (regions.hasNext())
     {
       // get region coordinates accounting for gaps
       // we can rely on gaps not being *in* hidden regions because we already
       // removed those
+      int[] region = regions.next();
       while (gapPosition < region[0])
       {
         gapPosition++;
@@ -1495,7 +1518,8 @@ public class HiddenColumns
   {
     if (hiddenColumns != null)
     {
-      return new BoundedHiddenColsIterator(0, hiddenColumns.size(), true);
+      int last = hiddenColumns.get(hiddenColumns.size() - 1)[1];
+      return new BoundedHiddenColsIterator(0, last, true);
     }
     else
     {
@@ -1550,13 +1574,6 @@ public class HiddenColumns
      *          lower bound to iterate from
      * @param upperBound
      *          upper bound to iterate to
-     * @param opt
-     *          Option.OVERLAP: regions which overlap [lowerBound,upperBound]
-     *          are included Option.START: regions which start in
-     *          [lowerBound,upperBound] are included
-     * @param useAbsolutePos
-     *          have bounds and return values with reference to absolute indices
-     *          (if false, use indices for visible columns)
      * @param useCopyCols
      *          whether to make a local copy of hiddenColumns for iteration (set
      *          to true if calling from outwith the HiddenColumns class)