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 currentPosition = cursor.findRegionForColumn(start);
44 if (currentPosition < hiddenColumns.size())
46 nextRegion = hiddenColumns.get(currentPosition);
52 public boolean hasNext()
54 return (hiddenColumns != null) && (nextRegion != null)
55 && (nextRegion[0] <= end);
61 currentRegion = nextRegion;
63 if (currentPosition < hiddenColumns.size())
65 nextRegion = hiddenColumns.get(currentPosition);
77 if ((currentRegion != null) && (removedIndex != currentPosition))
80 hiddenColumns.subList(currentPosition, currentPosition + 1).clear();
81 removedIndex = currentPosition;
85 // already removed element last returned by next()
86 // or next() has not yet been called
87 throw new IllegalStateException();