From: kiramt Date: Fri, 19 Jan 2018 07:51:31 +0000 (+0000) Subject: JAL-2759 Update to getVisibleStartAndEndIndex after review X-Git-Tag: Release_2_10_4~55^2~1^2~28 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=14b0554d88b9c2f51c15b7398430efa4b70529d6;p=jalview.git JAL-2759 Update to getVisibleStartAndEndIndex after review --- diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index ea8da8d..77d1c65 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -1234,42 +1234,27 @@ public class HiddenColumns try { LOCK.readLock().lock(); - int[] alignmentStartEnd = new int[] { 0, width - 1 }; - int startPos = alignmentStartEnd[0]; - int endPos = alignmentStartEnd[1]; - int[] lowestRange = new int[] { -1, -1 }; - int[] higestRange = new int[] { -1, -1 }; + int firstVisible = 0; + int lastVisible = width - 1; - if (hiddenColumns.isEmpty()) - { - return new int[] { startPos, endPos }; - } - - for (int[] range : hiddenColumns) + if (!hiddenColumns.isEmpty()) { - lowestRange = (range[0] <= startPos) ? range : lowestRange; - higestRange = (range[1] >= endPos) ? range : higestRange; - } + // first visible col with index 0, convert to absolute index + firstVisible = visibleToAbsoluteColumn(0); - if (lowestRange[0] == -1) // includes (lowestRange[1] == -1) - { - startPos = alignmentStartEnd[0]; - } - else - { - startPos = lowestRange[1] + 1; + // last visible column is either immediately to left of + // last hidden region, or is just the last column in the alignment + int[] lastregion = hiddenColumns.get(hiddenColumns.size() - 1); + if (lastregion[1] == width - 1) + { + // last region is at very end of alignment + // last visible column immediately precedes it + lastVisible = lastregion[0] - 1; + } } + return new int[] { firstVisible, lastVisible }; - if (higestRange[0] == -1) // includes (higestRange[1] == -1) - { - endPos = alignmentStartEnd[1]; - } - else - { - endPos = higestRange[0] - 1; - } - return new int[] { startPos, endPos }; } finally { LOCK.readLock().unlock(); diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index 9bbba5f..151e31d 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -679,7 +679,7 @@ public class HiddenColumnsTest } @Test(groups = { "Functional" }) - public void testHideBitset() + public void testHideColumns_BitSet() { HiddenColumns cs; @@ -1200,7 +1200,7 @@ public class HiddenColumnsTest } @Test(groups = "Functional") - public void testSubtractVisibleColumns() + public void testOffsetByVisibleColumns() { HiddenColumns h = new HiddenColumns(); int result = h.offsetByVisibleColumns(-1, 10);