| Class | Line # | Actions | |||
|---|---|---|---|---|---|
| VisibleRowsIterator | 32 | 18 | 11 |
| 1 | /* | |
| 2 | * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) | |
| 3 | * Copyright (C) $$Year-Rel$$ The Jalview Authors | |
| 4 | * | |
| 5 | * This file is part of Jalview. | |
| 6 | * | |
| 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. | |
| 11 | * | |
| 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. | |
| 16 | * | |
| 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. | |
| 20 | */ | |
| 21 | package jalview.datamodel; | |
| 22 | ||
| 23 | import java.util.Iterator; | |
| 24 | import java.util.NoSuchElementException; | |
| 25 | ||
| 26 | /** | |
| 27 | * An iterator which iterates over all visible rows in an alignment | |
| 28 | * | |
| 29 | * @author kmourao | |
| 30 | * | |
| 31 | */ | |
| 32 | public class VisibleRowsIterator implements Iterator<Integer> | |
| 33 | { | |
| 34 | private int last; | |
| 35 | ||
| 36 | private int current; | |
| 37 | ||
| 38 | private int next; | |
| 39 | ||
| 40 | private HiddenSequences hidden; | |
| 41 | ||
| 42 | private AlignmentI al; | |
| 43 | ||
| 44 | /** | |
| 45 | * Create an iterator for all visible rows in the alignment | |
| 46 | * | |
| 47 | * @param firstrow | |
| 48 | * absolute row index to start from | |
| 49 | * @param lastrow | |
| 50 | * absolute row index to end at | |
| 51 | * @param alignment | |
| 52 | * alignment to work with | |
| 53 | */ | |
| 54 | 0 | public VisibleRowsIterator(int firstrow, int lastrow, |
| 55 | AlignmentI alignment) | |
| 56 | { | |
| 57 | 0 | al = alignment; |
| 58 | 0 | current = firstrow; |
| 59 | 0 | last = lastrow; |
| 60 | 0 | hidden = al.getHiddenSequences(); |
| 61 | 0 | while (last > current && hidden.isHidden(last)) |
| 62 | { | |
| 63 | 0 | last--; |
| 64 | } | |
| 65 | 0 | current = firstrow; |
| 66 | 0 | while (current < last && hidden.isHidden(current)) |
| 67 | { | |
| 68 | 0 | current++; |
| 69 | } | |
| 70 | 0 | next = current; |
| 71 | } | |
| 72 | ||
| 73 | 0 | @Override |
| 74 | public boolean hasNext() | |
| 75 | { | |
| 76 | 0 | return next <= last; |
| 77 | } | |
| 78 | ||
| 79 | 0 | @Override |
| 80 | public Integer next() | |
| 81 | { | |
| 82 | 0 | if (next > last) |
| 83 | { | |
| 84 | 0 | throw new NoSuchElementException(); |
| 85 | } | |
| 86 | 0 | current = next; |
| 87 | 0 | do |
| 88 | { | |
| 89 | 0 | next++; |
| 90 | 0 | } while (next <= last && hidden.isHidden(next)); |
| 91 | 0 | return current; |
| 92 | } | |
| 93 | ||
| 94 | 0 | @Override |
| 95 | public void remove() | |
| 96 | { | |
| 97 | 0 | throw new UnsupportedOperationException(); |
| 98 | } | |
| 99 | } |