*
* - getVisibleColsIterator: iterates over the visible *columns*
*
- * For performance reasons, provide bounds where possible.
+ * For performance reasons, provide bounds where possible. Note that column
+ * numbering begins at 0 throughout this class.
*
* @author kmourao
*
* list of hidden column [start, end] ranges; the list is maintained in
* ascending start column order
*/
- private ArrayList<int[]> hiddenColumns;
+ private List<int[]> hiddenColumns;
/**
* Constructor
markHiddenRegions(hidden);
hidden.andNot(gaps);
hiddenColumns = null;
- this.hideMarkedBits(hidden);
+ this.hideColumns(hidden);
// for each sequence in the alignment, except the profile sequence,
// insert gaps corresponding to each hidden region but where each hidden
// column region is shifted backwards by the number of preceding visible
// gaps update hidden columns at the same time
Iterator<int[]> regions = hiddenColumns.iterator();
- ArrayList<int[]> newhidden = new ArrayList<>();
+ List<int[]> newhidden = new ArrayList<>();
int numGapsBefore = 0;
int gapPosition = 0;
* @param inserts
* - columns map to bits starting from zero
*/
- public void hideMarkedBits(BitSet inserts)
+ public void hideColumns(BitSet inserts)
{
try
{
*
* @param res
* visible residue position, unadjusted for hidden columns
- * @return region as [start,end] or null if no matching region is found
+ * @return region as [start,end] or null if no matching region is found. If
+ * res is adjacent to two regions, returns the left region.
*/
public int[] getRegionWithEdgeAtRes(int res)
{
+++ /dev/null
-package jalview.datamodel;
-
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * A local iterator which iterates over hidden column regions in a range.
- * Intended for use ONLY within the HiddenColumns class, because it works
- * directly with the hiddenColumns collection without locking (callers should
- * lock hiddenColumns).
- */
-public class RegionsIterator implements Iterator<int[]>
-{
- // start position to iterate from
- private int start;
-
- // end position to iterate to
- private int end;
-
- // current index in hiddenColumns
- private int currentPosition = 0;
-
- // current column in hiddenColumns
- private int[] nextRegion = null;
-
- private int[] currentRegion = null;
-
- private int removedIndex = -1;
-
- private final List<int[]> hiddenColumns;
-
- // Constructor with bounds
- RegionsIterator(int lowerBound, int upperBound, List<int[]> hiddenCols,
- HiddenColumnsCursor cursor)
- {
- start = lowerBound;
- end = upperBound;
- hiddenColumns = hiddenCols;
-
- if (hiddenColumns != null)
- {
- // TODO remove whole class?
- // commented out to compile
- // currentPosition = cursor.findRegionForColumn(start);
-
- if (currentPosition < hiddenColumns.size())
- {
- nextRegion = hiddenColumns.get(currentPosition);
- }
- }
- }
-
- @Override
- public boolean hasNext()
- {
- return (hiddenColumns != null) && (nextRegion != null)
- && (nextRegion[0] <= end);
- }
-
- @Override
- public int[] next()
- {
- currentRegion = nextRegion;
- currentPosition++;
- if (currentPosition < hiddenColumns.size())
- {
- nextRegion = hiddenColumns.get(currentPosition);
- }
- else
- {
- nextRegion = null;
- }
- return currentRegion;
- }
-
- @Override
- public void remove()
- {
- if ((currentRegion != null) && (removedIndex != currentPosition))
- {
- currentPosition--;
- hiddenColumns.subList(currentPosition, currentPosition + 1).clear();
- removedIndex = currentPosition;
- }
- else
- {
- // already removed element last returned by next()
- // or next() has not yet been called
- throw new IllegalStateException();
- }
- }
-
-}
inserts.or(mask);
// and set hidden columns accordingly
- hidden.hideMarkedBits(inserts);
+ hidden.hideColumns(inserts);
ap.av.getAlignment().setHiddenColumns(hidden);
refresh();
// one hidden range
one.set(1);
cs = new HiddenColumns();
- cs.hideMarkedBits(one);
+ cs.hideColumns(one);
assertEquals(1, cs.getNumberOfRegions());
one.set(2);
cs = new HiddenColumns();
- cs.hideMarkedBits(one);
+ cs.hideColumns(one);
assertEquals(1, cs.getNumberOfRegions());
one.set(3);
cs = new HiddenColumns();
- cs.hideMarkedBits(one);
+ cs.hideColumns(one);
assertEquals(1, cs.getNumberOfRegions());
// split
one.clear(2);
cs = new HiddenColumns();
- cs.hideMarkedBits(one);
+ cs.hideColumns(one);
assertEquals(2, cs.getNumberOfRegions());
assertEquals(0, cs.visibleToAbsoluteColumn(0));
// one again
one.clear(1);
cs = new HiddenColumns();
- cs.hideMarkedBits(one);
+ cs.hideColumns(one);
assertEquals(1, cs.getNumberOfRegions());
assertTrue(fromMark.isEmpty());
}
- hc.hideMarkedBits(toMark);
+ hc.hideColumns(toMark);
// see if we can recover bitfield
hc.markHiddenRegions(fromMark = new BitSet());
}
@Test(groups = "Functional")
- public void testGetVisibleStartAndEndIndexTest()
+ public void testGetVisibleStartAndEndIndex()
{
Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
AlignmentI align = new Alignment(new SequenceI[] { seq });
HiddenColumns h2 = new HiddenColumns();
BitSet tohide = new BitSet(21);
- h.hideMarkedBits(tohide);
+ h.hideColumns(tohide);
assertTrue(h.equals(h2));
// NB in hideMarkedBits, the last bit is not set to hidden
tohide.set(3, 6);
tohide.set(9);
tohide.set(19, 21);
- h.hideMarkedBits(tohide);
+ h.hideColumns(tohide);
h2.hideColumns(3, 5);
h2.hideColumns(9, 9);