{
return selected.get(0) ? 0 : selected.nextSetBit(0);
}
+
+ /**
+ * @return a series of selection intervals along the range
+ */
+ public List<int[]> getRanges()
+ {
+ List<int[]> rlist = new ArrayList<int[]>();
+ if (selected.isEmpty())
+ {
+ return rlist;
+ }
+ int next = selected.nextSetBit(0), clear = -1;
+ while (next != -1)
+ {
+ clear = selected.nextClearBit(next);
+ rlist.add(new int[] { next, clear - 1 });
+ next = selected.nextSetBit(clear);
+ }
+ return rlist;
+ }
}
IntList selected = new IntList();
}
/**
+ * @return list of int arrays containing start and end column position for
+ * runs of selected columns ordered from right to left.
+ */
+ public List<int[]> getSelectedRanges()
+ {
+ return selected.getRanges();
+ }
+
+ /**
*
* @param col
* index to search for in column selection
public void hideSelectedColumns()
{
- while (!selected.isEmpty())
- {
- int column = selected.elementAt(0);
- hideColumns(column);
+ synchronized (selected) {
+ for (int[] selregions:selected.getRanges())
+ {
+ hideColumns(selregions[0], selregions[1]);
+ }
+ selected.clear();
}
}
}
/**
+ * Test the method that gets runs of selected columns ordered by column. If
+ * this fails, HideSelectedColumns may also fail
+ */
+ @Test(groups = { "Functional" })
+ public void testgetSelectedRanges()
+ {
+ ColumnSelection cs = new ColumnSelection();
+ int[] sel = { 2, 3, 4, 7, 8, 9, 20, 21, 22 };
+ for (int col : sel)
+ {
+ cs.addElement(col);
+ }
+ List<int[]> range;
+ range = cs.getSelectedRanges();
+ assertEquals(3, range.size());
+ assertEquals("[2, 4]", Arrays.toString(range.get(0)));
+ assertEquals("[7, 9]", Arrays.toString(range.get(1)));
+ assertEquals("[20, 22]", Arrays.toString(range.get(2)));
+ cs.addElement(0);
+ cs.addElement(1);
+ range = cs.getSelectedRanges();
+ assertEquals(3, range.size());
+ assertEquals("[0, 4]", Arrays.toString(range.get(0)));
+ }
+
+ /**
* Test the method that reveals a range of hidden columns given the start
* column of the range
*/