if (!hiddenColumns.isEmpty())
{
// set up cursor reset values
- HiddenCursorPosition cursorPos = cursor.findRegionForColumn(start);
+ HiddenCursorPosition cursorPos = cursor.findRegionForColumn(start,
+ false);
regionindex = cursorPos.getRegionIndex();
if (regionindex > 0)
if (!hiddenColumns.isEmpty())
{
- int regionIndex = cursor.findRegionForColumn(start)
+ int regionIndex = cursor.findRegionForColumn(start, false)
.getRegionIndex();
if (regionIndex != -1 && regionIndex != hiddenColumns.size())
if (!hiddenColumns.isEmpty())
{
- result += cursor.findRegionForVisColumn(column).getHiddenSoFar();
+ result += cursor.findRegionForColumn(column, true)
+ .getHiddenSoFar();
}
return result;
if (!hiddenColumns.isEmpty())
{
HiddenCursorPosition cursorPos = cursor
- .findRegionForColumn(hiddenColumn);
+ .findRegionForColumn(hiddenColumn, false);
int index = cursorPos.getRegionIndex();
int hiddenBeforeCol = cursorPos.getHiddenSoFar();
LOCK.readLock().lock();
if (!hiddenColumns.isEmpty())
{
- int index = cursor.findRegionForColumn(alPos).getRegionIndex();
+ int index = cursor.findRegionForColumn(alPos, false)
+ .getRegionIndex();
if (left && index > 0)
{
{
LOCK.readLock().lock();
- int regionindex = cursor.findRegionForColumn(column).getRegionIndex();
+ int regionindex = cursor.findRegionForColumn(column, false)
+ .getRegionIndex();
if (regionindex > -1 && regionindex < hiddenColumns.size())
{
int[] region = hiddenColumns.get(regionindex);
if (!hiddenColumns.isEmpty())
{
- HiddenCursorPosition pos = cursor.findRegionForColumn(start);
+ HiddenCursorPosition pos = cursor.findRegionForColumn(start, false);
int index = pos.getRegionIndex();
int startindex = index; // first index in hiddenColumns to remove
}
}
- pos = cursor.findRegionForColumn(end);
+ pos = cursor.findRegionForColumn(end, false);
index = pos.getRegionIndex();
int endindex = index - 1; // last index in hiddenColumns to remove
if (!hiddenColumns.isEmpty())
{
// look for a region ending just before adjres
- int regionindex = cursor.findRegionForColumn(adjres - 1)
+ int regionindex = cursor.findRegionForColumn(adjres - 1, false)
.getRegionIndex();
if (regionindex < hiddenColumns.size()
&& hiddenColumns.get(regionindex)[1] == adjres - 1)
// region we'll get the cursor pointing to the region before, which is
// what we want
HiddenCursorPosition pos = cursor
- .findRegionForColumn(absoluteStart - 1);
+ .findRegionForColumn(absoluteStart - 1, false);
return new BoundedStartRegionIterator(pos, start, end,
hiddenColumns);
* @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)
+ /*protected HiddenCursorPosition findRegionForColumn(int column)
{
- if (hiddenColumns.isEmpty())
- {
- return null;
- }
-
- HiddenCursorPosition oldpos = cursorPos;
- int index = oldpos.getRegionIndex();
- int hiddenCount = oldpos.getHiddenSoFar();
-
- if (index == hiddenColumns.size())
- {
- // went past the end of hiddenColumns collection last time
- index--;
- int[] region = hiddenColumns.get(index);
- hiddenCount -= region[1] - region[0] + 1;
- }
-
- // this if statement excludes case where column is in current region
- // - no changes needed
- if (column < firstColumn)
- {
- index = 0;
- hiddenCount = 0;
- }
- // column is after current region
- else if (column > hiddenColumns.get(index)[1])
- {
- // iterate from where we are now, if we're lucky we'll be close by
- // (but still better than iterating from 0)
- // stop when we find the region *before* column
- // i.e. the next region starts after column or if not, ends after column
- while ((index < hiddenColumns.size())
- && (column > hiddenColumns.get(index)[1]))
- {
- int[] region = hiddenColumns.get(index);
- hiddenCount += region[1] - region[0] + 1;
- index++;
- }
- }
- // column is before current region
- else if (column < hiddenColumns.get(index)[0])
- {
- // column is before or in the previous region
- while ((index > 0) && (hiddenColumns.get(index - 1)[1] >= column))
- {
- index--;
- int[] region = hiddenColumns.get(index);
- hiddenCount -= region[1] - region[0] + 1;
- }
- }
-
- if (index != oldpos.getRegionIndex()
- || hiddenCount != oldpos.getHiddenSoFar())
- {
- cursorPos = new HiddenCursorPosition(index,
- hiddenCount);
- return cursorPos;
- }
- return oldpos;
- }
+ return findRegionForColumn(column, false);
+ }*/
/**
* Get the cursor pointing to the hidden region just after a visible column
* column is visible)
* @return cursor pointing to hidden region to the right of the column
*/
- protected HiddenCursorPosition findRegionForVisColumn(int column)
+ /* protected HiddenCursorPosition findRegionForVisColumn(int column)
+ {
+ return findRegionForColumn(column, true);
+ }*/
+
+ /**
+ * 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
+ * index of column in visible or absolute coordinates
+ * @param useVisible
+ * true if column is in visible coordinates, false if absolute
+ * @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,
+ boolean useVisible)
{
if (hiddenColumns.isEmpty())
{
return null;
}
+ // used to add in hiddenColumns offset when working with visible columns
+ int offset = (useVisible ? 1 : 0);
+
HiddenCursorPosition oldpos = cursorPos;
int index = oldpos.getRegionIndex();
int hiddenCount = oldpos.getHiddenSoFar();
index = 0;
hiddenCount = 0;
}
+
+ // column is after current region
else if ((index < hiddenColumns.size())
- && (hiddenColumns.get(index)[0] <= column + hiddenCount))
+ && (hiddenColumns.get(index)[0] <= column
+ + offset * hiddenCount))
{
// iterate from where we are now, if we're lucky we'll be close by
// (but still better than iterating from 0)
+ // stop when we find the region *before* column
+ // i.e. the next region starts after column or if not, ends after column
while ((index < hiddenColumns.size())
- && (hiddenColumns.get(index)[0] <= column + hiddenCount))
+ && (((useVisible && hiddenColumns.get(index)[0] <= column
+ + offset * hiddenCount))
+ || (!useVisible
+ && hiddenColumns.get(index)[1] < column)))
{
int[] region = hiddenColumns.get(index);
hiddenCount += region[1] - region[0] + 1;
index++;
}
}
+
+ // column is before current region
else
{
- while ((index > 0)
- && (hiddenColumns.get(index - 1)[1] >= column + hiddenCount))
+ // column is before or in the previous region
+ while ((index > 0) && (hiddenColumns.get(index - 1)[1] >= column
+ + offset * hiddenCount))
{
index--;
int[] region = hiddenColumns.get(index);
hiddenCount -= region[1] - region[0] + 1;
}
-
}
if (index != oldpos.getRegionIndex()
|| hiddenCount != oldpos.getHiddenSoFar())
{
- cursorPos = new HiddenCursorPosition(index,
- hiddenCount);
- return cursorPos;
+ return new HiddenCursorPosition(index, hiddenCount);
}
return oldpos;
}
+
}
{
HiddenColumnsCursor cursor = new HiddenColumnsCursor();
- HiddenCursorPosition pos = cursor.findRegionForColumn(20);
+ HiddenCursorPosition pos = cursor.findRegionForColumn(20, false);
assertNull(pos);
List<int[]> hidden = new ArrayList<>();
cursor = new HiddenColumnsCursor(hidden);
- int regionIndex = cursor.findRegionForColumn(126).getRegionIndex();
+ int regionIndex = cursor.findRegionForColumn(126, false).getRegionIndex();
assertEquals(2, regionIndex);
- regionIndex = cursor.findRegionForColumn(125).getRegionIndex();
+ regionIndex = cursor.findRegionForColumn(125, false).getRegionIndex();
assertEquals(1, regionIndex);
- regionIndex = cursor.findRegionForColumn(108).getRegionIndex();
+ regionIndex = cursor.findRegionForColumn(108, false).getRegionIndex();
assertEquals(1, regionIndex);
- regionIndex = cursor.findRegionForColumn(104).getRegionIndex();
+ regionIndex = cursor.findRegionForColumn(104, false).getRegionIndex();
assertEquals(1, regionIndex);
- regionIndex = cursor.findRegionForColumn(103).getRegionIndex();
+ regionIndex = cursor.findRegionForColumn(103, false).getRegionIndex();
assertEquals(1, regionIndex);
- regionIndex = cursor.findRegionForColumn(77).getRegionIndex();
+ regionIndex = cursor.findRegionForColumn(77, false).getRegionIndex();
assertEquals(1, regionIndex);
- regionIndex = cursor.findRegionForColumn(76).getRegionIndex();
+ regionIndex = cursor.findRegionForColumn(76, false).getRegionIndex();
assertEquals(0, regionIndex);
- regionIndex = cursor.findRegionForColumn(53).getRegionIndex();
+ regionIndex = cursor.findRegionForColumn(53, false).getRegionIndex();
assertEquals(0, regionIndex);
- regionIndex = cursor.findRegionForColumn(52).getRegionIndex();
+ regionIndex = cursor.findRegionForColumn(52, false).getRegionIndex();
assertEquals(0, regionIndex);
- regionIndex = cursor.findRegionForColumn(0).getRegionIndex();
+ regionIndex = cursor.findRegionForColumn(0, false).getRegionIndex();
assertEquals(0, regionIndex);
hidden.add(new int[] { 138, 155 });
cursor = new HiddenColumnsCursor(hidden);
- regionIndex = cursor.findRegionForColumn(160).getRegionIndex();
+ regionIndex = cursor.findRegionForColumn(160, false).getRegionIndex();
assertEquals(3, regionIndex);
- regionIndex = cursor.findRegionForColumn(100).getRegionIndex();
+ regionIndex = cursor.findRegionForColumn(100, false).getRegionIndex();
assertEquals(1, regionIndex);
}
{
HiddenColumnsCursor cursor = new HiddenColumnsCursor();
- HiddenCursorPosition pos = cursor.findRegionForVisColumn(20);
+ HiddenCursorPosition pos = cursor.findRegionForColumn(20, true);
assertNull(pos);
List<int[]> hidden = new ArrayList<>();
cursor = new HiddenColumnsCursor(hidden);
- int offset = cursor.findRegionForVisColumn(80).getHiddenSoFar();
+ int offset = cursor.findRegionForColumn(80, true).getHiddenSoFar();
assertEquals(46, offset);
- offset = cursor.findRegionForVisColumn(79).getHiddenSoFar();
+ offset = cursor.findRegionForColumn(79, true).getHiddenSoFar();
assertEquals(24, offset);
- offset = cursor.findRegionForVisColumn(53).getHiddenSoFar();
+ offset = cursor.findRegionForColumn(53, true).getHiddenSoFar();
assertEquals(24, offset);
- offset = cursor.findRegionForVisColumn(52).getHiddenSoFar();
+ offset = cursor.findRegionForColumn(52, true).getHiddenSoFar();
assertEquals(0, offset);
- offset = cursor.findRegionForVisColumn(10).getHiddenSoFar();
+ offset = cursor.findRegionForColumn(10, true).getHiddenSoFar();
assertEquals(0, offset);
- offset = cursor.findRegionForVisColumn(0).getHiddenSoFar();
+ offset = cursor.findRegionForColumn(0, true).getHiddenSoFar();
assertEquals(0, offset);
+
+ offset = cursor.findRegionForColumn(79, true).getHiddenSoFar();
+ assertEquals(24, offset);
+
+ offset = cursor.findRegionForColumn(80, true).getHiddenSoFar();
+ assertEquals(46, offset);
}
}