*/
public void hideColumns(BitSet inserts)
{
+ hideColumns(inserts, 0, inserts.length() - 1);
+ }
+
+ /**
+ * Hide columns corresponding to the marked bits, within the range
+ * [start,end]. Entries in tohide which are outside [start,end] are ignored.
+ *
+ * @param tohide
+ * columns mapped to bits starting from zero
+ * @param start
+ * start of range to hide columns within
+ * @param end
+ * end of range to hide columns within
+ */
+ private void hideColumns(BitSet tohide, int start, int end)
+ {
try
{
LOCK.writeLock().lock();
- for (int firstSet = inserts
- .nextSetBit(0), lastSet = 0; firstSet >= 0; firstSet = inserts
+ for (int firstSet = tohide
+ .nextSetBit(start), lastSet = start; firstSet >= start
+ && lastSet <= end; firstSet = tohide
.nextSetBit(lastSet))
{
- lastSet = inserts.nextClearBit(firstSet);
- hideColumns(firstSet, lastSet - 1);
+ lastSet = tohide.nextClearBit(firstSet);
+ if (lastSet <= end)
+ {
+ hideColumns(firstSet, lastSet - 1);
+ }
+ else if (firstSet <= end)
+ {
+ hideColumns(firstSet, end);
+ }
}
cursor = new HiddenColumnsCursor(hiddenColumns);
} finally
/**
* Hide columns corresponding to the marked bits, within the range
* [start,end]. Entries in tohide which are outside [start,end] are ignored.
+ * NB Existing entries in [start,end] are cleared.
*
* @param tohide
* columns mapped to bits starting from zero
* @param end
* end of range to hide columns within
*/
- public void hideColumns(BitSet tohide, int start, int end)
+ public void clearAndHideColumns(BitSet tohide, int start, int end)
{
clearHiddenColumnsInRange(start, end);
-
- // make sure only bits between start and end are set
- if (!tohide.isEmpty())
- {
- tohide.clear(0, start);
- tohide.clear(Math.min(end + 1, tohide.length() + 1),
- tohide.length() + 1);
- }
-
- hideColumns(tohide);
+ hideColumns(tohide, start, end);
}
/**
}
inserts.and(sq.getInsertionsAsBits());
}
- hidden.hideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
+ hidden.clearAndHideColumns(inserts, ap.av.getSelectionGroup().getStartRes(),
ap.av.getSelectionGroup().getEndRes());
}
HiddenColumns h = new HiddenColumns();
HiddenColumns h2 = new HiddenColumns();
- BitSet tohide = new BitSet(21);
+ BitSet tohide = new BitSet(25);
h.hideColumns(tohide);
assertTrue(h.equals(h2));
tohide.set(3, 6);
tohide.set(9);
tohide.set(15, 21);
- h.hideColumns(tohide, 5, 23);
+ h.clearAndHideColumns(tohide, 5, 23);
h2.hideColumns(5, 5);
h2.hideColumns(9, 9);
tohide.clear();
tohide.set(41);
- h.hideColumns(tohide, 23, 30);
+ h.clearAndHideColumns(tohide, 23, 30);
assertTrue(h.equals(h2));
assertEquals(h.getSize(), h2.getSize());
tohide.set(41);
- h.hideColumns(tohide, 30, 45);
+ h.clearAndHideColumns(tohide, 30, 45);
h2.hideColumns(41, 41);
assertTrue(h.equals(h2));
assertEquals(h.getSize(), h2.getSize());
tohide.clear();
tohide.set(25, 28);
- h.hideColumns(tohide, 17, 50);
+ h.clearAndHideColumns(tohide, 17, 50);
h2 = new HiddenColumns();
h2.hideColumns(5, 5);
h2.hideColumns(9, 9);
tohide = new BitSet();
// all unhidden if tohide is empty and range covers hidden
- hc.hideColumns(tohide, 1, 70);
+ hc.clearAndHideColumns(tohide, 1, 70);
assertTrue(!hc.hasHiddenColumns());
assertEquals(0, hc.getSize());
assertEquals(25, hc.getSize());
// but not if range does not cover hidden
- hc.hideColumns(tohide, 23, 40);
+ hc.clearAndHideColumns(tohide, 23, 40);
assertTrue(hc.hasHiddenColumns());
assertEquals(25, hc.getSize());
// and partial unhide if range partially covers
- hc.hideColumns(tohide, 1, 17);
+ hc.clearAndHideColumns(tohide, 1, 17);
Iterator<int[]> it = hc.iterator();
assertTrue(it.hasNext());
int[] region = it.next();