You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2007/05/12 18:55:03 UTC
svn commit: r537482 -
/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LongComparator.java
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" );
+ }
+ }
}
}