directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r537482 - /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LongComparator.java
Date Sat, 12 May 2007 16:55:03 GMT
Author: elecharny
Date: Sat May 12 09:55:03 2007
New Revision: 537482

URL: http://svn.apache.org/viewvc?view=rev&rev=537482
Log:
Modified the compare method so that the exception are tested only
if we get a NPE (which is hopefully not something we will ever get !).
Don't call the Long.compareTo(Long) method, instead do the direct
computation in this method.

The modified method is 20% fatser than the previous one.

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LongComparator.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LongComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LongComparator.java?view=diff&rev=537482&r1=537481&r2=537482
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LongComparator.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LongComparator.java
Sat May 12 09:55:03 2007
@@ -49,18 +49,22 @@
      */
     public int compare( Object obj1, Object obj2 )
     {
-        if ( obj1 == null )
-        {
-            throw new IllegalArgumentException( "Argument 'obj1' is null" );
-        }
-
-        if ( obj2 == null )
-        {
-            throw new IllegalArgumentException( "Argument 'obj2' is null" );
-        }
-
-        Long long1 = (Long)obj1;
-        Long long2 = (Long)obj2;
-        return long1.compareTo( long2 );
+    	try
+    	{
+            Long long1 = (Long)obj1;
+            Long long2 = (Long)obj2;
+            return long1 < long2 ? -1 : long1 == long2 ? 0 : -1 ;
+    	}
+    	catch ( NullPointerException npe )
+    	{
+	        if ( obj1 == null )
+	        {
+	            throw new IllegalArgumentException( "Argument 'obj1' is null" );
+	        }
+	        else
+	        {
+	            throw new IllegalArgumentException( "Argument 'obj2' is null" );
+	        }
+    	}
     }
 }



Mime
View raw message