JAL-2759 Simplified HiddenColumns constructor after review
[jalview.git] / src / jalview / datamodel / HiddenColumns.java
index 93791e4..d1345e3 100644 (file)
@@ -42,7 +42,8 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
  * 
  * - getVisibleColsIterator: iterates over the visible *columns*
  * 
- * For performance reasons, provide bounds where possible.
+ * For performance reasons, provide bounds where possible. Note that column
+ * numbering begins at 0 throughout this class.
  * 
  * @author kmourao
  *
@@ -68,7 +69,7 @@ public class HiddenColumns
    * list of hidden column [start, end] ranges; the list is maintained in
    * ascending start column order
    */
-  private ArrayList<int[]> hiddenColumns;
+  private List<int[]> hiddenColumns;
 
   /**
    * Constructor
@@ -93,29 +94,7 @@ public class HiddenColumns
    */
   public HiddenColumns(HiddenColumns copy)
   {
-    try
-    {
-      LOCK.writeLock().lock();
-      numColumns = 0;
-      if (copy != null)
-      {
-        if (copy.hiddenColumns != null)
-        {
-          hiddenColumns = new ArrayList<>();
-          Iterator<int[]> it = copy.iterator();
-          while (it.hasNext())
-          {
-            int[] region = it.next();
-            hiddenColumns.add(region);
-            numColumns += region[1] - region[0] + 1;
-          }
-          cursor.resetCursor(hiddenColumns);
-        }
-      }
-    } finally
-    {
-      LOCK.writeLock().unlock();
-    }
+    this(copy, Integer.MIN_VALUE, Integer.MAX_VALUE, 0);
   }
 
   /**
@@ -483,14 +462,14 @@ public class HiddenColumns
       markHiddenRegions(hidden);
       hidden.andNot(gaps);
       hiddenColumns = null;
-      this.hideMarkedBits(hidden);
+      this.hideColumns(hidden);
 
       // for each sequence in the alignment, except the profile sequence,
       // insert gaps corresponding to each hidden region but where each hidden
       // column region is shifted backwards by the number of preceding visible
       // gaps update hidden columns at the same time
       Iterator<int[]> regions = hiddenColumns.iterator();
-      ArrayList<int[]> newhidden = new ArrayList<>();
+      List<int[]> newhidden = new ArrayList<>();
 
       int numGapsBefore = 0;
       int gapPosition = 0;
@@ -1277,7 +1256,7 @@ public class HiddenColumns
    * @param inserts
    *          - columns map to bits starting from zero
    */
-  public void hideMarkedBits(BitSet inserts)
+  public void hideColumns(BitSet inserts)
   {
     try
     {
@@ -1384,7 +1363,8 @@ public class HiddenColumns
    * 
    * @param res
    *          visible residue position, unadjusted for hidden columns
-   * @return region as [start,end] or null if no matching region is found
+   * @return region as [start,end] or null if no matching region is found. If
+   *         res is adjacent to two regions, returns the left region.
    */
   public int[] getRegionWithEdgeAtRes(int res)
   {