From: Jim Procter Date: Sun, 4 Jun 2017 12:18:27 +0000 (+0100) Subject: JAL-2291 get bitset representing hidden columns X-Git-Tag: Release_2_10_2~3^2~32 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=52c730fe6038e42a6e8a6c67bb0d3072b9e5f31c;p=jalview.git JAL-2291 get bitset representing hidden columns --- diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index 96fff97..f0d99e5 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -1279,4 +1279,21 @@ public class HiddenColumns } } + /** + * + * @param inserts + * BitSet where hidden columns will be marked + */ + public void markHiddenRegions(BitSet inserts) + { + if (hiddenColumns == null) + { + return; + } + for (int[] range : hiddenColumns) + { + inserts.set(range[0], range[1] + 1); + } + } + } diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index a671263..10808d6 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -31,6 +31,7 @@ import jalview.gui.JvOptionPane; import java.util.Arrays; import java.util.BitSet; import java.util.List; +import java.util.Random; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -563,4 +564,25 @@ public class HiddenColumnsTest assertEquals(2, cs.adjustForHiddenColumns(2)); assertEquals(4, cs.adjustForHiddenColumns(3)); } + + @Test(groups = { "Functional" }) + public void testGetBitset() + { + BitSet toMark, fromMark; + long seed = -3241532; + Random number = new Random(seed); + for (int n = 0; n < 1000; n++) + { + // create a random bitfield + toMark = BitSet.valueOf(new long[] { number.nextLong(), + number.nextLong(), number.nextLong() }); + toMark.set(n * number.nextInt(10), n * (25 + number.nextInt(25))); + HiddenColumns hc = new HiddenColumns(); + hc.hideMarkedBits(toMark); + + // see if we can recover bitfield + hc.markHiddenRegions(fromMark = new BitSet()); + assertEquals(toMark, fromMark); + } + } }