From: kiramt Date: Mon, 15 Jan 2018 11:46:07 +0000 (+0000) Subject: JAL-2759 Minor doc and naming changes X-Git-Tag: Release_2_10_4~55^2~1^2~43 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=3a4b2f8436ac8f23d1681a4782209ae0fbb37fdd;p=jalview.git JAL-2759 Minor doc and naming changes --- diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index 93791e4..18afa5b 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -42,7 +42,8 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; * * - 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 * @@ -68,7 +69,7 @@ public class HiddenColumns * list of hidden column [start, end] ranges; the list is maintained in * ascending start column order */ - private ArrayList hiddenColumns; + private List hiddenColumns; /** * Constructor @@ -483,14 +484,14 @@ public class HiddenColumns 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 regions = hiddenColumns.iterator(); - ArrayList newhidden = new ArrayList<>(); + List newhidden = new ArrayList<>(); int numGapsBefore = 0; int gapPosition = 0; @@ -1277,7 +1278,7 @@ public class HiddenColumns * @param inserts * - columns map to bits starting from zero */ - public void hideMarkedBits(BitSet inserts) + public void hideColumns(BitSet inserts) { try { @@ -1384,7 +1385,8 @@ public class HiddenColumns * * @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) { diff --git a/src/jalview/datamodel/RegionsIterator.java b/src/jalview/datamodel/RegionsIterator.java deleted file mode 100644 index 7eb5ff8..0000000 --- a/src/jalview/datamodel/RegionsIterator.java +++ /dev/null @@ -1,93 +0,0 @@ -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 -{ - // 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 hiddenColumns; - - // Constructor with bounds - RegionsIterator(int lowerBound, int upperBound, List 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(); - } - } - -} diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java index 850a09a..1e4116d 100644 --- a/src/jalview/gui/PopupMenu.java +++ b/src/jalview/gui/PopupMenu.java @@ -1503,7 +1503,7 @@ public class PopupMenu extends JPopupMenu implements ColourChangeListener inserts.or(mask); // and set hidden columns accordingly - hidden.hideMarkedBits(inserts); + hidden.hideColumns(inserts); ap.av.getAlignment().setHiddenColumns(hidden); refresh(); diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index 133f06e..ba2c1ea 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -689,23 +689,23 @@ public class HiddenColumnsTest // 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)); @@ -715,7 +715,7 @@ public class HiddenColumnsTest // one again one.clear(1); cs = new HiddenColumns(); - cs.hideMarkedBits(one); + cs.hideColumns(one); assertEquals(1, cs.getNumberOfRegions()); @@ -746,7 +746,7 @@ public class HiddenColumnsTest assertTrue(fromMark.isEmpty()); } - hc.hideMarkedBits(toMark); + hc.hideColumns(toMark); // see if we can recover bitfield hc.markHiddenRegions(fromMark = new BitSet()); @@ -771,7 +771,7 @@ public class HiddenColumnsTest } @Test(groups = "Functional") - public void testGetVisibleStartAndEndIndexTest() + public void testGetVisibleStartAndEndIndex() { Sequence seq = new Sequence("testSeq", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); AlignmentI align = new Alignment(new SequenceI[] { seq }); @@ -1156,14 +1156,14 @@ public class HiddenColumnsTest 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);