Github user tkruse commented on a diff in the pull request:
https://github.com/apache/groovy/pull/360#discussion_r69118703
--- Diff: src/main/groovy/lang/ObjectRange.java ---
@@ -426,89 +419,52 @@ public void remove() {
innerIterator.remove();
}
};
- return safeIterator;
}
/**
* convenience class to serve in other methods.
* It's not thread-safe, and lazily produces the next element only on
calls of hasNext() or next()
*/
- private static class StepIterator implements Iterator {
- // actual step, can be +1 when desired step is -1 and direction is
from high to low
- private final int step;
+ static class StepIterator implements Iterator {
private final ObjectRange range;
- private int index = -1;
- private Comparable value;
- private boolean nextFetched = true;
+ private final boolean isAscending;
+ private Object next;
- private StepIterator(ObjectRange range, final int desiredStep) {
+ StepIterator(ObjectRange range, int desiredStep) {
if (desiredStep == 0 && compareNotEqual(range.getFrom(),
range.getTo())) {
throw new GroovyRuntimeException("Infinite loop detected
due to step size of 0");
}
+
this.range = range;
- if (range.isReverse()) {
- step = -desiredStep;
+ if (desiredStep < 0) {
+ isAscending = range.isReverse();
} else {
- step = desiredStep;
- }
- if (step > 0) {
- value = range.getFrom();
- } else {
- value = range.getTo();
+ isAscending = !range.isReverse();
}
+ next = isAscending ? range.getFrom() : range.getTo();
}
@Override
public void remove() {
- range.remove(index);
+ throw new UnsupportedOperationException();
}
@Override
public Object next() {
- // not thread safe
- if (!nextFetched) {
- value = peek();
- nextFetched = true;
+ if (!hasNext()) {
+ return null;
}
- nextFetched = false;
- index++;
- return value;
+
+ final Object result = next;
+ next = isAscending ? increment(next) : decrement(next);
+ return result;
}
@Override
public boolean hasNext() {
--- End diff --
There is a difference in any case, and your commit message does not point
it out to reviewers, and the javadoc of StepIterator was not changed.
Such changes make your PR more difficult to merge.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---