Clover icon

jalviewX

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

File VisibleContigsIterator.java

 

Coverage histogram

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

Code metrics

12
31
4
1
116
76
11
0.35
7.75
4
2.75

Classes

Class Line # Actions
VisibleContigsIterator 32 31 11 0
1.0100%
 

Contributing tests

This file is covered by 32 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 regions in a range. Provides a
29    * special "endsAtHidden" indicator to allow callers to determine if the final
30    * visible column is adjacent to a hidden region.
31    */
 
32    public class VisibleContigsIterator implements Iterator<int[]>
33    {
34    private List<int[]> vcontigs = new ArrayList<>();
35   
36    private int currentPosition = 0;
37   
38    private boolean endsAtHidden = false;
39   
 
40  682 toggle VisibleContigsIterator(int start, int end,
41    List<int[]> hiddenColumns)
42    {
43  682 if (hiddenColumns != null && hiddenColumns.size() > 0)
44    {
45  670 int vstart = start;
46  670 int hideStart;
47  670 int hideEnd;
48   
49  670 for (int[] region : hiddenColumns)
50    {
51  1013 endsAtHidden = false;
52  1013 hideStart = region[0];
53  1013 hideEnd = region[1];
54   
55    // navigate to start
56  1013 if (hideEnd < vstart)
57    {
58  435 continue;
59    }
60  578 if (hideStart > vstart)
61    {
62  379 if (end - 1 > hideStart - 1)
63    {
64  254 int[] contig = new int[] { vstart, hideStart - 1 };
65  254 vcontigs.add(contig);
66  254 endsAtHidden = true;
67    }
68    else
69    {
70  125 int[] contig = new int[] { vstart, end - 1 };
71  125 vcontigs.add(contig);
72    }
73    }
74  578 vstart = hideEnd + 1;
75   
76    // exit if we're past the end
77  578 if (vstart >= end)
78    {
79  345 break;
80    }
81    }
82   
83  670 if (vstart < end)
84    {
85  325 int[] contig = new int[] { vstart, end - 1 };
86  325 vcontigs.add(contig);
87  325 endsAtHidden = false;
88    }
89    }
90    else
91    {
92  12 int[] contig = new int[] { start, end - 1 };
93  12 vcontigs.add(contig);
94    }
95    }
96   
 
97  2053 toggle @Override
98    public boolean hasNext()
99    {
100  2053 return (currentPosition < vcontigs.size());
101    }
102   
 
103  716 toggle @Override
104    public int[] next()
105    {
106  716 int[] result = vcontigs.get(currentPosition);
107  716 currentPosition++;
108  716 return result;
109    }
110   
 
111  451 toggle public boolean endsAtHidden()
112    {
113  451 return endsAtHidden;
114    }
115    }
116