From: kiramt Date: Wed, 4 Oct 2017 15:11:59 +0000 (+0100) Subject: JAL-2674 Adjustments to hideColumns X-Git-Tag: Release_2_10_4~55^2~1^2~85 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=fa5b03518dd51a47066670e6782ca81c792b6a29;p=jalview.git JAL-2674 Adjustments to hideColumns --- diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index b9e67ef..cd3183f 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -526,66 +526,71 @@ public class HiddenColumns } /* - * traverse existing hidden ranges and insert / amend / append as - * appropriate + * new range follows everything else; check first to avoid looping over whole hiddenColumns collection */ - for (int i = 0; i < hiddenColumns.size(); i++) + if (hiddenColumns.isEmpty() + || start > hiddenColumns.get(hiddenColumns.size() - 1)[1]) { - int[] region = hiddenColumns.get(i); - - if (end < region[0] - 1) - { - /* - * insert discontiguous preceding range - */ - hiddenColumns.add(i, new int[] { start, end }); - return; - } - - if (end <= region[1]) + hiddenColumns.add(new int[] { start, end }); + } + else + { + /* + * traverse existing hidden ranges and insert / amend / append as + * appropriate + */ + boolean added = false; + for (int i = 0; !added && i < hiddenColumns.size(); i++) { - /* - * new range overlaps existing, or is contiguous preceding it - adjust - * start column - */ - region[0] = Math.min(region[0], start); - return; - } + int[] region = hiddenColumns.get(i); - if (start <= region[1] + 1) - { - /* - * new range overlaps existing, or is contiguous following it - adjust - * start and end columns - */ - region[0] = Math.min(region[0], start); - region[1] = Math.max(region[1], end); - - /* - * also update or remove any subsequent ranges - * that are overlapped - */ - while (i < hiddenColumns.size() - 1) + if (end < region[0] - 1) { - int[] nextRegion = hiddenColumns.get(i + 1); - if (nextRegion[0] > end + 1) + /* + * insert discontiguous preceding range + */ + hiddenColumns.add(i, new int[] { start, end }); + added = true; + } + else if (end <= region[1]) + { + /* + * new range overlaps existing, or is contiguous preceding it - adjust + * start column + */ + region[0] = Math.min(region[0], start); + added = true; + } + else if (start <= region[1] + 1) + { + /* + * new range overlaps existing, or is contiguous following it - adjust + * start and end columns + */ + region[0] = Math.min(region[0], start); + region[1] = Math.max(region[1], end); + + /* + * also update or remove any subsequent ranges + * that are overlapped + */ + while (i < hiddenColumns.size() - 1) { - /* - * gap to next hidden range - no more to update - */ - break; + int[] nextRegion = hiddenColumns.get(i + 1); + if (nextRegion[0] > end + 1) + { + /* + * gap to next hidden range - no more to update + */ + break; + } + region[1] = Math.max(nextRegion[1], end); + hiddenColumns.remove(i + 1); } - region[1] = Math.max(nextRegion[1], end); - hiddenColumns.remove(i + 1); + added = true; } - return; - } + } // for } - - /* - * remaining case is that the new range follows everything else - */ - hiddenColumns.add(new int[] { start, end }); } finally { if (!wasAlreadyLocked)