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:24 UTC

[2/3] incubator-groovy git commit: Groovy-7574: Allow for subclassing of ObjectRange

Groovy-7574: Allow for subclassing of ObjectRange


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/2d22ca8d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/2d22ca8d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/2d22ca8d

Branch: refs/heads/master
Commit: 2d22ca8df5fd116d833a0cf80c112c7a4c6105bb
Parents: 76c8718
Author: Thibault Kruse <th...@gmx.de>
Authored: Wed Oct 14 15:29:16 2015 +0200
Committer: paulk <pa...@asert.com.au>
Committed: Thu Oct 15 10:18:45 2015 +1000

----------------------------------------------------------------------
 src/main/groovy/lang/ObjectRange.java | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/2d22ca8d/src/main/groovy/lang/ObjectRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/ObjectRange.java b/src/main/groovy/lang/ObjectRange.java
index 61033c6..22e5527 100644
--- a/src/main/groovy/lang/ObjectRange.java
+++ b/src/main/groovy/lang/ObjectRange.java
@@ -129,11 +129,19 @@ public class ObjectRange extends AbstractList implements Range {
             this.from = normaliseStringType(smaller);
             this.to = normaliseStringType(larger);
         }
+        checkBoundaryCompatibility();
+    }
+
+    /**
+     * throws IllegalArgumentException if to and from are incompatible, meaning they e.g. (likely) produce infinite sequences.
+     * Called at construction time, subclasses may override cautiously (using only members to and from).
+     */
+    protected void checkBoundaryCompatibility() {
         if (from instanceof String || to instanceof String) {
             // this test depends deeply on the String.next implementation
             // 009.next is 00:, not 010
-            String start = smaller.toString();
-            String end = larger.toString();
+            String start = from.toString();
+            String end = to.toString();
             if (start.length() > end.length()) {
                 throw new IllegalArgumentException("Incompatible Strings for Range: starting String is longer than ending string");
             }
@@ -145,7 +153,6 @@ public class ObjectRange extends AbstractList implements Range {
             if (i < length - 1) {
                 throw new IllegalArgumentException("Incompatible Strings for Range: String#next() will not reach the expected value");
             }
-
         }
     }
 
@@ -278,7 +285,7 @@ public class ObjectRange extends AbstractList implements Range {
         return contains(value);
     }
 
-    private int compareTo(Comparable first, Comparable second) {
+    protected int compareTo(Comparable first, Comparable second) {
         return DefaultGroovyMethods.numberAwareCompareTo(first, second);
     }