1 package jalview.datamodel;
3 import java.util.ArrayList;
4 import java.util.Iterator;
6 import java.util.NoSuchElementException;
9 * Iterator over the visible *columns* (not regions) as determined by the set of
10 * hidden columns. Uses a local copy of hidden columns.
15 public class VisibleColsIterator implements Iterator<Integer>
23 private List<int[]> localHidden = new ArrayList<>();
25 private int nexthiddenregion;
27 VisibleColsIterator(int firstcol, int lastcol, List<int[]> hiddenColumns)
34 if (hiddenColumns != null)
37 for (i = 0; i < hiddenColumns.size()
38 && (current <= hiddenColumns.get(i)[0]); ++i)
40 if (current >= hiddenColumns.get(i)[0]
41 && current <= hiddenColumns.get(i)[1])
43 // current is hidden, move to right
44 current = hiddenColumns.get(i)[1] + 1;
46 nexthiddenregion = i + 1;
50 for (i = hiddenColumns.size() - 1; i >= 0
51 && (last >= hiddenColumns.get(i)[1]); --i)
53 if (last >= hiddenColumns.get(i)[0]
54 && last <= hiddenColumns.get(i)[1])
56 // last is hidden, move to left
57 last = hiddenColumns.get(i)[0] - 1;
61 // make a local copy of the bit we need
63 while (i < hiddenColumns.size() && hiddenColumns.get(i)[0] <= last)
65 int[] region = new int[] { hiddenColumns.get(i)[0],
66 hiddenColumns.get(i)[1] };
67 localHidden.add(region);
74 public boolean hasNext()
84 throw new NoSuchElementException();
87 if ((localHidden != null) && (nexthiddenregion < localHidden.size()))
89 // still some more hidden regions
90 if (next + 1 < localHidden.get(nexthiddenregion)[0])
92 // next+1 is still before the next hidden region
95 else if ((next + 1 >= localHidden.get(nexthiddenregion)[0])
96 && (next + 1 <= localHidden.get(nexthiddenregion)[1]))
98 // next + 1 is in the next hidden region
99 next = localHidden.get(nexthiddenregion)[1] + 1;
105 // finished with hidden regions, just increment normally
114 throw new UnsupportedOperationException();