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

[2/3] groovy git commit: Refactor: added missing @Override annotations for the Range classes (port to 2_4_X)

Refactor: added missing @Override annotations for the 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/f87a5e9d
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f87a5e9d
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f87a5e9d

Branch: refs/heads/GROOVY_2_4_X
Commit: f87a5e9d4788cc41ef64932fe71341b38492311b
Parents: 9e37804
Author: Pap L\u0151rinc <pa...@yahoo.com>
Authored: Thu Jun 30 01:52:12 2016 +0300
Committer: paulk <pa...@asert.com.au>
Committed: Fri Jul 1 17:42:20 2016 +1000

----------------------------------------------------------------------
 src/main/groovy/lang/EmptyRange.java  | 17 +++++++++++++++++
 src/main/groovy/lang/IntRange.java    | 16 ++++++++++++++++
 src/main/groovy/lang/ObjectRange.java | 15 +++++++++++++++
 3 files changed, 48 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/f87a5e9d/src/main/groovy/lang/EmptyRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/EmptyRange.java b/src/main/groovy/lang/EmptyRange.java
index df177e6..8f74a7e 100644
--- a/src/main/groovy/lang/EmptyRange.java
+++ b/src/main/groovy/lang/EmptyRange.java
@@ -49,6 +49,7 @@ public class EmptyRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public Comparable getFrom() {
         return at;
     }
@@ -56,6 +57,7 @@ public class EmptyRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public Comparable getTo() {
         return at;
     }
@@ -65,6 +67,7 @@ public class EmptyRange extends AbstractList implements Range {
      * 
      * @return <code>false</code>
      */
+    @Override
     public boolean isReverse() {
         return false;
     }
@@ -74,6 +77,7 @@ public class EmptyRange extends AbstractList implements Range {
      *
      * @return <code>false</code>
      */
+    @Override
     public boolean containsWithinBounds(Object o) {
         return false;
     }
@@ -81,6 +85,7 @@ public class EmptyRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public String inspect() {
         return InvokerHelper.inspect(at) + "..<" + InvokerHelper.inspect(at);
     }
@@ -99,6 +104,7 @@ public class EmptyRange extends AbstractList implements Range {
      * 
      * @return 0
      */
+    @Override
     public int size() {
         return 0;
     }
@@ -108,6 +114,7 @@ public class EmptyRange extends AbstractList implements Range {
      * 
      * @throws IndexOutOfBoundsException always
      */
+    @Override
     public Object get(int index) {
         throw new IndexOutOfBoundsException("can't get values from Empty Ranges");
     }
@@ -117,6 +124,7 @@ public class EmptyRange extends AbstractList implements Range {
      *
      * @throws UnsupportedOperationException always
      */
+    @Override
     public boolean add(Object o) {
         throw new UnsupportedOperationException("cannot add to Empty Ranges");
     }
@@ -126,6 +134,7 @@ public class EmptyRange extends AbstractList implements Range {
      *
      * @throws UnsupportedOperationException
      */
+    @Override
     public boolean addAll(int index, Collection c) {
         throw new UnsupportedOperationException("cannot add to Empty Ranges");
     }
@@ -135,6 +144,7 @@ public class EmptyRange extends AbstractList implements Range {
      *
      * @throws UnsupportedOperationException
      */
+    @Override
     public boolean addAll(Collection c) {
         throw new UnsupportedOperationException("cannot add to Empty Ranges");
     }
@@ -144,6 +154,7 @@ public class EmptyRange extends AbstractList implements Range {
      *
      * @throws UnsupportedOperationException
      */
+    @Override
     public boolean remove(Object o) {
         throw new UnsupportedOperationException("cannot remove from Empty Ranges");
     }
@@ -153,6 +164,7 @@ public class EmptyRange extends AbstractList implements Range {
      *
      * @throws UnsupportedOperationException
      */
+    @Override
     public Object remove(int index) {
         throw new UnsupportedOperationException("cannot remove from Empty Ranges");
     }
@@ -162,6 +174,7 @@ public class EmptyRange extends AbstractList implements Range {
      *
      * @throws UnsupportedOperationException
      */
+    @Override
     public boolean removeAll(Collection c) {
         throw new UnsupportedOperationException("cannot remove from Empty Ranges");
     }
@@ -171,6 +184,7 @@ public class EmptyRange extends AbstractList implements Range {
      *
      * @throws UnsupportedOperationException
      */
+    @Override
     public boolean retainAll(Collection c) {
         throw new UnsupportedOperationException("cannot retainAll in Empty Ranges");
     }
@@ -180,6 +194,7 @@ public class EmptyRange extends AbstractList implements Range {
       *
      * @throws UnsupportedOperationException
      */
+    @Override
     public Object set(int index, Object element) {
         throw new UnsupportedOperationException("cannot set in Empty Ranges");
     }
@@ -187,12 +202,14 @@ public class EmptyRange extends AbstractList implements Range {
     /**
      * Always does nothing for an empty range.
      */
+    @Override
     public void step(int step, Closure closure) {
     }
 
     /**
      * Always returns an empty list for an empty range.
      */
+    @Override
     public List step(int step) {
         return new ArrayList();
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/f87a5e9d/src/main/groovy/lang/IntRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/IntRange.java b/src/main/groovy/lang/IntRange.java
index 2e7b05c..bd8a768 100644
--- a/src/main/groovy/lang/IntRange.java
+++ b/src/main/groovy/lang/IntRange.java
@@ -62,10 +62,12 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
          */
         private int value = isReverse() ? getTo() : getFrom();
 
+        @Override
         public boolean hasNext() {
             return index < size;
         }
 
+        @Override
         public Integer next() {
             if (!hasNext()) {
                 // TODO instead of returning null, do this: throw new NoSuchElementException();
@@ -87,6 +89,7 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
          * @throws java.lang.UnsupportedOperationException
          *          always
          */
+        @Override
         public void remove() {
             IntRange.this.remove(index);
         }
@@ -235,6 +238,7 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
                 || (inclusive != null && inclusive == that.inclusive && from == that.from && to == that.to));
     }
 
+    @Override
     public Integer getFrom() {
         if (inclusive == null || from <= to) {
             return from;
@@ -242,6 +246,7 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
         return inclusive ? to : to + 1;
     }
 
+    @Override
     public Integer getTo() {
         if (inclusive == null) {
             return to;
@@ -277,14 +282,17 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
         return getTo();
     }
 
+    @Override
     public boolean isReverse() {
         return inclusive == null ? reverse : (from > to);
     }
 
+    @Override
     public boolean containsWithinBounds(Object o) {
         return contains(o);
     }
 
+    @Override
     public Integer get(int index) {
         if (index < 0) {
             throw new IndexOutOfBoundsException("Index: " + index + " should not be negative");
@@ -295,14 +303,17 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
         return isReverse() ? getTo() - index : index + getFrom();
     }
 
+    @Override
     public int size() {
         return getTo() - getFrom() + 1;
     }
 
+    @Override
     public Iterator<Integer> iterator() {
         return new IntRangeIterator();
     }
 
+    @Override
     public List<Integer> subList(int fromIndex, int toIndex) {
         if (fromIndex < 0) {
             throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
@@ -326,10 +337,12 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
                 : (reverse ? "" + to + ".." + from : "" + from + ".." + to);
     }
 
+    @Override
     public String inspect() {
         return toString();
     }
 
+    @Override
     public boolean contains(Object value) {
         if (value instanceof Integer) {
             return (Integer) value >= getFrom() && (Integer) value <= getTo();
@@ -341,6 +354,7 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
         return false;
     }
 
+    @Override
     public boolean containsAll(Collection other) {
         if (other instanceof IntRange) {
             final IntRange range = (IntRange) other;
@@ -349,6 +363,7 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
         return super.containsAll(other);
     }
 
+    @Override
     public void step(int step, Closure closure) {
         if (step == 0) {
             if (!getFrom().equals(getTo())) {
@@ -382,6 +397,7 @@ public class IntRange extends AbstractList<Integer> implements Range<Integer> {
         }
     }
 
+    @Override
     public List<Integer> step(int step) {
         final IteratorClosureAdapter<Integer> adapter = new IteratorClosureAdapter<Integer>(this);
         step(step, adapter);

http://git-wip-us.apache.org/repos/asf/groovy/blob/f87a5e9d/src/main/groovy/lang/ObjectRange.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/lang/ObjectRange.java b/src/main/groovy/lang/ObjectRange.java
index 688f877..9a1548f 100644
--- a/src/main/groovy/lang/ObjectRange.java
+++ b/src/main/groovy/lang/ObjectRange.java
@@ -165,6 +165,7 @@ public class ObjectRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public Comparable getFrom() {
         return from;
     }
@@ -172,6 +173,7 @@ public class ObjectRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public Comparable getTo() {
         return to;
     }
@@ -179,6 +181,7 @@ public class ObjectRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public boolean isReverse() {
         return reverse;
     }
@@ -186,6 +189,7 @@ public class ObjectRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public Object get(int index) {
         if (index < 0) {
             throw new IndexOutOfBoundsException("Index: " + index + " should not be negative");
@@ -248,6 +252,7 @@ public class ObjectRange extends AbstractList implements Range {
      * @param value the value of interest
      * @return true if the value is within the bounds
      */
+    @Override
     public boolean containsWithinBounds(Object value) {
         if (value instanceof Comparable) {
             final int result = compareTo(from, (Comparable) value);
@@ -263,6 +268,7 @@ public class ObjectRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public int size() {
         if (size == -1) {
             if ((from instanceof Integer || from instanceof Long)
@@ -301,6 +307,7 @@ public class ObjectRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public List subList(int fromIndex, int toIndex) {
         if (fromIndex < 0) {
             throw new IndexOutOfBoundsException("fromIndex = " + fromIndex);
@@ -328,12 +335,18 @@ public class ObjectRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public String inspect() {
         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) {
         final Iterator it = iterator();
         if (value == null) {
@@ -352,6 +365,7 @@ public class ObjectRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public void step(int step, Closure closure) {
         if (step == 0) {
             if (compareTo(from, to) != 0) {
@@ -391,6 +405,7 @@ public class ObjectRange extends AbstractList implements Range {
     /**
      * {@inheritDoc}
      */
+    @Override
     public List step(int step) {
         final IteratorClosureAdapter adapter = new IteratorClosureAdapter(this);
         step(step, adapter);