From: Jim Procter Date: Sun, 4 Jun 2017 11:05:49 +0000 (+0100) Subject: JAL-2291 method taking a BitSet for hiding columns X-Git-Tag: Release_2_10_2~3^2~34 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ce3d87d456ac70e1677909dc527eb548275e6daa;p=jalview.git JAL-2291 method taking a BitSet for hiding columns --- diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index 3685ab0..96fff97 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -4,6 +4,7 @@ import jalview.util.Comparison; import jalview.util.ShiftList; import java.util.ArrayList; +import java.util.BitSet; import java.util.Collections; import java.util.List; import java.util.Vector; @@ -1262,4 +1263,20 @@ public class HiddenColumns return hashCode; } + /** + * Hide columns corresponding to the marked bits + * + * @param inserts + * - columns map to bits starting from zero + */ + public void hideMarkedBits(BitSet inserts) + { + for (int firstSet = inserts.nextSetBit(0), lastSet = 0; firstSet >= 0; firstSet = inserts + .nextSetBit(lastSet)) + { + lastSet = inserts.nextClearBit(firstSet); + hideColumns(firstSet, lastSet - 1); + } + } + } diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index b767cf7..a671263 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -29,6 +29,7 @@ import jalview.analysis.AlignmentGenerator; import jalview.gui.JvOptionPane; import java.util.Arrays; +import java.util.BitSet; import java.util.List; import org.testng.annotations.BeforeClass; @@ -517,4 +518,49 @@ public class HiddenColumnsTest assertEquals("[60, 70]", Arrays.toString(hidden.get(1))); } + @Test(groups = { "Functional" }) + public void testHideBitset() + { + HiddenColumns cs; + + BitSet one = new BitSet(); + + // one hidden range + one.set(1); + cs = new HiddenColumns(); + cs.hideMarkedBits(one); + assertEquals(1, cs.getHiddenRegions().size()); + + one.set(2); + cs = new HiddenColumns(); + cs.hideMarkedBits(one); + assertEquals(1, cs.getHiddenRegions().size()); + + one.set(3); + cs = new HiddenColumns(); + cs.hideMarkedBits(one); + assertEquals(1, cs.getHiddenRegions().size()); + + // split + one.clear(2); + cs = new HiddenColumns(); + cs.hideMarkedBits(one); + assertEquals(2, cs.getHiddenRegions().size()); + + assertEquals(0, cs.adjustForHiddenColumns(0)); + assertEquals(2, cs.adjustForHiddenColumns(1)); + assertEquals(4, cs.adjustForHiddenColumns(2)); + + // one again + one.clear(1); + cs = new HiddenColumns(); + cs.hideMarkedBits(one); + + assertEquals(1, cs.getHiddenRegions().size()); + + assertEquals(0, cs.adjustForHiddenColumns(0)); + assertEquals(1, cs.adjustForHiddenColumns(1)); + assertEquals(2, cs.adjustForHiddenColumns(2)); + assertEquals(4, cs.adjustForHiddenColumns(3)); + } }