1 package jalview.datamodel;
3 import java.util.Iterator;
7 * A local iterator which iterates over hidden column regions in a range.
8 * Intended for use ONLY within the HiddenColumns class, because it works
9 * directly with the hiddenColumns collection without locking (callers should
10 * lock hiddenColumns).
12 public class RegionsIterator implements Iterator<int[]>
14 // start position to iterate from
17 // end position to iterate to
20 // current index in hiddenColumns
21 private int currentPosition = 0;
23 // current column in hiddenColumns
24 private int[] nextRegion = null;
26 private int[] currentRegion = null;
28 private int removedIndex = -1;
30 private final List<int[]> hiddenColumns;
32 // Constructor with bounds
33 RegionsIterator(int lowerBound, int upperBound, List<int[]> hiddenCols,
34 HiddenColumnsCursor cursor)
38 hiddenColumns = hiddenCols;
40 if (hiddenColumns != null)
42 // TODO remove whole class?
43 // commented out to compile
44 // currentPosition = cursor.findRegionForColumn(start);
46 if (currentPosition < hiddenColumns.size())
48 nextRegion = hiddenColumns.get(currentPosition);
54 public boolean hasNext()
56 return (hiddenColumns != null) && (nextRegion != null)
57 && (nextRegion[0] <= end);
63 currentRegion = nextRegion;
65 if (currentPosition < hiddenColumns.size())
67 nextRegion = hiddenColumns.get(currentPosition);
79 if ((currentRegion != null) && (removedIndex != currentPosition))
82 hiddenColumns.subList(currentPosition, currentPosition + 1).clear();
83 removedIndex = currentPosition;
87 // already removed element last returned by next()
88 // or next() has not yet been called
89 throw new IllegalStateException();