From 52c730fe6038e42a6e8a6c67bb0d3072b9e5f31c Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Sun, 4 Jun 2017 13:18:27 +0100 Subject: [PATCH] JAL-2291 get bitset representing hidden columns --- src/jalview/datamodel/HiddenColumns.java | 17 +++++++++++++++++ test/jalview/datamodel/HiddenColumnsTest.java | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) 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); + } + } } -- 1.7.10.2