From: kiramt Date: Mon, 15 Jan 2018 16:27:22 +0000 (+0000) Subject: JAL-2759 More compact iterator usage; after review X-Git-Tag: Release_2_10_4~55^2~1^2~36 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=8874aa9fd956f7bc248fe15a669a6d8d81d6891b;p=jalview.git JAL-2759 More compact iterator usage; after review --- diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index 718f64e..6677151 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -325,10 +325,8 @@ public class HiddenColumns { LOCK.writeLock().lock(); - Iterator it = hiddenColumns.iterator(); - while (it.hasNext()) + for (int[] region : hiddenColumns) { - int[] region = it.next(); for (int j = region[0]; j < region[1] + 1; j++) { sel.addElement(j); @@ -460,17 +458,15 @@ public class HiddenColumns // insert gaps corresponding to each hidden region but where each hidden // column region is shifted backwards by the number of preceding visible // gaps update hidden columns at the same time - Iterator regions = hiddenColumns.iterator(); List newhidden = new ArrayList<>(); int numGapsBefore = 0; int gapPosition = 0; - while (regions.hasNext()) + for (int[] region : hiddenColumns) { // get region coordinates accounting for gaps // we can rely on gaps not being *in* hidden regions because we already // removed those - int[] region = regions.next(); while (gapPosition < region[0]) { gapPosition++; @@ -580,16 +576,19 @@ public class HiddenColumns LOCK.readLock().lock(); StringBuilder regionBuilder = new StringBuilder(); - Iterator it = hiddenColumns.iterator(); - while (it.hasNext()) + boolean first = true; + for (int[] range : hiddenColumns) { - int[] range = it.next(); - regionBuilder.append(delimiter).append(range[0]).append(between) - .append(range[1]); - if (!it.hasNext()) + if (!first) { - regionBuilder.deleteCharAt(0); + regionBuilder.append(delimiter); } + else + { + first = false; + } + regionBuilder.append(range[0]).append(between).append(range[1]); + } return regionBuilder.toString(); @@ -615,10 +614,8 @@ public class HiddenColumns // numColumns is out of date, so recalculate int size = 0; - Iterator it = hiddenColumns.iterator(); - while (it.hasNext()) + for (int[] range : hiddenColumns) { - int[] range = it.next(); size += range[1] - range[0] + 1; } @@ -676,11 +673,9 @@ public class HiddenColumns return false; } - Iterator it = hiddenColumns.iterator(); Iterator thatit = that.iterator(); - while (it.hasNext()) + for (int[] thisRange : hiddenColumns) { - int[] thisRange = it.next(); int[] thatRange = thatit.next(); if (thisRange[0] != thatRange[0] || thisRange[1] != thatRange[1]) { @@ -1223,10 +1218,8 @@ public class HiddenColumns { LOCK.readLock().lock(); int hashCode = 1; - Iterator it = hiddenColumns.iterator(); - while (it.hasNext()) + for (int[] hidden : hiddenColumns) { - int[] hidden = it.next(); hashCode = HASH_MULTIPLIER * hashCode + hidden[0]; hashCode = HASH_MULTIPLIER * hashCode + hidden[1]; } @@ -1274,10 +1267,8 @@ public class HiddenColumns { LOCK.readLock().lock(); - Iterator it = hiddenColumns.iterator(); - while (it.hasNext()) + for (int[] range : hiddenColumns) { - int[] range = it.next(); inserts.set(range[0], range[1] + 1); } } finally @@ -1310,10 +1301,8 @@ public class HiddenColumns return new int[] { startPos, endPos }; } - Iterator it = hiddenColumns.iterator(); - while (it.hasNext()) + for (int[] range : hiddenColumns) { - int[] range = it.next(); lowestRange = (range[0] <= startPos) ? range : lowestRange; higestRange = (range[1] >= endPos) ? range : higestRange; }