bayard      02/02/20 22:26:37

  Modified:    util/src/java/org/apache/commons/util/compare
                        ComparableComparator.java
  Log:
  Throws ClassCastException instead of IllegalArgumentException as
  per Comparable interface's contract.
  Reviewed by:  Michael A. Smith
  
  Revision  Changes    Path
  1.4       +8 -8      
jakarta-commons-sandbox/util/src/java/org/apache/commons/util/compare/ComparableComparator.java
  
  Index: ComparableComparator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/util/src/java/org/apache/commons/util/compare/ComparableComparator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ComparableComparator.java 21 Feb 2002 06:16:32 -0000      1.3
  +++ ComparableComparator.java 21 Feb 2002 06:26:37 -0000      1.4
  @@ -59,14 +59,14 @@
   
   /**
    * A Comparator that compares Comparable objects.
  - * Throws IllegalArgumentExceptions if the objects are not 
  + * Throws ClassCastExceptions if the objects are not 
    * Comparable, or if they are null.
  - * Throws IllegalArgumentException if the compareTo of both 
  + * Throws ClassCastException if the compareTo of both 
    * objects do not provide an inverse result of each other 
    * as per the Comparable javadoc.
    *
    * @author [EMAIL PROTECTED]
  - * @version $Id: ComparableComparator.java,v 1.3 2002/02/21 06:16:32 bayard Exp $
  + * @version $Id: ComparableComparator.java,v 1.4 2002/02/21 06:26:37 bayard Exp $
    */
   public class ComparableComparator implements Comparator {
   
  @@ -75,7 +75,7 @@
   
       public int compare(Object o1, Object o2) {
           if( (o1 == null) || (o2 == null) ) {
  -            throw new IllegalArgumentException(
  +            throw new ClassCastException(
                   "There were nulls in the arguments for this method: "+
                   "compare("+o1 + ", " + o2 + ")"
                   );
  @@ -97,11 +97,11 @@
                       return result1;
                   } else {
                       // results inconsistent
  -                    throw new IllegalArgumentException("o1 not comparable to o2");
  +                    throw new ClassCastException("o1 not comparable to o2");
                   }
               } else {
                   // o2 wasn't comparable
  -                throw new IllegalArgumentException(
  +                throw new ClassCastException(
                       "The first argument of this method was not a Comparable: " +
                       o2.getClass().getName()
                       );
  @@ -109,13 +109,13 @@
           } else 
           if(o2 instanceof Comparable) {
               // o1 wasn't comparable
  -            throw new IllegalArgumentException(
  +            throw new ClassCastException(
                   "The second argument of this method was not a Comparable: " +
                   o1.getClass().getName()
                   );
           } else {
               // neither were comparable
  -            throw new IllegalArgumentException(
  +            throw new ClassCastException(
                   "Both arguments of this method were not Comparables: " +
                   o1.getClass().getName() + " and " + o2.getClass().getName()
                   );
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to