JAL-2001 drop isSelected(int) in favour of original ‘contains(int)’ method
[jalview.git] / src / jalview / datamodel / ColumnSelection.java
index 9795570..c63b6cd 100644 (file)
@@ -169,6 +169,21 @@ public class ColumnSelection
       // lastly update the bitfield all at once
       selected.or(mask);
     }
+
+    public boolean isSelected(int column)
+    {
+      return selected.get(column);
+    }
+
+    public int getMaxColumn()
+    {
+      return selected.length() - 1;
+    }
+
+    public int getMinColumn()
+    {
+      return selected.get(0) ? 0 : selected.nextSetBit(0);
+    }
   }
 
   IntList selected = new IntList();
@@ -231,7 +246,8 @@ public class ColumnSelection
 
   /**
    * Returns a list of selected columns. The list contains no duplicates but is
-   * not necessarily ordered.
+   * not necessarily ordered. It also may include columns hidden from the
+   * current view
    */
   public List<Integer> getSelected()
   {
@@ -243,11 +259,11 @@ public class ColumnSelection
    * @param col
    *          index to search for in column selection
    * 
-   * @return true if Integer(col) is in selection.
+   * @return true if col is selected
    */
   public boolean contains(int col)
   {
-    return selected.contains(new Integer(col));
+    return (col > -1) ? selected.isSelected(col) : false;
   }
 
   /**
@@ -265,17 +281,11 @@ public class ColumnSelection
    */
   public int getMax()
   {
-    int max = -1;
-
-    for (int sel : getSelected())
+    if (selected.isEmpty())
     {
-      if (sel > max)
-      {
-        max = sel;
-      }
+      return -1;
     }
-
-    return max;
+    return selected.getMaxColumn();
   }
 
   /**
@@ -285,17 +295,11 @@ public class ColumnSelection
    */
   public int getMin()
   {
-    int min = 1000000000;
-
-    for (int sel : getSelected())
+    if (selected.isEmpty())
     {
-      if (sel < min)
-      {
-        min = sel;
-      }
+      return 1000000000;
     }
-
-    return min;
+    return selected.getMinColumn();
   }
 
   /**