directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r809379 - /directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectClassTypeComparator.java
Date Sun, 30 Aug 2009 17:09:18 GMT
Author: akarasulu
Date: Sun Aug 30 17:09:17 2009
New Revision: 809379

URL: http://svn.apache.org/viewvc?rev=809379&view=rev
Log:
adding missing comparator

Added:
    directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectClassTypeComparator.java

Added: directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectClassTypeComparator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectClassTypeComparator.java?rev=809379&view=auto
==============================================================================
--- directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectClassTypeComparator.java
(added)
+++ directory/shared/branches/shared-schema/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparators/ObjectClassTypeComparator.java
Sun Aug 30 17:09:17 2009
@@ -0,0 +1,71 @@
+/**
+ * 
+ */
+package org.apache.directory.shared.ldap.schema.comparators;
+
+
+import org.apache.directory.shared.ldap.schema.LdapComparator;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A comparator that compares the objectClass type with values: AUXILIARY,
+ * ABSTRACT, and STRUCTURAL.
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ObjectClassTypeComparator<T> extends LdapComparator<T> 
+{
+    private static final long serialVersionUID = 1L;
+
+    
+    public int compare( T o1, T o2 )
+    {
+        String s1 = getString( o1 );
+        String s2 = getString( o2 );
+        
+        if ( s1 == null && s2 == null )
+        {
+            return 0;
+        }
+        
+        if ( s1 == null )
+        {
+            return -1;
+        }
+        
+        if ( s2 == null )
+        {
+            return 1;
+        }
+        
+        return s1.compareTo( s2 );
+    }
+    
+    
+    String getString( T obj )
+    {
+        String strValue;
+
+        if ( obj == null )
+        {
+            return null;
+        }
+        
+        if ( obj instanceof String )
+        {
+            strValue = ( String ) obj;
+        }
+        else if ( obj instanceof byte[] )
+        {
+            strValue = StringTools.utf8ToString( ( byte[] ) obj ); 
+        }
+        else
+        {
+            strValue = obj.toString();
+        }
+
+        return strValue;
+    }
+}



Mime
View raw message