From: kiramt Date: Mon, 29 Jan 2018 12:00:35 +0000 (+0000) Subject: JAL-2759 numColumns reset X-Git-Tag: Release_2_10_4~55^2~1^2~19 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=9e064d395de4746f14106c1c296bc94696a6190e;p=jalview.git JAL-2759 numColumns reset --- diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index 402ea25..9a8669f 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -66,6 +66,9 @@ public class HiddenColumns { private static final int HASH_MULTIPLIER = 31; + private static final int NUMCOLUMNS_RESET = -1; // value of numColumns if it + // needs to be recalculated + private static final ReentrantReadWriteLock LOCK = new ReentrantReadWriteLock(); /* @@ -212,7 +215,7 @@ public class HiddenColumns prevHiddenCount); // reset the number of columns so they will be recounted - numColumns = 0; + resetNumColumns(); } finally { @@ -303,7 +306,7 @@ public class HiddenColumns hideColumns(r[0], r[1]); } cursor = new HiddenColumnsCursor(hiddenColumns); - numColumns = 0; + resetNumColumns(); } finally { LOCK.writeLock().unlock(); @@ -328,7 +331,7 @@ public class HiddenColumns } hiddenColumns.clear(); cursor = new HiddenColumnsCursor(hiddenColumns); - numColumns = 0; + resetNumColumns(); } finally { @@ -372,7 +375,7 @@ public class HiddenColumns if (hiddenColumns.isEmpty()) { - numColumns = 0; + resetNumColumns(); } else { @@ -438,7 +441,7 @@ public class HiddenColumns { LOCK.readLock().lock(); - if (numColumns == 0) + if (numColumns == NUMCOLUMNS_RESET) { // numColumns is out of date, so recalculate int size = 0; @@ -459,6 +462,17 @@ public class HiddenColumns } /** + * Reset numColumns so that it gets recalculated. Currently the code does not + * recalculate numColumns on hide/reveal as it requires a full sweep of the + * hidden columns collection / smarter updating. Placeholder here if later on + * a recalculation is added. + */ + private void resetNumColumns() + { + numColumns = NUMCOLUMNS_RESET; + } + + /** * Get the number of distinct hidden regions * * @return number of regions @@ -783,7 +797,7 @@ public class HiddenColumns hideColumns(firstSet, lastSet - 1); } cursor = new HiddenColumnsCursor(hiddenColumns); - numColumns = 0; + resetNumColumns(); } finally { LOCK.writeLock().unlock(); @@ -867,7 +881,7 @@ public class HiddenColumns hiddenColumns.subList(startindex, endindex + 1).clear(); cursor = new HiddenColumnsCursor(hiddenColumns); - numColumns = 0; + resetNumColumns(); } } finally {