You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2005/11/07 15:12:29 UTC

svn commit: r331271 - /directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/AttributeUtils.java

Author: akarasulu
Date: Mon Nov  7 06:12:24 2005
New Revision: 331271

URL: http://svn.apache.org/viewcvs?rev=331271&view=rev
Log:
added some methods I have yet to use

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

Modified: directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/AttributeUtils.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/AttributeUtils.java?rev=331271&r1=331270&r2=331271&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/AttributeUtils.java (original)
+++ directory/shared/ldap/trunk/common/src/main/java/org/apache/ldap/common/util/AttributeUtils.java Mon Nov  7 06:12:24 2005
@@ -19,6 +19,8 @@
 
 import org.apache.asn1.codec.util.StringUtils;
 import org.apache.ldap.common.message.LockableAttributeImpl;
+import org.apache.ldap.common.schema.AttributeType;
+import org.apache.ldap.common.schema.Normalizer;
 
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
@@ -34,6 +36,75 @@
  */
 public class AttributeUtils
 {
+    public static boolean containsValue( Attribute attr, Object compared, AttributeType type ) throws NamingException
+    {
+        Normalizer normalizer = type.getEquality().getNormalizer();
+
+        if ( type.getSyntax().isHumanReadible() )
+        {
+            String comparedStr = ( String ) normalizer.normalize( compared );
+            for ( int ii = attr.size(); ii >= 0; ii-- )
+            {
+                String value = ( String ) attr.get( ii );
+                if ( comparedStr.equals( normalizer.normalize( value ) ) )
+                {
+                    return true;
+                }
+            }
+        }
+        else
+        {
+            byte[] comparedBytes = ( byte[] ) compared;
+            for ( int ii = attr.size(); ii >= 0; ii-- )
+            {
+                if ( ArrayUtils.isEquals( comparedBytes, attr.get( ii ) ) )
+                {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+
+    public static boolean containsAnyValues( Attribute attr, Object[] compared, AttributeType type ) throws NamingException
+    {
+        Normalizer normalizer = type.getEquality().getNormalizer();
+
+        if ( type.getSyntax().isHumanReadible() )
+        {
+            for ( int jj = 0; jj < compared.length; jj++ )
+            {
+                String comparedStr = ( String ) normalizer.normalize( compared[jj] );
+                for ( int ii = attr.size(); ii >= 0; ii-- )
+                {
+                    String value = ( String ) attr.get( ii );
+                    if ( comparedStr.equals( normalizer.normalize( value ) ) )
+                    {
+                        return true;
+                    }
+                }
+            }
+        }
+        else
+        {
+            for ( int jj = 0; jj < compared.length; jj++ )
+            {
+                byte[] comparedBytes = ( byte[] ) compared[jj];
+                for ( int ii = attr.size(); ii >= 0; ii-- )
+                {
+                    if ( ArrayUtils.isEquals( comparedBytes, attr.get( ii ) ) )
+                    {
+                        return true;
+                    }
+                }
+            }
+        }
+
+        return false;
+    }
+
     /**
      * Creates a new attribute which contains the values representing the difference
      * of two attributes.  If both attributes are null then we cannot determine the
@@ -61,7 +132,7 @@
         {
             return ( Attribute ) attr0.clone();
         }
-        else if ( ! ( ( String ) attr0.getID() ).equalsIgnoreCase( attr1.getID() ) )
+        else if ( ! attr0.getID().equalsIgnoreCase( attr1.getID() ) )
         {
             throw new IllegalArgumentException( "Cannot take difference of attributes with different IDs!" );
         }
@@ -119,7 +190,7 @@
         {
             id = attr0.getID();
         }
-        else if ( ! ( ( String ) attr0.getID() ).equalsIgnoreCase( attr1.getID() ) )
+        else if ( ! attr0.getID().equalsIgnoreCase( attr1.getID() ) )
         {
             throw new IllegalArgumentException( "Cannot take union of attributes with different IDs!" );
         }