Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.datamodel

File StartRegionIterator.java

 

Coverage histogram

../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

8
24
4
1
143
67
10
0.42
6
4
2.5

Classes

Class Line # Actions
StartRegionIterator 31 24 10 0
1.0100%
 

Contributing tests

This file is covered by 11 tests. .

Source view

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.ArrayList;
24    import java.util.Iterator;
25    import java.util.List;
26   
27    /**
28    * An iterator which iterates over visible start positions of hidden column
29    * regions in a range.
30    */
 
31    public class StartRegionIterator implements Iterator<Integer>
32    {
33    // start position to iterate from
34    private int start;
35   
36    // end position to iterate to
37    private int end;
38   
39    // current index in hiddenColumns
40    private int currentPosition = 0;
41   
42    // local copy or reference to hiddenColumns
43    private List<Integer> positions = null;
44   
45    /**
46    * Construct an iterator over hiddenColums bounded at [lowerBound,upperBound]
47    *
48    * @param lowerBound
49    * lower bound to iterate from
50    * @param upperBound
51    * upper bound to iterate to
52    * @param useCopyCols
53    * whether to make a local copy of hiddenColumns for iteration (set
54    * to true if calling from outwith the HiddenColumns class)
55    */
 
56  7 toggle StartRegionIterator(int lowerBound, int upperBound,
57    List<int[]> hiddenColumns)
58    {
59  7 this(null, lowerBound, upperBound, hiddenColumns);
60    }
61   
62    /**
63    * Construct an iterator over hiddenColums bounded at [lowerBound,upperBound]
64    *
65    * @param pos
66    * a hidden cursor position to start from - may be null
67    * @param lowerBound
68    * lower bound to iterate from - will be ignored if pos != null
69    * @param upperBound
70    * upper bound to iterate to
71    * @param hiddenColumns
72    * the hidden columns collection to use
73    */
 
74  454 toggle StartRegionIterator(HiddenCursorPosition pos, int lowerBound,
75    int upperBound, List<int[]> hiddenColumns)
76    {
77  454 start = lowerBound;
78  454 end = upperBound;
79   
80  454 if (hiddenColumns != null)
81    {
82  452 positions = new ArrayList<>(hiddenColumns.size());
83   
84    // navigate to start, keeping count of hidden columns
85  452 int i = 0;
86  452 int hiddenSoFar = 0;
87   
88  452 if (pos != null)
89    {
90    // use the cursor position provided
91  439 i = pos.getRegionIndex();
92  439 hiddenSoFar = pos.getHiddenSoFar();
93    }
94    else
95    {
96    // navigate to start
97  15 while ((i < hiddenColumns.size())
98    && (hiddenColumns.get(i)[0] < start + hiddenSoFar))
99    {
100  2 int[] region = hiddenColumns.get(i);
101  2 hiddenSoFar += region[1] - region[0] + 1;
102  2 i++;
103    }
104    }
105   
106    // iterate from start to end, adding start positions of each
107    // hidden region. Positions are visible columns count, not absolute
108  757 while (i < hiddenColumns.size()
109    && (hiddenColumns.get(i)[0] <= end + hiddenSoFar))
110    {
111  305 int[] region = hiddenColumns.get(i);
112  305 positions.add(region[0] - hiddenSoFar);
113  305 hiddenSoFar += region[1] - region[0] + 1;
114  305 i++;
115    }
116    }
117    else
118    {
119  2 positions = new ArrayList<>();
120    }
121   
122    }
123   
 
124  757 toggle @Override
125    public boolean hasNext()
126    {
127  757 return (currentPosition < positions.size());
128    }
129   
130    /**
131    * Get next hidden region start position
132    *
133    * @return the start position in *visible* coordinates
134    */
 
135  305 toggle @Override
136    public Integer next()
137    {
138  305 int result = positions.get(currentPosition);
139  305 currentPosition++;
140  305 return result;
141    }
142    }
143