JAL-2591 updated HiddenColumns::findHiddenRegionPositions + test
[jalview.git] / src / jalview / datamodel / HiddenColumns.java
index 9722c0a..1e1a58b 100644 (file)
@@ -273,39 +273,41 @@ public class HiddenColumns implements Iterable<int[]>
   }
 
   /**
-   * Use this method to determine where the next hiddenRegion starts
+   * Use this method to determine the set of hiddenRegion start positions
    * 
-   * @param hiddenRegion
-   *          index of hidden region (counts from 0)
-   * @return column number in visible view
+   * @return list of column number in visible view where hidden regions start
    */
-  public int findHiddenRegionPosition(int hiddenRegion)
+  public List<Integer> findHiddenRegionPositions()
   {
     try
     {
       lock.readLock().lock();
-      int result = 0;
-      if (hiddenColumns != null)
+      List<Integer> positions = new ArrayList<>(
+              hiddenColumns.size());
+
+      positions.add(hiddenColumns.elementAt(0)[0]);
+      for (int i = 1; i < hiddenColumns.size(); ++i)
       {
-        int index = 0;
-        int gaps = 0;
-        do
+
+        int result = 0;
+        if (hiddenColumns != null)
         {
-          int[] region = hiddenColumns.elementAt(index);
-          if (hiddenRegion == 0)
+          int index = 0;
+          int gaps = 0;
+          do
           {
-            return region[0];
-          }
-
-          gaps += region[1] + 1 - region[0];
-          result = region[1] + 1;
-          index++;
-        } while (index <= hiddenRegion);
+            int[] region = hiddenColumns.elementAt(index);
+            gaps += region[1] + 1 - region[0];
+            result = region[1] + 1;
+            index++;
+          } while (index <= i);
 
-        result -= gaps;
+          result -= gaps;
+        }
+        positions.add(result);
       }
 
-      return result;
+      return positions;
     }
     finally
     {