JAL-2759 Rationalise VisibleColsIterator and HiddenColsIterator
[jalview.git] / src / jalview / datamodel / RangeIterator.java
index 2c5d949..7a69ac6 100644 (file)
@@ -5,57 +5,57 @@ import java.util.Iterator;
 import java.util.List;
 
 /**
- * An iterator which iterates over regions in a range. Works with a copy of the
- * collection of regions.
+ * An iterator which iterates over a list of ranges. Works with a copy of the
+ * collection of ranges.
  */
 public class RangeIterator implements Iterator<int[]>
 {
-  // current index in regionsList
+  // current index in rangeList
   private int currentPosition = 0;
 
-  // current column in regionsList
-  private int[] currentRegion;
+  // current range in rangeList
+  private int[] currentRange;
 
-  // local copy or reference to regionsList
-  private List<int[]> localRegions;
+  // local copy or reference to rangeList
+  private List<int[]> localRanges;
 
   /**
    * Unbounded constructor
    * 
-   * @param regionsList
-   *          list of regions to iterate over
+   * @param rangeList
+   *          list of ranges to iterate over
    */
-  RangeIterator(List<int[]> regionsList)
+  RangeIterator(List<int[]> rangeList)
   {
-    if (!regionsList.isEmpty())
+    if (!rangeList.isEmpty())
     {
-      int last = regionsList.get(regionsList.size() - 1)[1];
-      init(0, last, regionsList);
+      int last = rangeList.get(rangeList.size() - 1)[1];
+      init(0, last, rangeList);
     }
     else
     {
-      init(0, 0, regionsList);
+      init(0, 0, rangeList);
     }
   }
 
   /**
-   * Construct an iterator over regionsList bounded at [lowerBound,upperBound]
+   * Construct an iterator over rangeList bounded at [lowerBound,upperBound]
    * 
    * @param lowerBound
    *          lower bound to iterate from
    * @param upperBound
    *          upper bound to iterate to
-   * @param regionsList
-   *          list of regions to iterate over
+   * @param rangeList
+   *          list of ranges to iterate over
    */
   RangeIterator(int lowerBound, int upperBound,
-          List<int[]> regionsList)
+          List<int[]> rangeList)
   {
-    init(lowerBound, upperBound, regionsList);
+    init(lowerBound, upperBound, rangeList);
   }
 
   /**
-   * Construct an iterator over regionsList bounded at [lowerBound,upperBound]
+   * Construct an iterator over rangeList bounded at [lowerBound,upperBound]
    * 
    * @param lowerBound
    *          lower bound to iterate from
@@ -63,30 +63,30 @@ public class RangeIterator implements Iterator<int[]>
    *          upper bound to iterate to
    */
   private void init(int lowerBound, int upperBound,
-          List<int[]> regionsList)
+          List<int[]> rangeList)
   {
     int start = lowerBound;
     int end = upperBound;
 
-    if (regionsList != null)
+    if (rangeList != null)
     {
-      localRegions = new ArrayList<>();
+      localRanges = new ArrayList<>();
 
-      // iterate until a region overlaps with [start,end]
+      // iterate until a range overlaps with [start,end]
       int i = 0;
-      while ((i < regionsList.size()) && (regionsList.get(i)[1] < start))
+      while ((i < rangeList.size()) && (rangeList.get(i)[1] < start))
       {
         i++;
       }
 
-      // iterate from start to end, adding each region. Positions are
-      // absolute, and all regions which *overlap* [start,end] are added.
-      while (i < regionsList.size() && (regionsList.get(i)[0] <= end))
+      // iterate from start to end, adding each range. Positions are
+      // absolute, and all ranges which *overlap* [start,end] are added.
+      while (i < rangeList.size() && (rangeList.get(i)[0] <= end))
       {
-        int[] rh = regionsList.get(i);
+        int[] rh = rangeList.get(i);
         int[] cp = new int[2];
         System.arraycopy(rh, 0, cp, 0, rh.length);
-        localRegions.add(cp);
+        localRanges.add(cp);
         i++;
       }
     }
@@ -95,20 +95,20 @@ public class RangeIterator implements Iterator<int[]>
   @Override
   public boolean hasNext()
   {
-    return (localRegions != null) && (currentPosition < localRegions.size());
+    return (localRanges != null) && (currentPosition < localRanges.size());
   }
 
   @Override
   public int[] next()
   {
-    currentRegion = localRegions.get(currentPosition);
+    currentRange = localRanges.get(currentPosition);
     currentPosition++;
-    return currentRegion;
+    return currentRange;
   }
 
   @Override
   public void remove()
   {
-    localRegions.remove(--currentPosition);
+    localRanges.remove(--currentPosition);
   }
 }