JAL-2759 First pass instantiate hiddenColumns collection in constructor
[jalview.git] / src / jalview / datamodel / HiddenColumnsCursor.java
index 3d82ee7..a875f87 100644 (file)
@@ -20,6 +20,7 @@
  */
 package jalview.datamodel;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicReference;
 
@@ -28,7 +29,7 @@ public class HiddenColumnsCursor
   // absolute position of first hidden column
   private int firstColumn;
 
-  private List<int[]> hiddenColumns;
+  private List<int[]> hiddenColumns = new ArrayList<>();
 
   // AtomicReference to hold the current region index and hidden column count
   // Could be done with synchronisation but benchmarking shows this way is 2x
@@ -70,7 +71,7 @@ public class HiddenColumnsCursor
           int hiddencount)
   {
     hiddenColumns = hiddenCols;
-    if ((hiddenCols != null) && (!hiddenCols.isEmpty()))
+    if (!hiddenCols.isEmpty())
     {
       firstColumn = hiddenColumns.get(0)[0];
       HiddenCursorPosition oldpos = cursorPos.get();
@@ -93,7 +94,7 @@ public class HiddenColumnsCursor
   protected void updateForDeletedRegion(List<int[]> hiddenCols)
   {
 
-    if ((hiddenCols != null) && (!hiddenCols.isEmpty()))
+    if (!hiddenCols.isEmpty())
     {
       // if there is a region to the right of the current region,
       // nothing changes; otherwise
@@ -116,18 +117,21 @@ public class HiddenColumnsCursor
   }
 
   /**
-   * Get the index of the region that column is within (if column is hidden) or
-   * which is to the right of column (if column is visible). If no hidden
-   * columns are to the right, will return size of hiddenColumns. If hidden
-   * columns is empty returns -1.
+   * Get the cursor pointing to the hidden region that column is within (if
+   * column is hidden) or which is to the right of column (if column is
+   * visible). If no hidden columns are to the right, returns a cursor pointing
+   * to an imaginary hidden region beyond the end of the hidden columns
+   * collection (this ensures the count of previous hidden columns is correct).
+   * If hidden columns is empty returns null.
    * 
    * @param column
    *          absolute position of a column in the alignment
-   * @return region index
+   * @return cursor pointing to hidden region containing the column (if hidden)
+   *         or to the right of the column (if visible)
    */
   protected HiddenCursorPosition findRegionForColumn(int column)
   {
-    if (hiddenColumns == null)
+    if (hiddenColumns.isEmpty())
     {
       return null;
     }
@@ -190,16 +194,16 @@ public class HiddenColumnsCursor
   }
 
   /**
-   * Get the number of hidden columns in regions before column i.e. excludes
-   * hidden columns in the region column is in, if any
+   * Get the cursor pointing to the hidden region just after a visible column
    * 
    * @param column
-   *          index of column in visible alignment
-   * @return
+   *          index of column in *visible* alignment (therefore by definition
+   *          column is visible)
+   * @return cursor pointing to hidden region to the right of the column
    */
-  protected HiddenCursorPosition getHiddenOffset(int column)
+  protected HiddenCursorPosition findRegionForVisColumn(int column)
   {
-    if (hiddenColumns == null)
+    if (hiddenColumns.isEmpty())
     {
       return null;
     }