From 34b682702fe2dee7a5d79f95960a1accbea17ef6 Mon Sep 17 00:00:00 2001 From: kiramt Date: Mon, 5 Feb 2018 14:41:46 +0000 Subject: [PATCH] JAL-2759 Fix errant RangeElementsIterator (unit tests were failing) --- src/jalview/datamodel/HiddenColumns.java | 2 +- src/jalview/datamodel/RangeElementsIterator.java | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) 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 { -- 1.7.10.2