From: kiramt Date: Mon, 13 Nov 2017 07:54:56 +0000 (+0000) Subject: JAL-2759 Converted getHiddenBoundaryLeft/Right to use cursor X-Git-Tag: Release_2_10_4~55^2~1^2~73 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=aee4f1ed59e360cfee845b480d6d85550b7e6d82;p=jalview.git JAL-2759 Converted getHiddenBoundaryLeft/Right to use cursor --- diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index dd1e1b3..084ea55 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -267,17 +267,6 @@ public class HiddenColumns if (hiddenColumns != null) { result += cursor.getHiddenOffset(column); - - - /*Iterator it = hiddenColumns.iterator(); - while (it.hasNext()) - { - int[] region = it.next(); - if (result >= region[0]) - { - result += region[1] - region[0] + 1; - } - }*/ } return result; @@ -404,7 +393,8 @@ public class HiddenColumns * hidden columns. In otherwords, the next hidden column. * * @param alPos - * the (visible) alignmentPosition to find the next hidden column for + * the absolute (visible) alignmentPosition to find the next hidden + * column for */ public int getHiddenBoundaryRight(int alPos) { @@ -413,14 +403,22 @@ public class HiddenColumns LOCK.readLock().lock(); if (hiddenColumns != null) { - Iterator it = hiddenColumns.iterator(); - while (it.hasNext()) + int index = cursor.findRegionForColumn(alPos); + if (index < hiddenColumns.size()) { - int[] region = it.next(); + int[] region = hiddenColumns.get(index); if (alPos < region[0]) { return region[0]; } + else if ((alPos <= region[1]) + && (index + 1 < hiddenColumns.size())) + { + // alPos is within a hidden region, return the next one + // if there is one + region = hiddenColumns.get(index + 1); + return region[0]; + } } } return alPos; @@ -435,8 +433,8 @@ public class HiddenColumns * hidden columns. In otherwords, the previous hidden column. * * @param alPos - * the (visible) alignmentPosition to find the previous hidden column - * for + * the absolute (visible) alignmentPosition to find the previous + * hidden column for */ public int getHiddenBoundaryLeft(int alPos) { @@ -444,17 +442,16 @@ public class HiddenColumns { LOCK.readLock().lock(); - Iterator it = new ReverseRegionsIterator(0, alPos, - hiddenColumns); - while (it.hasNext()) + if (hiddenColumns != null) { - int[] region = it.next(); - if (alPos > region[1]) + int index = cursor.findRegionForColumn(alPos); + + if (index > 0) { + int[] region = hiddenColumns.get(index - 1); return region[1]; } } - return alPos; } finally { @@ -1289,18 +1286,25 @@ public class HiddenColumns int adjres = adjustForHiddenColumns(res); int[] reveal = null; - Iterator it = new RegionsIterator(adjres - 2, - adjres + 2, hiddenColumns, cursor); - while (it.hasNext()) + + if (hiddenColumns != null) { - int[] region = it.next(); - if (adjres + 1 == region[0] || adjres - 1 == region[1]) + int regionindex = cursor.findRegionForColumn(adjres - 1); + if (hiddenColumns.get(regionindex)[1] == adjres - 1) { - reveal = region; - break; + reveal = hiddenColumns.get(regionindex); + } + else + { + regionindex = cursor.findRegionForColumn(adjres + 1); + if (hiddenColumns.get(regionindex)[0] == adjres + 1) + { + reveal = hiddenColumns.get(regionindex); + } } } return reveal; + } finally { LOCK.readLock().unlock(); diff --git a/src/jalview/datamodel/HiddenColumnsCursor.java b/src/jalview/datamodel/HiddenColumnsCursor.java index 7fa96c1..7be6cca 100644 --- a/src/jalview/datamodel/HiddenColumnsCursor.java +++ b/src/jalview/datamodel/HiddenColumnsCursor.java @@ -99,8 +99,9 @@ public class HiddenColumnsCursor } if ((hiddenColumns.get(index)[0] <= column) - && (hiddenColumns.get(index)[1] >= column)) + && hiddenColumns.get(index)[1] >= column) { + // column is in the current region // we hit the jackpot // don't need to move index } @@ -109,26 +110,25 @@ public class HiddenColumnsCursor index = 0; hiddenCount = 0; } - /*else if (column > lastColumn) - { - index = hiddenColumns.size(); - // TODO resolve here - need full hidden count - }*/ + // column is after current region else if (column > hiddenColumns.get(index)[1]) // includes if column > // lastColumn { // iterate from where we are now, if we're lucky we'll be close by // (but still better than iterating from 0) + // stop when we find the region *before* column + // i.e. the next region starts after column or if not, ends after column while ((index < hiddenColumns.size()) - && (hiddenColumns.get(index)[0] <= column)) + && (column > hiddenColumns.get(index)[1])) { int[] region = hiddenColumns.get(index); hiddenCount += region[1] - region[0] + 1; index++; } - } - else // (column < hiddenColumns.get(regionIndex)[0]) + + // column is before current region + else if (column < hiddenColumns.get(index)[0]) { while ((index > 0) && (hiddenColumns.get(index)[1] > column)) { diff --git a/src/jalview/datamodel/RegionsIterator.java b/src/jalview/datamodel/RegionsIterator.java index d1251f8..bafc288 100644 --- a/src/jalview/datamodel/RegionsIterator.java +++ b/src/jalview/datamodel/RegionsIterator.java @@ -41,13 +41,6 @@ public class RegionsIterator implements Iterator { currentPosition = cursor.findRegionForColumn(start); - // iterate until a region overlaps with [start,end] - /* currentPosition = 0; - while ((currentPosition < hiddenColumns.size()) - && (hiddenColumns.get(currentPosition)[1] < start)) - { - currentPosition++; - }*/ if (currentPosition < hiddenColumns.size()) { nextRegion = hiddenColumns.get(currentPosition);