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 2016/07/01 07:48:32 UTC

[3/3] groovy git commit: Refactor: minor tidy up of style changes to Range classes (port to 2_4_X)

Refactor: minor tidy up of style changes to Range classes (port to 2_4_X)


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

Branch: refs/heads/GROOVY_2_4_X
Commit: 540595e39b3c4da7a6e6a98815da409eed452707
Parents: f87a5e9
Author: paulk <pa...@asert.com.au>
Authored: Fri Jul 1 17:17:51 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Fri Jul 1 17:47:48 2016 +1000

----------------------------------------------------------------------
 src/main/groovy/lang/EmptyRange.java     |  2 --
 src/main/groovy/lang/IntRange.java       | 16 +++++++---------
 src/main/groovy/lang/ObjectRange.java    | 15 ++++++---------
 src/main/groovy/lang/Range.java          | 13 -------------
 src/test/groovy/lang/EmptyRangeTest.java | 17 +++++++++--------
 5 files changed, 22 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/540595e3/src/main/groovy/lang/EmptyRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/EmptyRange.java b/src/main/groovy/lang/EmptyRange.java
index 8f74a7e..705ff5a 100644
--- a/src/main/groovy/lang/EmptyRange.java
+++ b/src/main/groovy/lang/EmptyRange.java
@@ -27,8 +27,6 @@ import java.util.List;
 
 /**
  * Constructing Ranges like 0..&lt;0
- * @author Dierk Koenig
- * @author Edwin Tellman
  */
 public class EmptyRange extends AbstractList implements Range {
     

http://git-wip-us.apache.org/repos/asf/groovy/blob/540595e3/src/main/groovy/lang/IntRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/IntRange.java b/src/main/groovy/lang/IntRange.java
index bd8a768..60a4c14 100644
--- a/src/main/groovy/lang/IntRange.java
+++ b/src/main/groovy/lang/IntRange.java
@@ -38,8 +38,6 @@ import java.util.List;
  * 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>
  */
 public class IntRange extends AbstractList<Integer> implements Range<Integer> {
 
@@ -346,7 +344,8 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
     public boolean contains(Object value) {
         if (value instanceof Integer) {
             return (Integer) value >= getFrom() && (Integer) value <= getTo();
-        } else if (value instanceof BigInteger) {
+        }
+        if (value instanceof BigInteger) {
             final BigInteger bigint = (BigInteger) value;
             return bigint.compareTo(BigInteger.valueOf(getFrom())) >= 0 &&
                     bigint.compareTo(BigInteger.valueOf(getTo())) <= 0;
@@ -368,9 +367,8 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
         if (step == 0) {
             if (!getFrom().equals(getTo())) {
                 throw new GroovyRuntimeException("Infinite loop detected due to step size of 0");
-            } else {
-                return; // from == to and step == 0, nothing to do, so return
             }
+            return; // from == to and step == 0, nothing to do, so return
         }
 
         if (isReverse()) {
@@ -379,8 +377,8 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
         if (step > 0) {
             int value = getFrom();
             while (value <= getTo()) {
-                closure.call(Integer.valueOf(value));
-                if((0L + value + step) >= Integer.MAX_VALUE) {
+                closure.call(value);
+                if(((long) value + step) >= Integer.MAX_VALUE) {
                     break;
                 }
                 value = value + step;
@@ -388,8 +386,8 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
         } else {
             int value = getTo();
             while (value >= getFrom()) {
-                closure.call(Integer.valueOf(value));
-                if((0L + value + step) <= Integer.MIN_VALUE) {
+                closure.call(value);
+                if(((long) value + step) <= Integer.MIN_VALUE) {
                     break;
                 }
                 value = value + step;

http://git-wip-us.apache.org/repos/asf/groovy/blob/540595e3/src/main/groovy/lang/ObjectRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/ObjectRange.java b/src/main/groovy/lang/ObjectRange.java
index 9a1548f..71839eb 100644
--- a/src/main/groovy/lang/ObjectRange.java
+++ b/src/main/groovy/lang/ObjectRange.java
@@ -36,8 +36,6 @@ import java.util.List;
  * <p>
  * 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 {
 
@@ -107,9 +105,9 @@ public class ObjectRange extends AbstractList implements Range {
         }
 
         if (from instanceof Integer && to instanceof Long) {
-            from = Long.valueOf(((Integer) from).longValue());
+            from = ((Integer) from).longValue();
         } else if (to instanceof Integer && from instanceof Long) {
-            to = Long.valueOf(((Integer) to).longValue());
+            to = ((Integer) to).longValue();
         }
 
         // TODO: should we care about different types here?
@@ -435,16 +433,15 @@ public class ObjectRange extends AbstractList implements Range {
     private static Comparable normaliseStringType(final Comparable operand) {
         if (operand instanceof Character) {
             return (int) (Character) operand;
-        } else if (operand instanceof String) {
+        }
+        if (operand instanceof String) {
             final String string = (String) operand;
 
             if (string.length() == 1) {
                 return (int) string.charAt(0);
-            } else {
-                return string;
             }
-        } else {
-            return operand;
+            return string;
         }
+        return operand;
     }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/540595e3/src/main/groovy/lang/Range.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/Range.java b/src/main/groovy/lang/Range.java
index e12f2c2..788be17 100644
--- a/src/main/groovy/lang/Range.java
+++ b/src/main/groovy/lang/Range.java
@@ -23,23 +23,10 @@ import java.util.List;
 /**
  * A Range represents the list of all items obtained by starting from a
  * <code>from</code> value and calling <code>next()</code> successively
-<<<<<<< HEAD
  * until you reach the <code>to</code> value. For a reverse range,
  * the list is obtained by starting at the <code>to</code> value and
  * successively calling <code>previous()</code> until the <code>from</code>
  * value is reached.
-=======
- * until another call to <code>next()</code> would be higher than the <code>to</code> value.
- * For a reverse range, the list is obtained by starting at the <code>to</code> value and
- * successively calling <code>previous()</code> until another call to
- * <code>previous()</code> would be lower than the <code>from</code>value.
- * <p>
- * This means in odd cases the second boundary may not be contained in the range,
- * and a..b may produce a different set of elements than (b..a).reversed().
- * E.g.  1..2.5 == [1, 2]; but 2.5..1 == [2.5, 1.5]
->>>>>>> a8413d3... Refactor: unified the style of Range related classes
- *
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
  */
 public interface Range<T extends Comparable> extends List<T> {
     /**

http://git-wip-us.apache.org/repos/asf/groovy/blob/540595e3/src/test/groovy/lang/EmptyRangeTest.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/EmptyRangeTest.java b/src/test/groovy/lang/EmptyRangeTest.java
index dfa5d89..e5e09d9 100644
--- a/src/test/groovy/lang/EmptyRangeTest.java
+++ b/src/test/groovy/lang/EmptyRangeTest.java
@@ -16,14 +16,15 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
-/**
- *
- */
 package groovy.lang;
 
 import groovy.util.GroovyTestCase;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
 
 /**
  * Provides unit tests for the {@link EmptyRange} class.
@@ -35,7 +36,7 @@ public class EmptyRangeTest extends GroovyTestCase {
     /**
      * The 'from' value for the {@link Range}.
      */
-    private static final Integer AT = new Integer(17);
+    private static final Integer AT = 17;
 
     /**
      * The {@link Range} to test.
@@ -159,7 +160,7 @@ public class EmptyRangeTest extends GroovyTestCase {
      */
     public void testAddIntObject() {
         try {
-            range.add(0, new Integer(12));
+            range.add(0, 12);
             fail("added value to empty range");
         } catch (UnsupportedOperationException e) {
             assertTrue("expected exception thrown", true);
@@ -189,7 +190,7 @@ public class EmptyRangeTest extends GroovyTestCase {
      */
     public void testAddObject() {
         try {
-            range.add(new Integer(12));
+            range.add(12);
             fail("added value to empty range");
         } catch (UnsupportedOperationException e) {
             assertTrue("expected exception thrown", true);
@@ -386,7 +387,7 @@ public class EmptyRangeTest extends GroovyTestCase {
         assertTrue("too many elements", result.isEmpty());
 
         // make sure a new list is returned each time
-        result.add(new Integer(1));
+        result.add(1);
         result = range.step(1);
         assertTrue("too many elements", result.isEmpty());
     }