directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r939626 - /directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnComparator.java
Date Fri, 30 Apr 2010 10:39:30 GMT
Author: kayyagari
Date: Fri Apr 30 10:39:30 2010
New Revision: 939626

URL: http://svn.apache.org/viewvc?rev=939626&view=rev
Log:
fixed for the case where CSN is sent encapsulated in StringValue object

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnComparator.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnComparator.java?rev=939626&r1=939625&r2=939626&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnComparator.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/CsnComparator.java
Fri Apr 30 10:39:30 2010
@@ -21,6 +21,7 @@ package org.apache.directory.shared.ldap
 
 
 import org.apache.directory.shared.ldap.csn.Csn;
+import org.apache.directory.shared.ldap.entry.StringValue;
 import org.apache.directory.shared.ldap.schema.LdapComparator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,7 +39,7 @@ import org.slf4j.LoggerFactory;
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class CsnComparator extends LdapComparator<String>
+public class CsnComparator extends LdapComparator<Object>
 {
     /** A logger for this class */
     private static final Logger LOG = LoggerFactory.getLogger( CsnComparator.class );
@@ -59,46 +60,47 @@ public class CsnComparator extends LdapC
     /**
      * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
      */
-    public int compare( String csnStr1, String csnStr2 )
+    public int compare( Object csnObj1, Object csnObj2 )
     {
-        LOG.debug( "comparing CSN objects '{}' with '{}'", csnStr1, csnStr2 );
+        LOG.debug( "comparing CSN objects '{}' with '{}'", csnObj1, csnObj2 );
 
         // -------------------------------------------------------------------
         // Handle some basis cases
         // -------------------------------------------------------------------
-        if ( csnStr1 == null )
+        if ( csnObj1 == null )
         {
-            return ( csnStr2 == null ) ? 0 : -1;
+            return ( csnObj2 == null ) ? 0 : -1;
         }
         
-        if ( csnStr2 == null )
+        if ( csnObj2 == null )
         {
             return 1;
         }
         
-        Csn csn1 = new Csn( csnStr1 );
-        Csn csn2 = new Csn( csnStr2 );
+        String csnStr1 = null;
+        String csnStr2 = null;
         
-        if ( csn1.getTimestamp() != csn2.getTimestamp() )
+        if( csnObj1 instanceof StringValue )
         {
-            return ( csn1.getTimestamp() < csn2.getTimestamp() ? -1 : 1 );
+            csnStr1 = ( ( StringValue ) csnObj1 ).get();
         }
-        
-        if ( csn1.getChangeCount() != csn2.getChangeCount() )
+        else
         {
-            return ( csn1.getChangeCount() < csn2.getChangeCount() ? -1 : 1 );
+            csnStr1 = csnObj1.toString();
         }
-        
-        if ( csn1.getReplicaId() != csn2.getReplicaId() )
+
+        if( csnObj2 instanceof StringValue )
         {
-            return ( csn1.getReplicaId() < csn2.getReplicaId() ? -1 : 1 );
+            csnStr2 = ( ( StringValue ) csnObj2 ).get();
         }
-        
-        if ( csn1.getOperationNumber() != csn2.getOperationNumber() )
+        else
         {
-            return ( csn1.getOperationNumber() < csn2.getOperationNumber() ? -1 : 1 );
+            csnStr2 = csnObj2.toString();
         }
         
-        return 0;
+        Csn csn1 = new Csn( csnStr1 );
+        Csn csn2 = new Csn( csnStr2 );
+        
+        return csn1.compareTo( csn2 );
     }
 }



Mime
View raw message