* An iterator which iterates over visible start positions of hidden column
* regions in a range.
*/
-public class BoundedStartRegionIterator implements Iterator<Integer>
+public class StartRegionIterator implements Iterator<Integer>
{
// start position to iterate from
private int start;
* whether to make a local copy of hiddenColumns for iteration (set
* to true if calling from outwith the HiddenColumns class)
*/
- BoundedStartRegionIterator(int lowerBound, int upperBound,
+ StartRegionIterator(int lowerBound, int upperBound,
List<int[]> hiddenColumns)
{
- start = lowerBound;
- end = upperBound;
-
- if (hiddenColumns != null)
- {
- positions = new ArrayList<>(hiddenColumns.size());
-
- // navigate to start, keeping count of hidden columns
- int i = 0;
- int hiddenSoFar = 0;
- while ((i < hiddenColumns.size())
- && (hiddenColumns.get(i)[0] < start + hiddenSoFar))
- {
- int[] region = hiddenColumns.get(i);
- hiddenSoFar += region[1] - region[0] + 1;
- i++;
- }
-
- // iterate from start to end, adding start positions of each
- // hidden region. Positions are visible columns count, not absolute
- while (i < hiddenColumns.size()
- && (hiddenColumns.get(i)[0] <= end + hiddenSoFar))
- {
- int[] region = hiddenColumns.get(i);
- positions.add(region[0] - hiddenSoFar);
- hiddenSoFar += region[1] - region[0] + 1;
- i++;
- }
- }
- else
- {
- positions = new ArrayList<>();
- }
-
+ this(null, lowerBound, upperBound, hiddenColumns);
}
/**
* @param hiddenColumns
* the hidden columns collection to use
*/
- BoundedStartRegionIterator(HiddenCursorPosition pos, int lowerBound,
+ StartRegionIterator(HiddenCursorPosition pos, int lowerBound,
int upperBound, List<int[]> hiddenColumns)
{
start = lowerBound;
import org.testng.annotations.Test;
-public class BoundedStartRegionIteratorTest
+public class StartRegionIteratorTest
{
/**
* Test the start region iterator
List<int[]> hiddenColumns = null;
// null hidden columns
- Iterator<Integer> it = new BoundedStartRegionIterator(3, 10,
+ Iterator<Integer> it = new StartRegionIterator(3, 10,
hiddenColumns);
assertFalse(it.hasNext());
hiddenColumns = new ArrayList<>();
// no hidden columns
- it = new BoundedStartRegionIterator(3, 10, hiddenColumns);
+ it = new StartRegionIterator(3, 10, hiddenColumns);
assertFalse(it.hasNext());
// add some hidden columns
hiddenColumns.add(new int[] { 5, 10 });
hiddenColumns.add(new int[] { 25, 40 });
- it = new BoundedStartRegionIterator(3, 10, hiddenColumns);
+ it = new StartRegionIterator(3, 10, hiddenColumns);
assertTrue(it.hasNext());
Integer result = it.next();
assertEquals(5, (int) result);
assertFalse(it.hasNext());
- it = new BoundedStartRegionIterator(3, 15, hiddenColumns);
+ it = new StartRegionIterator(3, 15, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(5, (int) result);
assertFalse(it.hasNext());
- it = new BoundedStartRegionIterator(3, 18, hiddenColumns);
+ it = new StartRegionIterator(3, 18, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(5, (int) result);
assertFalse(it.hasNext());
- it = new BoundedStartRegionIterator(3, 19, hiddenColumns);
+ it = new StartRegionIterator(3, 19, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(5, (int) result);
hiddenColumns.add(new int[] { 47, 50 });
- it = new BoundedStartRegionIterator(15, 60, hiddenColumns);
+ it = new StartRegionIterator(15, 60, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(19, (int) result);
HiddenCursorPosition pos = null;
// null hidden columns
- Iterator<Integer> it = new BoundedStartRegionIterator(pos, 3, 10,
+ Iterator<Integer> it = new StartRegionIterator(pos, 3, 10,
hiddenColumns);
assertFalse(it.hasNext());
hiddenColumns = new ArrayList<>();
// no hidden columns
- it = new BoundedStartRegionIterator(pos, 3, 10, hiddenColumns);
+ it = new StartRegionIterator(pos, 3, 10, hiddenColumns);
assertFalse(it.hasNext());
// add some hidden columns
hiddenColumns.add(new int[] { 5, 10 });
hiddenColumns.add(new int[] { 25, 40 });
- it = new BoundedStartRegionIterator(pos, 3, 10, hiddenColumns);
+ it = new StartRegionIterator(pos, 3, 10, hiddenColumns);
assertTrue(it.hasNext());
Integer result = it.next();
assertEquals(5, (int) result);
assertFalse(it.hasNext());
- it = new BoundedStartRegionIterator(pos, 3, 15, hiddenColumns);
+ it = new StartRegionIterator(pos, 3, 15, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(5, (int) result);
assertFalse(it.hasNext());
- it = new BoundedStartRegionIterator(pos, 3, 18, hiddenColumns);
+ it = new StartRegionIterator(pos, 3, 18, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(5, (int) result);
assertFalse(it.hasNext());
- it = new BoundedStartRegionIterator(pos, 3, 19, hiddenColumns);
+ it = new StartRegionIterator(pos, 3, 19, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(5, (int) result);
hiddenColumns.add(new int[] { 47, 50 });
- it = new BoundedStartRegionIterator(pos, 15, 60, hiddenColumns);
+ it = new StartRegionIterator(pos, 15, 60, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(19, (int) result);
HiddenCursorPosition pos = new HiddenCursorPosition(0, 0);
- Iterator<Integer> it = new BoundedStartRegionIterator(pos, 3, 10,
+ Iterator<Integer> it = new StartRegionIterator(pos, 3, 10,
hiddenColumns);
assertTrue(it.hasNext());
Integer result = it.next();
assertEquals(5, (int) result);
assertFalse(it.hasNext());
- it = new BoundedStartRegionIterator(pos, 3, 15, hiddenColumns);
+ it = new StartRegionIterator(pos, 3, 15, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(5, (int) result);
assertFalse(it.hasNext());
- it = new BoundedStartRegionIterator(pos, 3, 18, hiddenColumns);
+ it = new StartRegionIterator(pos, 3, 18, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(5, (int) result);
assertFalse(it.hasNext());
- it = new BoundedStartRegionIterator(pos, 3, 19, hiddenColumns);
+ it = new StartRegionIterator(pos, 3, 19, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(5, (int) result);
pos = new HiddenCursorPosition(1, 6);
hiddenColumns.add(new int[] { 47, 50 });
- it = new BoundedStartRegionIterator(pos, 15, 60, hiddenColumns);
+ it = new StartRegionIterator(pos, 15, 60, hiddenColumns);
assertTrue(it.hasNext());
result = it.next();
assertEquals(19, (int) result);