You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2015/10/15 05:01:25 UTC
[3/3] incubator-groovy git commit: Groovy-7574: Ranges: Make Range
members final (minor refactor, closes PR#141)
Groovy-7574: Ranges: Make Range members final (minor refactor, closes PR#141)
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/74c422e4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/74c422e4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/74c422e4
Branch: refs/heads/master
Commit: 74c422e41bc951719124bc2c5333f15dd34a4be7
Parents: 2d22ca8
Author: paulk <pa...@asert.com.au>
Authored: Thu Oct 15 13:00:34 2015 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Thu Oct 15 13:00:34 2015 +1000
----------------------------------------------------------------------
src/main/groovy/lang/EmptyRange.java | 2 --
src/main/groovy/lang/IntRange.java | 20 ++++++++++++++------
src/main/groovy/lang/ObjectRange.java | 14 ++++++--------
3 files changed, 20 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/74c422e4/src/main/groovy/lang/EmptyRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/EmptyRange.java b/src/main/groovy/lang/EmptyRange.java
index 1680809..56ec153 100644
--- a/src/main/groovy/lang/EmptyRange.java
+++ b/src/main/groovy/lang/EmptyRange.java
@@ -24,8 +24,6 @@ import java.util.*;
/**
* Constructing Ranges like 0..<0
- * @author Dierk Koenig
- * @author Edwin Tellman
*/
public class EmptyRange extends AbstractList implements Range {
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/74c422e4/src/main/groovy/lang/IntRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/IntRange.java b/src/main/groovy/lang/IntRange.java
index dd8f96a..7077ddd 100644
--- a/src/main/groovy/lang/IntRange.java
+++ b/src/main/groovy/lang/IntRange.java
@@ -28,18 +28,26 @@ import java.util.Iterator;
import java.util.List;
/**
- * Represents a list of Integer objects from a specified int up (or down) to and including
- * a given to.<p>
+ * Represents a list of Integer objects starting at a specified {@code from} value up (or down)
+ * to and potentially including a given {@code to} value.
* <p>
- * This class is a copy of {@link ObjectRange} optimized for <code>int</code>. If you make any
- * changes to this class, you might consider making parallel changes to {@link ObjectRange}.
* Instances of this class may be either inclusive aware or non-inclusive aware. See the
* relevant constructors for creating each type. Inclusive aware IntRange instances are
* suitable for use with Groovy's range indexing - in particular if the from or to values
* might be negative. This normally happens underneath the covers but is worth keeping
* in mind if creating these ranges yourself explicitly.
- *
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
+ * <p>
+ * Note: the design of this class might seem a little strange at first. It contains a Boolean
+ * field, {@code inclusive}, which can be {@code true}, {@code false} or {@code null}. This
+ * design is for backwards compatibility reasons. Groovy uses this class under the covers
+ * to represent range indexing, e.g. {@code someList[x..y]} and {@code someString[x..<y]}.
+ * In early versions of Groovy the ranges in these expressions were represented under the
+ * covers by the {@code new IntRange(x, y)} and {@code new IntRange(x, y-1)}. This turns
+ * out to be a lossy abstraction when x and/or y are negative values. Now the latter case
+ * is represented by {@code new IntRange(false, x, y)}.
+ * <p>
+ * Note: This class is a copy of {@link ObjectRange} optimized for <code>int</code>. If you make any
+ * changes to this class, you might consider making parallel changes to {@link ObjectRange}.
*/
public class IntRange extends AbstractList<Integer> implements Range<Integer> {
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/74c422e4/src/main/groovy/lang/ObjectRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/ObjectRange.java b/src/main/groovy/lang/ObjectRange.java
index 22e5527..d2e3427 100644
--- a/src/main/groovy/lang/ObjectRange.java
+++ b/src/main/groovy/lang/ObjectRange.java
@@ -34,10 +34,8 @@ import java.util.List;
* Represents an inclusive list of objects from a value to a value using
* comparators.
* <p>
- * This class is similar to {@link IntRange}. If you make any changes to this
+ * Note: This class is similar to {@link IntRange}. If you make any changes to this
* class, you might consider making parallel changes to {@link IntRange}.
- *
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
*/
public class ObjectRange extends AbstractList implements Range {
@@ -101,7 +99,7 @@ public class ObjectRange extends AbstractList implements Range {
}
this.reverse = computedReverse;
} else {
- this.reverse = reverse.booleanValue();
+ this.reverse = reverse;
}
if (smaller instanceof Short) {
@@ -116,9 +114,9 @@ public class ObjectRange extends AbstractList implements Range {
}
if (smaller instanceof Integer && larger instanceof Long) {
- smaller = Long.valueOf(((Integer) smaller).longValue());
+ smaller = ((Integer) smaller).longValue();
} else if (larger instanceof Integer && smaller instanceof Long) {
- larger = Long.valueOf(((Integer) larger).longValue());
+ larger = ((Integer) larger).longValue();
}
// TODO: should we care about different types here?
@@ -292,7 +290,7 @@ public class ObjectRange extends AbstractList implements Range {
/**
* protection against calls from Groovy
*/
- private void setSize(int x) {
+ private void setSize(int size) {
throw new UnsupportedOperationException("size must not be changed");
}
@@ -457,7 +455,7 @@ public class ObjectRange extends AbstractList implements Range {
private static Comparable normaliseStringType(final Comparable operand) {
if (operand instanceof Character) {
- return (int) ((Character) operand).charValue();
+ return (int) (Character) operand;
} else if (operand instanceof String) {
final String string = (String) operand;