svn commit: r915686 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ComparableRange.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r915686 - /ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ComparableRange.java

doogie-3
Author: doogie
Date: Wed Feb 24 05:43:41 2010
New Revision: 915686

URL: http://svn.apache.org/viewvc?rev=915686&view=rev
Log:
Improve generics markup, T extends Comparable<T>, which means no more
casting as to be done.

Modified:
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ComparableRange.java

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ComparableRange.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ComparableRange.java?rev=915686&r1=915685&r2=915686&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ComparableRange.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ComparableRange.java Wed Feb 24 05:43:41 2010
@@ -19,50 +19,44 @@
 package org.ofbiz.base.util;
 
 /** An immutable range of values. */
-public class ComparableRange<T> implements Range<T> {
-
-    @SuppressWarnings("unchecked")
-    protected static <T> Comparable<T> cast(T value) {
-        return (Comparable<T>) value;
-    }
+public class ComparableRange<T extends Comparable<T>> implements Range<T> {
 
     protected final T start;
     protected final T end;
     protected final boolean isPoint;
 
-    @SuppressWarnings("unchecked")
-    public ComparableRange(Comparable<T> start, Comparable<T> end) {
+    public ComparableRange(T start, T end) {
         if (start.getClass() != end.getClass()) {
             throw new IllegalArgumentException("start Class and end Class must be the same");
         }
-        if (end.compareTo((T) start) >= 0) {
-            this.start = (T) start;
-            this.end = (T) end;
+        if (end.compareTo(start) >= 0) {
+            this.start = start;
+            this.end = end;
         } else {
-            this.start = (T) end;
-            this.end = (T) start;
+            this.start = end;
+            this.end = start;
         }
         this.isPoint = start.equals(end);
     }
 
     @Override
     public boolean after(Range<T> range) {
-        return cast(this.start).compareTo(range.end()) > 0;
+        return this.start.compareTo(range.end()) > 0;
     }
 
     @Override
     public boolean after(T value) {
-        return cast(this.start).compareTo(value) > 0;
+        return this.start.compareTo(value) > 0;
     }
 
     @Override
     public boolean before(Range<T> range) {
-        return cast(this.end).compareTo(range.start()) < 0;
+        return this.end.compareTo(range.start()) < 0;
     }
 
     @Override
     public boolean before(T value) {
-        return cast(this.end).compareTo(value) < 0;
+        return this.end.compareTo(value) < 0;
     }
 
     @Override
@@ -70,14 +64,13 @@
         return this.end;
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public boolean equals(Object obj) {
         if (obj == this) {
             return true;
         }
         try {
-            ComparableRange<T> that = (ComparableRange<T>) obj;
+            ComparableRange that = (ComparableRange) obj;
             return this.start.equals(that.start) && this.end.equals(that.end);
         } catch (ClassCastException e) {}
         return false;
@@ -93,7 +86,7 @@
         if (this.isPoint) {
             return value.equals(this.start);
         }
-        return (cast(value).compareTo(this.start) >= 0 && cast(value).compareTo(this.end) <= 0);
+        return (value.compareTo(this.start) >= 0 && value.compareTo(this.end) <= 0);
     }
 
     @Override