commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r882949 - /commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java
Date Sat, 21 Nov 2009 18:07:16 GMT
Author: sebb
Date: Sat Nov 21 18:07:15 2009
New Revision: 882949

URL: http://svn.apache.org/viewvc?rev=882949&view=rev
Log:
Fix generics

Modified:
    commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java

Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java?rev=882949&r1=882948&r2=882949&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java (original)
+++ commons/proper/lang/trunk/src/java/org/apache/commons/lang/Range.java Sat Nov 21 18:07:15
2009
@@ -31,7 +31,7 @@
 
     private static final long serialVersionUID = 1L;
 
-    private final Comparator comparator;
+    private final Comparator<T> comparator;
     private final T minimum;
     private final T maximum;
 
@@ -45,8 +45,8 @@
      * @throws IllegalArgumentException if the value is <code>null</code>
      * @throws ClassCastException if the value is not Comparable
      */
-    public static <T extends Comparable> Range is(T element) {
-        return new Range(element, element, ComparableComparator.INSTANCE);
+    public static <T extends Comparable<T>> Range<T> is(T element) {
+        return new Range<T>(element, element, ComparableComparator.<T>getInstance());
     }
 
     /**
@@ -63,8 +63,8 @@
      * @throws IllegalArgumentException if either value is <code>null</code>
      * @throws ClassCastException if either value is not Comparable
      */
-    public static <T extends Comparable> Range between(T element1, T element2) {
-        return new Range( element1, element2, ComparableComparator.INSTANCE);
+    public static <T extends Comparable<T>> Range<T> between(T element1,
T element2) {
+        return new Range<T>( element1, element2, ComparableComparator.<T>getInstance());
     }
 
     /**
@@ -77,8 +77,8 @@
      * @param c comparator to be used
      * @throws IllegalArgumentException if the value is <code>null</code>
      */
-    public static <T> Range is(T element, Comparator c) {
-        return new Range(element, element, c);
+    public static <T> Range<T> is(T element, Comparator<T> c) {
+        return new Range<T>(element, element, c);
     }
 
     /**
@@ -95,11 +95,11 @@
      * @param c comparator to be used
      * @throws IllegalArgumentException if either value is <code>null</code>
      */
-    public static <T> Range between(T element1, T element2, Comparator c) {
-        return new Range(element1, element2, c);
+    public static <T> Range<T> between(T element1, T element2, Comparator<T>
c) {
+        return new Range<T>(element1, element2, c);
     }
 
-    private Range(T element1, T element2, Comparator c) {
+    private Range(T element1, T element2, Comparator<T> c) {
         if(element1 == null || element2 == null) {
             throw new IllegalArgumentException("Elements in a range must not be null: element1="
+ 
                                                element1 + ", element2=" + element2);
@@ -145,7 +145,7 @@
      *
      * @return the comparator being used
      */
-    public Comparator getComparator() {
+    public Comparator<T> getComparator() {
         return this.comparator;
     }
 
@@ -287,7 +287,8 @@
         } else if (obj == null || obj.getClass() != getClass()) {
             return false;
         } else {
-            Range range = (Range) obj;
+            @SuppressWarnings("unchecked") // OK because we checked the class above
+            Range<T> range = (Range<T>) obj;
             return getMinimum().equals(range.getMinimum()) &&
                    getMaximum().equals(range.getMaximum());
         }



Mime
View raw message