groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pa...@apache.org
Subject groovy git commit: minor refactor: generify EmptyRange
Date Sun, 10 Jul 2016 11:12:58 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 057cf3661 -> 43140c893


minor refactor: generify EmptyRange


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

Branch: refs/heads/master
Commit: 43140c893a55c1958a2e6f606c59ea371f8a2306
Parents: 057cf36
Author: paulk <paulk@asert.com.au>
Authored: Sun Jul 10 21:12:47 2016 +1000
Committer: paulk <paulk@asert.com.au>
Committed: Sun Jul 10 21:12:47 2016 +1000

----------------------------------------------------------------------
 src/main/groovy/lang/EmptyRange.java  | 30 +++++++++++++++---------------
 src/main/groovy/lang/IntRange.java    |  2 +-
 src/main/groovy/lang/ObjectRange.java |  2 +-
 src/main/groovy/lang/Range.java       |  2 --
 4 files changed, 17 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/43140c89/src/main/groovy/lang/EmptyRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/EmptyRange.java b/src/main/groovy/lang/EmptyRange.java
index 2b5e73a..b67b32e 100644
--- a/src/main/groovy/lang/EmptyRange.java
+++ b/src/main/groovy/lang/EmptyRange.java
@@ -28,19 +28,19 @@ import java.util.List;
 /**
  * Constructing Ranges like 0..&lt;0
  */
-public class EmptyRange extends AbstractList implements Range {
+public class EmptyRange<T extends Comparable> extends AbstractList<T> implements
Range<T> {
 
     /**
      * The value at which the range originates (may be <code>null</code>).
      */
-    protected Comparable at;
+    protected T at;
 
     /**
      * Creates a new {@link EmptyRange}.
      *
      * @param at the value at which the range starts (may be <code>null</code>).
      */
-    public EmptyRange(Comparable at) {
+    public EmptyRange(T at) {
         this.at = at;
     }
 
@@ -48,7 +48,7 @@ public class EmptyRange extends AbstractList implements Range {
      * {@inheritDoc}
      */
     @Override
-    public Comparable getFrom() {
+    public T getFrom() {
         return at;
     }
 
@@ -56,7 +56,7 @@ public class EmptyRange extends AbstractList implements Range {
      * {@inheritDoc}
      */
     @Override
-    public Comparable getTo() {
+    public T getTo() {
         return at;
     }
 
@@ -113,7 +113,7 @@ public class EmptyRange extends AbstractList implements Range {
      * @throws IndexOutOfBoundsException always
      */
     @Override
-    public Object get(int index) {
+    public T get(int index) {
         throw new IndexOutOfBoundsException("can't get values from Empty Ranges");
     }
 
@@ -123,7 +123,7 @@ public class EmptyRange extends AbstractList implements Range {
      * @throws UnsupportedOperationException always
      */
     @Override
-    public boolean add(Object o) {
+    public boolean add(T o) {
         throw new UnsupportedOperationException("cannot add to Empty Ranges");
     }
 
@@ -133,7 +133,7 @@ public class EmptyRange extends AbstractList implements Range {
      * @throws UnsupportedOperationException
      */
     @Override
-    public boolean addAll(int index, Collection c) {
+    public boolean addAll(int index, Collection<? extends T> c) {
         throw new UnsupportedOperationException("cannot add to Empty Ranges");
     }
 
@@ -143,7 +143,7 @@ public class EmptyRange extends AbstractList implements Range {
      * @throws UnsupportedOperationException
      */
     @Override
-    public boolean addAll(Collection c) {
+    public boolean addAll(Collection<? extends T> c) {
         throw new UnsupportedOperationException("cannot add to Empty Ranges");
     }
 
@@ -163,7 +163,7 @@ public class EmptyRange extends AbstractList implements Range {
      * @throws UnsupportedOperationException
      */
     @Override
-    public Object remove(int index) {
+    public T remove(int index) {
         throw new UnsupportedOperationException("cannot remove from Empty Ranges");
     }
 
@@ -173,7 +173,7 @@ public class EmptyRange extends AbstractList implements Range {
      * @throws UnsupportedOperationException
      */
     @Override
-    public boolean removeAll(Collection c) {
+    public boolean removeAll(Collection<?> c) {
         throw new UnsupportedOperationException("cannot remove from Empty Ranges");
     }
 
@@ -183,7 +183,7 @@ public class EmptyRange extends AbstractList implements Range {
      * @throws UnsupportedOperationException
      */
     @Override
-    public boolean retainAll(Collection c) {
+    public boolean retainAll(Collection<?> c) {
         throw new UnsupportedOperationException("cannot retainAll in Empty Ranges");
     }
 
@@ -193,7 +193,7 @@ public class EmptyRange extends AbstractList implements Range {
      * @throws UnsupportedOperationException
      */
     @Override
-    public Object set(int index, Object element) {
+    public T set(int index, T element) {
         throw new UnsupportedOperationException("cannot set in Empty Ranges");
     }
 
@@ -208,7 +208,7 @@ public class EmptyRange extends AbstractList implements Range {
      * Always returns an empty list for an empty range.
      */
     @Override
-    public List step(int step) {
-        return new ArrayList();
+    public List<T> step(int step) {
+        return new ArrayList<T>();
     }
 }

http://git-wip-us.apache.org/repos/asf/groovy/blob/43140c89/src/main/groovy/lang/IntRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/IntRange.java b/src/main/groovy/lang/IntRange.java
index 574e24e..3855f43 100644
--- a/src/main/groovy/lang/IntRange.java
+++ b/src/main/groovy/lang/IntRange.java
@@ -338,7 +338,7 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer>
{
         }
 
         if (fromIndex == toIndex) {
-            return new EmptyRange(getFrom());
+            return new EmptyRange<Integer>(getFrom());
         }
 
         return new IntRange(fromIndex + getFrom(), toIndex + getFrom() - 1, isReverse());

http://git-wip-us.apache.org/repos/asf/groovy/blob/43140c89/src/main/groovy/lang/ObjectRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/ObjectRange.java b/src/main/groovy/lang/ObjectRange.java
index d198e42..efb9bd2 100644
--- a/src/main/groovy/lang/ObjectRange.java
+++ b/src/main/groovy/lang/ObjectRange.java
@@ -337,7 +337,7 @@ public class ObjectRange extends AbstractList implements Range {
             throw new IllegalArgumentException("fromIndex(" + fromIndex + ") > toIndex("
+ toIndex + ")");
         }
         if (fromIndex == toIndex) {
-            return new EmptyRange(from);
+            return new EmptyRange<Comparable>(from);
         }
 
         // Performance detail:

http://git-wip-us.apache.org/repos/asf/groovy/blob/43140c89/src/main/groovy/lang/Range.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/Range.java b/src/main/groovy/lang/Range.java
index 8f37707..6cf1be4 100644
--- a/src/main/groovy/lang/Range.java
+++ b/src/main/groovy/lang/Range.java
@@ -31,8 +31,6 @@ import java.util.List;
  * 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]
- *
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
  */
 public interface Range<T extends Comparable> extends List<T> {
     /**


Mime
View raw message