if (hiddenColumns != null)
{
result += cursor.getHiddenOffset(column);
-
-
- /*Iterator<int[]> it = hiddenColumns.iterator();
- while (it.hasNext())
- {
- int[] region = it.next();
- if (result >= region[0])
- {
- result += region[1] - region[0] + 1;
- }
- }*/
}
return result;
* hidden columns. In otherwords, the next hidden column.
*
* @param alPos
- * the (visible) alignmentPosition to find the next hidden column for
+ * the absolute (visible) alignmentPosition to find the next hidden
+ * column for
*/
public int getHiddenBoundaryRight(int alPos)
{
LOCK.readLock().lock();
if (hiddenColumns != null)
{
- Iterator<int[]> it = hiddenColumns.iterator();
- while (it.hasNext())
+ int index = cursor.findRegionForColumn(alPos);
+ if (index < hiddenColumns.size())
{
- int[] region = it.next();
+ int[] region = hiddenColumns.get(index);
if (alPos < region[0])
{
return region[0];
}
+ else if ((alPos <= region[1])
+ && (index + 1 < hiddenColumns.size()))
+ {
+ // alPos is within a hidden region, return the next one
+ // if there is one
+ region = hiddenColumns.get(index + 1);
+ return region[0];
+ }
}
}
return alPos;
* hidden columns. In otherwords, the previous hidden column.
*
* @param alPos
- * the (visible) alignmentPosition to find the previous hidden column
- * for
+ * the absolute (visible) alignmentPosition to find the previous
+ * hidden column for
*/
public int getHiddenBoundaryLeft(int alPos)
{
{
LOCK.readLock().lock();
- Iterator<int[]> it = new ReverseRegionsIterator(0, alPos,
- hiddenColumns);
- while (it.hasNext())
+ if (hiddenColumns != null)
{
- int[] region = it.next();
- if (alPos > region[1])
+ int index = cursor.findRegionForColumn(alPos);
+
+ if (index > 0)
{
+ int[] region = hiddenColumns.get(index - 1);
return region[1];
}
}
-
return alPos;
} finally
{
int adjres = adjustForHiddenColumns(res);
int[] reveal = null;
- Iterator<int[]> it = new RegionsIterator(adjres - 2,
- adjres + 2, hiddenColumns, cursor);
- while (it.hasNext())
+
+ if (hiddenColumns != null)
{
- int[] region = it.next();
- if (adjres + 1 == region[0] || adjres - 1 == region[1])
+ int regionindex = cursor.findRegionForColumn(adjres - 1);
+ if (hiddenColumns.get(regionindex)[1] == adjres - 1)
{
- reveal = region;
- break;
+ reveal = hiddenColumns.get(regionindex);
+ }
+ else
+ {
+ regionindex = cursor.findRegionForColumn(adjres + 1);
+ if (hiddenColumns.get(regionindex)[0] == adjres + 1)
+ {
+ reveal = hiddenColumns.get(regionindex);
+ }
}
}
return reveal;
+
} finally
{
LOCK.readLock().unlock();
}
if ((hiddenColumns.get(index)[0] <= column)
- && (hiddenColumns.get(index)[1] >= column))
+ && hiddenColumns.get(index)[1] >= column)
{
+ // column is in the current region
// we hit the jackpot
// don't need to move index
}
index = 0;
hiddenCount = 0;
}
- /*else if (column > lastColumn)
- {
- index = hiddenColumns.size();
- // TODO resolve here - need full hidden count
- }*/
+ // column is after current region
else if (column > hiddenColumns.get(index)[1]) // includes if column >
// lastColumn
{
// 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))
+ && (column > hiddenColumns.get(index)[1]))
{
int[] region = hiddenColumns.get(index);
hiddenCount += region[1] - region[0] + 1;
index++;
}
-
}
- else // (column < hiddenColumns.get(regionIndex)[0])
+
+ // column is before current region
+ else if (column < hiddenColumns.get(index)[0])
{
while ((index > 0) && (hiddenColumns.get(index)[1] > column))
{