// make sure only bits between start and end are set
if (!tohide.isEmpty())
{
- tohide.clear(0, start - 1);
- tohide.clear(Math.min(end + 1, tohide.length() - 1),
- tohide.length() - 1);
+ tohide.clear(0, start);
+ tohide.clear(Math.min(end + 1, tohide.length() + 1),
+ tohide.length() + 1);
}
hideColumns(tohide);
{
LOCK.writeLock().lock();
- HiddenCursorPosition pos = cursor.findRegionForColumn(start);
- int index = pos.getRegionIndex();
- int startindex = index; // first index in hiddenColumns to remove
-
- if (index != -1 && index != hiddenColumns.size())
+ if (!hiddenColumns.isEmpty())
{
- // regionIndex is the region which either contains start
- // or lies to the right of start
- int[] region = hiddenColumns.get(index);
- if (region[0] < start && region[1] >= start)
+ HiddenCursorPosition pos = cursor.findRegionForColumn(start);
+ int index = pos.getRegionIndex();
+ int startindex = index; // first index in hiddenColumns to remove
+
+ if (index != -1 && index != hiddenColumns.size())
{
- // region contains start, truncate so that it ends just before start
- region[1] = start - 1;
- startindex++;
+ // regionIndex is the region which either contains start
+ // or lies to the right of start
+ int[] region = hiddenColumns.get(index);
+ if (region[0] < start && region[1] >= start)
+ {
+ // region contains start, truncate so that it ends just before start
+ region[1] = start - 1;
+ startindex++;
+ }
}
- }
-
- pos = cursor.findRegionForColumn(end);
- index = pos.getRegionIndex();
- int endindex = index - 1; // last index in hiddenColumns to remove
- if (index != -1 && index != hiddenColumns.size())
- {
- // regionIndex is the region which either contains end
- // or lies to the right of end
- int[] region = hiddenColumns.get(index);
- if (region[0] <= end && region[1] > end)
+ pos = cursor.findRegionForColumn(end);
+ index = pos.getRegionIndex();
+ int endindex = index - 1; // last index in hiddenColumns to remove
+
+ if (index != -1 && index != hiddenColumns.size())
{
- // region contains end, truncate so that it starts just after end
- region[0] = end + 1;
+ // regionIndex is the region which either contains end
+ // or lies to the right of end
+ int[] region = hiddenColumns.get(index);
+ if (region[0] <= end && region[1] > end)
+ {
+ // region contains end, truncate so that it starts just after end
+ region[0] = end + 1;
+ }
}
+
+ hiddenColumns.subList(startindex, endindex + 1).clear();
+ cursor.resetCursor(hiddenColumns);
+ numColumns = 0;
}
-
- hiddenColumns.subList(startindex, endindex + 1).clear();
- cursor.resetCursor(hiddenColumns);
- numColumns = 0;
} finally
{
LOCK.writeLock().unlock();
}
@Test(groups = "Functional")
- public void testHideColumns_BitSet()
+ public void testHideColumns_BitSet_range()
{
HiddenColumns h = new HiddenColumns();
HiddenColumns h2 = new HiddenColumns();
h.hideColumns(tohide);
assertTrue(h.equals(h2));
- // NB in hideMarkedBits, the last bit is not set to hidden
+ // when setting bitset, first param is invlusive, second exclusive
tohide.set(3, 6);
tohide.set(9);
- tohide.set(19, 21);
- h.hideColumns(tohide);
+ tohide.set(15, 21);
+ h.hideColumns(tohide, 5, 23);
- h2.hideColumns(3, 5);
+ h2.hideColumns(5, 5);
h2.hideColumns(9, 9);
- h2.hideColumns(19, 20);
+ h2.hideColumns(15, 20);
+ assertTrue(h.equals(h2));
+
+ tohide.clear();
+ tohide.set(41);
+ h.hideColumns(tohide, 23, 30);
+ assertTrue(h.equals(h2));
+
+ tohide.set(41);
+ h.hideColumns(tohide, 30, 45);
+ h2.hideColumns(41, 41);
assertTrue(h.equals(h2));
+
+ tohide.clear();
+ tohide.set(25, 28);
+ h.hideColumns(tohide, 17, 50);
+ h2 = new HiddenColumns();
+ h2.hideColumns(17, 20);
+ h2.hideColumns(25, 27);
+ h2.hideColumns(41, 41);
}
@Test(groups = "Functional")