2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.NoSuchElementException;
28 * An iterator which iterates over all visible columns in an alignment
33 public class VisibleColsIterator implements Iterator<Integer>
41 private List<int[]> hidden;
43 private int lasthiddenregion;
45 public VisibleColsIterator(int firstcol, int lastcol,
46 HiddenColumns hiddenCols)
51 hidden = hiddenCols.getHiddenRegions();
52 lasthiddenregion = -1;
57 for (i = 0; i < hidden.size(); ++i)
59 if (current >= hidden.get(i)[0] && current <= hidden.get(i)[1])
61 // current is hidden, move to right
62 current = hidden.get(i)[1] + 1;
65 if (current < hidden.get(i)[0])
70 lasthiddenregion = i - 1;
72 for (i = hidden.size() - 1; i >= 0; --i)
74 if (last >= hidden.get(i)[0] && last <= hidden.get(i)[1])
76 // last is hidden, move to left
77 last = hidden.get(i)[0] - 1;
79 if (last > hidden.get(i)[1])
88 public boolean hasNext()
98 throw new NoSuchElementException();
101 if ((hidden != null) && (lasthiddenregion + 1 < hidden.size()))
103 // still some more hidden regions
104 if (next + 1 < hidden.get(lasthiddenregion + 1)[0])
106 // next+1 is still before the next hidden region
109 else if ((next + 1 >= hidden.get(lasthiddenregion + 1)[0])
110 && (next + 1 <= hidden.get(lasthiddenregion + 1)[1]))
112 // next + 1 is in the next hidden region
113 next = hidden.get(lasthiddenregion + 1)[1] + 1;
119 // finished with hidden regions, just increment normally
128 throw new UnsupportedOperationException();