From 5c1e80ada930876d477059fd92c68c898659efbf Mon Sep 17 00:00:00 2001 From: kiramt Date: Mon, 5 Feb 2018 13:46:09 +0000 Subject: [PATCH] JAL-2759 Changes to StartRegionIterator after review --- src/jalview/datamodel/HiddenColumns.java | 2 +- ...egionIterator.java => StartRegionIterator.java} | 41 ++------------------ ...ratorTest.java => StartRegionIteratorTest.java} | 40 +++++++++---------- 3 files changed, 25 insertions(+), 58 deletions(-) rename src/jalview/datamodel/{BoundedStartRegionIterator.java => StartRegionIterator.java} (71%) rename test/jalview/datamodel/{BoundedStartRegionIteratorTest.java => StartRegionIteratorTest.java} (79%) diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index 509bd73..a9cd4d7 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -1062,7 +1062,7 @@ public class HiddenColumns HiddenCursorPosition pos = cursor .findRegionForColumn(absoluteStart - 1, false); - return new BoundedStartRegionIterator(pos, start, end, + return new StartRegionIterator(pos, start, end, hiddenColumns); } finally { diff --git a/src/jalview/datamodel/BoundedStartRegionIterator.java b/src/jalview/datamodel/StartRegionIterator.java similarity index 71% rename from src/jalview/datamodel/BoundedStartRegionIterator.java rename to src/jalview/datamodel/StartRegionIterator.java index d68eeeb..bd036e4 100644 --- a/src/jalview/datamodel/BoundedStartRegionIterator.java +++ b/src/jalview/datamodel/StartRegionIterator.java @@ -8,7 +8,7 @@ import java.util.List; * An iterator which iterates over visible start positions of hidden column * regions in a range. */ -public class BoundedStartRegionIterator implements Iterator +public class StartRegionIterator implements Iterator { // start position to iterate from private int start; @@ -33,43 +33,10 @@ public class BoundedStartRegionIterator implements Iterator * whether to make a local copy of hiddenColumns for iteration (set * to true if calling from outwith the HiddenColumns class) */ - BoundedStartRegionIterator(int lowerBound, int upperBound, + StartRegionIterator(int lowerBound, int upperBound, List hiddenColumns) { - start = lowerBound; - end = upperBound; - - if (hiddenColumns != null) - { - positions = new ArrayList<>(hiddenColumns.size()); - - // navigate to start, keeping count of hidden columns - int i = 0; - int hiddenSoFar = 0; - while ((i < hiddenColumns.size()) - && (hiddenColumns.get(i)[0] < start + hiddenSoFar)) - { - int[] region = hiddenColumns.get(i); - hiddenSoFar += region[1] - region[0] + 1; - i++; - } - - // iterate from start to end, adding start positions of each - // hidden region. Positions are visible columns count, not absolute - while (i < hiddenColumns.size() - && (hiddenColumns.get(i)[0] <= end + hiddenSoFar)) - { - int[] region = hiddenColumns.get(i); - positions.add(region[0] - hiddenSoFar); - hiddenSoFar += region[1] - region[0] + 1; - i++; - } - } - else - { - positions = new ArrayList<>(); - } - + this(null, lowerBound, upperBound, hiddenColumns); } /** @@ -84,7 +51,7 @@ public class BoundedStartRegionIterator implements Iterator * @param hiddenColumns * the hidden columns collection to use */ - BoundedStartRegionIterator(HiddenCursorPosition pos, int lowerBound, + StartRegionIterator(HiddenCursorPosition pos, int lowerBound, int upperBound, List hiddenColumns) { start = lowerBound; diff --git a/test/jalview/datamodel/BoundedStartRegionIteratorTest.java b/test/jalview/datamodel/StartRegionIteratorTest.java similarity index 79% rename from test/jalview/datamodel/BoundedStartRegionIteratorTest.java rename to test/jalview/datamodel/StartRegionIteratorTest.java index 77b4fd2..23d0b00 100644 --- a/test/jalview/datamodel/BoundedStartRegionIteratorTest.java +++ b/test/jalview/datamodel/StartRegionIteratorTest.java @@ -30,7 +30,7 @@ import java.util.List; import org.testng.annotations.Test; -public class BoundedStartRegionIteratorTest +public class StartRegionIteratorTest { /** * Test the start region iterator @@ -41,39 +41,39 @@ public class BoundedStartRegionIteratorTest List hiddenColumns = null; // null hidden columns - Iterator it = new BoundedStartRegionIterator(3, 10, + Iterator it = new StartRegionIterator(3, 10, hiddenColumns); assertFalse(it.hasNext()); hiddenColumns = new ArrayList<>(); // no hidden columns - it = new BoundedStartRegionIterator(3, 10, hiddenColumns); + it = new StartRegionIterator(3, 10, hiddenColumns); assertFalse(it.hasNext()); // add some hidden columns hiddenColumns.add(new int[] { 5, 10 }); hiddenColumns.add(new int[] { 25, 40 }); - it = new BoundedStartRegionIterator(3, 10, hiddenColumns); + it = new StartRegionIterator(3, 10, hiddenColumns); assertTrue(it.hasNext()); Integer result = it.next(); assertEquals(5, (int) result); assertFalse(it.hasNext()); - it = new BoundedStartRegionIterator(3, 15, hiddenColumns); + it = new StartRegionIterator(3, 15, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(5, (int) result); assertFalse(it.hasNext()); - it = new BoundedStartRegionIterator(3, 18, hiddenColumns); + it = new StartRegionIterator(3, 18, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(5, (int) result); assertFalse(it.hasNext()); - it = new BoundedStartRegionIterator(3, 19, hiddenColumns); + it = new StartRegionIterator(3, 19, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(5, (int) result); @@ -84,7 +84,7 @@ public class BoundedStartRegionIteratorTest hiddenColumns.add(new int[] { 47, 50 }); - it = new BoundedStartRegionIterator(15, 60, hiddenColumns); + it = new StartRegionIterator(15, 60, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(19, (int) result); @@ -104,39 +104,39 @@ public class BoundedStartRegionIteratorTest HiddenCursorPosition pos = null; // null hidden columns - Iterator it = new BoundedStartRegionIterator(pos, 3, 10, + Iterator it = new StartRegionIterator(pos, 3, 10, hiddenColumns); assertFalse(it.hasNext()); hiddenColumns = new ArrayList<>(); // no hidden columns - it = new BoundedStartRegionIterator(pos, 3, 10, hiddenColumns); + it = new StartRegionIterator(pos, 3, 10, hiddenColumns); assertFalse(it.hasNext()); // add some hidden columns hiddenColumns.add(new int[] { 5, 10 }); hiddenColumns.add(new int[] { 25, 40 }); - it = new BoundedStartRegionIterator(pos, 3, 10, hiddenColumns); + it = new StartRegionIterator(pos, 3, 10, hiddenColumns); assertTrue(it.hasNext()); Integer result = it.next(); assertEquals(5, (int) result); assertFalse(it.hasNext()); - it = new BoundedStartRegionIterator(pos, 3, 15, hiddenColumns); + it = new StartRegionIterator(pos, 3, 15, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(5, (int) result); assertFalse(it.hasNext()); - it = new BoundedStartRegionIterator(pos, 3, 18, hiddenColumns); + it = new StartRegionIterator(pos, 3, 18, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(5, (int) result); assertFalse(it.hasNext()); - it = new BoundedStartRegionIterator(pos, 3, 19, hiddenColumns); + it = new StartRegionIterator(pos, 3, 19, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(5, (int) result); @@ -147,7 +147,7 @@ public class BoundedStartRegionIteratorTest hiddenColumns.add(new int[] { 47, 50 }); - it = new BoundedStartRegionIterator(pos, 15, 60, hiddenColumns); + it = new StartRegionIterator(pos, 15, 60, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(19, (int) result); @@ -171,26 +171,26 @@ public class BoundedStartRegionIteratorTest HiddenCursorPosition pos = new HiddenCursorPosition(0, 0); - Iterator it = new BoundedStartRegionIterator(pos, 3, 10, + Iterator it = new StartRegionIterator(pos, 3, 10, hiddenColumns); assertTrue(it.hasNext()); Integer result = it.next(); assertEquals(5, (int) result); assertFalse(it.hasNext()); - it = new BoundedStartRegionIterator(pos, 3, 15, hiddenColumns); + it = new StartRegionIterator(pos, 3, 15, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(5, (int) result); assertFalse(it.hasNext()); - it = new BoundedStartRegionIterator(pos, 3, 18, hiddenColumns); + it = new StartRegionIterator(pos, 3, 18, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(5, (int) result); assertFalse(it.hasNext()); - it = new BoundedStartRegionIterator(pos, 3, 19, hiddenColumns); + it = new StartRegionIterator(pos, 3, 19, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(5, (int) result); @@ -202,7 +202,7 @@ public class BoundedStartRegionIteratorTest pos = new HiddenCursorPosition(1, 6); hiddenColumns.add(new int[] { 47, 50 }); - it = new BoundedStartRegionIterator(pos, 15, 60, hiddenColumns); + it = new StartRegionIterator(pos, 15, 60, hiddenColumns); assertTrue(it.hasNext()); result = it.next(); assertEquals(19, (int) result); -- 1.7.10.2