commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r666195 - in /commons/sandbox/functor/trunk/src: main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java
Date Tue, 10 Jun 2008 16:46:40 GMT
Author: mbenson
Date: Tue Jun 10 09:46:39 2008
New Revision: 666195

URL: http://svn.apache.org/viewvc?rev=666195&view=rev
Log:
unchecked warnings from test code; make ComparatorFunction conform to the INSTANCE vs. instance()
approach taken during the genericization process

Modified:
    commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java
    commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java

Modified: commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java?rev=666195&r1=666194&r2=666195&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java
(original)
+++ commons/sandbox/functor/trunk/src/main/java/org/apache/commons/functor/core/comparator/ComparatorFunction.java
Tue Jun 10 09:46:39 2008
@@ -29,10 +29,12 @@
  * @author Rodney Waldhoff
  */
 public final class ComparatorFunction<T> implements BinaryFunction<T, T, Integer>,
Serializable {
-    private static final ComparatorFunction<Comparable<?>> INSTANCE = new ComparatorFunction<Comparable<?>>(
-            ComparableComparator.instance());
+    /**
+     * Basic ComparatorFunction instance.
+     */
+    public static final ComparatorFunction<Comparable<?>> INSTANCE = ComparatorFunction.<Comparable<?>>instance();
 
-    private Comparator<? super T> comparator = null;
+    private Comparator<? super T> comparator;
 
     /**
      * Create a new ComparatorFunction.
@@ -86,7 +88,8 @@
      * Get a basic ComparatorFunction instance.
      * @return ComparatorFunction
      */
-    public static ComparatorFunction<Comparable<?>> instance() {
-        return INSTANCE;
+    @SuppressWarnings("unchecked")
+    public static <T> ComparatorFunction<T> instance() {
+        return new ComparatorFunction<T>(ComparableComparator.INSTANCE);
     }
 }

Modified: commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java
URL: http://svn.apache.org/viewvc/commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java?rev=666195&r1=666194&r2=666195&view=diff
==============================================================================
--- commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java
(original)
+++ commons/sandbox/functor/trunk/src/test/java/org/apache/commons/functor/core/comparator/TestComparatorFunction.java
Tue Jun 10 09:46:39 2008
@@ -44,14 +44,14 @@
     // ------------------------------------------------------------------------
 
     protected Object makeFunctor() {
-        return new ComparatorFunction(new ComparableComparator());
+        return ComparatorFunction.INSTANCE;
     }
 
     // Tests
     // ------------------------------------------------------------------------
 
     public void testEvaluate() {
-        ComparatorFunction f = ComparatorFunction.instance();
+        ComparatorFunction<Integer> f = ComparatorFunction.<Integer>instance();
 
         assertTrue(((Integer)(f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(Integer.MAX_VALUE)))).intValue()
== 0);
         assertTrue(((Integer)(f.evaluate(new Integer(Integer.MAX_VALUE),new Integer(1)))).intValue()
> 0);
@@ -84,10 +84,11 @@
         assertTrue(((Integer)(f.evaluate(new Integer(Integer.MIN_VALUE),new Integer(Integer.MIN_VALUE)))).intValue()
== 0);
     }
 
+    @SuppressWarnings("unchecked")
     public void testEquals() {
-        ComparatorFunction f = ComparatorFunction.instance();
+        ComparatorFunction<Comparable<?>> f = ComparatorFunction.instance();
         assertObjectsAreEqual(f,f);
-        assertObjectsAreEqual(f,new ComparatorFunction(new ComparableComparator()));
+        assertObjectsAreEqual(f,new ComparatorFunction<Comparable<?>>(ComparableComparator.instance()));
         assertObjectsAreNotEqual(f,new ComparatorFunction(Collections.reverseOrder()));
     }
 }



Mime
View raw message