Github user tkruse commented on a diff in the pull request:
https://github.com/apache/groovy/pull/360#discussion_r69115512
--- Diff: src/main/groovy/lang/ObjectRange.java ---
@@ -357,160 +363,182 @@ public String toString() {
return reverse ? "" + to + ".." + from : "" + from + ".." + to;
}
+ @Override
public String inspect() {
- String toText = InvokerHelper.inspect(to);
- String fromText = InvokerHelper.inspect(from);
+ final String toText = InvokerHelper.inspect(to);
+ final String fromText = InvokerHelper.inspect(from);
return reverse ? "" + toText + ".." + fromText : "" + fromText +
".." + toText;
}
/**
* iterates over all values and returns true if one value matches.
* Also see containsWithinBounds.
*/
+ @Override
public boolean contains(Object value) {
- Iterator it = new StepIterator(this, 1);
- if (value == null) return false;
- while (it.hasNext()) {
- try {
- if (DefaultTypeTransformation.compareEqual(value,
it.next())) return true;
- } catch (ClassCastException e) {
- return false;
+ if (value == null) {
+ return false;
+ }
+
+ for (Iterator it = iterator(); it.hasNext(); ) {
+ if (compareEqual(value, it.next())) {
+ return true;
}
}
return false;
}
+ @Override
public void step(int step, Closure closure) {
- if (step == 0 && compareTo(from, to) == 0) {
+ step((Number) step, closure);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void step(Number step, Closure closure) {
+ if (compareEqual(step, 0) && compareTo(from, to) == 0) {
return; // from == to and step == 0, nothing to do, so return
}
- StepIterator iter = new StepIterator(this, step);
- while (iter.hasNext()) {
- closure.call(iter.next());
+
+ for (StepIterator it = new StepIterator(this, step); it.hasNext();
) {
+ closure.call(it.next());
}
}
/**
* {@inheritDoc}
*/
+ @Override
public Iterator iterator() {
- // non thread-safe iterator
--- End diff --
the comment is not a javadoc that says what the iterator() method should
return. it comments the next line.
---
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.
---