From: kiramt Date: Mon, 5 Feb 2018 14:41:46 +0000 (+0000) Subject: JAL-2759 Fix errant RangeElementsIterator (unit tests were failing) X-Git-Tag: Release_2_10_4~55^2~1^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=34b682702fe2dee7a5d79f95960a1accbea17ef6;p=jalview.git JAL-2759 Fix errant RangeElementsIterator (unit tests were failing) --- diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index 8f6ecd6..a7e93da 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -1084,7 +1084,7 @@ public class HiddenColumns try { LOCK.readLock().lock(); - return new RangeElementsIterator(start, end, + return new RangeElementsIterator( new VisibleContigsIterator(start, end + 1, hiddenColumns)); } finally { diff --git a/src/jalview/datamodel/RangeElementsIterator.java b/src/jalview/datamodel/RangeElementsIterator.java index ca6c4f7..85272f2 100644 --- a/src/jalview/datamodel/RangeElementsIterator.java +++ b/src/jalview/datamodel/RangeElementsIterator.java @@ -23,29 +23,27 @@ public class RangeElementsIterator implements Iterator private int[] nextRange = null; - RangeElementsIterator(int from, int to, Iterator it) + RangeElementsIterator(Iterator it) { - last = to; - current = from; - next = from; rangeIterator = it; if (rangeIterator.hasNext()) { nextRange = rangeIterator.next(); + next = nextRange[0]; + last = nextRange[1]; } - checkNextRange(); } @Override public boolean hasNext() { - return next <= last; + return rangeIterator.hasNext() || next <= last; } @Override public Integer next() { - if (next > last) + if (!hasNext()) { throw new NoSuchElementException(); } @@ -66,12 +64,13 @@ public class RangeElementsIterator implements Iterator */ private void checkNextRange() { - if (nextRange != null && next >= nextRange[0]) + if (nextRange != null && next > nextRange[1]) { - next = nextRange[1] + 1; if (rangeIterator.hasNext()) { nextRange = rangeIterator.next(); + next = nextRange[0]; + last = nextRange[1]; } else {