1 package jalview.datamodel;
3 import java.util.Iterator;
7 * A local iterator which reverse iterates over hidden column regions in a
8 * range. 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 ReverseRegionsIterator implements Iterator<int[]>
14 // start position to iterate to
17 // end position to iterate from
20 // current index in hiddenColumns
21 private int currentPosition = 0;
23 // current column in hiddenColumns
24 private int[] nextRegion = null;
26 private final List<int[]> hiddenColumns;
28 // Constructor with bounds
29 ReverseRegionsIterator(int lowerBound, int upperBound,
30 List<int[]> hiddenCols)
32 hiddenColumns = hiddenCols;
36 if (hiddenColumns != null)
38 // iterate until a region overlaps with [start,end]
39 currentPosition = hiddenColumns.size() - 1;
40 while (currentPosition >= 0
41 && hiddenColumns.get(currentPosition)[1] > end)
45 if (currentPosition >= 0)
47 nextRegion = hiddenColumns.get(currentPosition);
53 public boolean hasNext()
55 return (hiddenColumns != null) && (nextRegion != null)
56 && (nextRegion[1] >= start);
62 int[] region = nextRegion;
64 if (currentPosition >= 0)
66 nextRegion = hiddenColumns.get(currentPosition);