directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 36829 - incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message
Date Wed, 25 Aug 2004 01:17:50 GMT
Author: akarasulu
Date: Tue Aug 24 18:17:48 2004
New Revision: 36829

Modified:
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/SearchRequestImpl.java
Log:
Commit changes ...

 o cleaned up formatting: a_, m_ and space before ; was removed
 o added eqauls method to compare two requests
 


Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/SearchRequestImpl.java
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/SearchRequestImpl.java
(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/message/SearchRequestImpl.java
Tue Aug 24 18:17:48 2004
@@ -20,8 +20,10 @@
 import java.util.ArrayList ;
 import java.util.Collection ;
 import java.util.Collections ;
+import java.util.Iterator;
 
 import org.apache.ldap.common.filter.ExprNode ;
+import org.apache.ldap.common.filter.BranchNormalizedVisitor;
 
 
 /**
@@ -35,21 +37,21 @@
     extends AbstractRequest implements SearchRequest
 {
     /** Search base distinguished name */
-    private String m_baseDn ;
+    private String baseDn ;
     /** Search filter expression tree's root node */
-    private ExprNode m_filter ;
+    private ExprNode filter ;
     /** Search scope enumeration value */
-    private ScopeEnum m_scope ;
+    private ScopeEnum scope ;
     /** Types only return flag */
-    private boolean m_typesOnly ;
+    private boolean typesOnly ;
     /** Max size in entries to return */
-    private int m_sizeLimit ;
+    private int sizeLimit ;
     /** Max seconds to wait for search to complete */
-    private int m_timeLimit ;
+    private int timeLimit ;
     /** Alias dereferencing mode enumeration value */
-    private DerefAliasesEnum m_derefAliases ;
+    private DerefAliasesEnum derefAliases ;
     /** Attributes to return */
-    private Collection m_attributes = new ArrayList() ;
+    private Collection attributes = new ArrayList() ;
 
 
     // ------------------------------------------------------------------------
@@ -61,11 +63,11 @@
      * Creates a Lockable SearcRequest implementing object used to search the
      * DIT.
      *
-     * @param a_id the sequential message identifier
+     * @param id the sequential message identifier
      */
-    public SearchRequestImpl( final int a_id )
+    public SearchRequestImpl( final int id )
     {
-        super( a_id, TYPE, true ) ;
+        super( id, TYPE, true ) ;
     }
 
 
@@ -101,7 +103,7 @@
      */
     public Collection getAttributes()
     {
-        return Collections.unmodifiableCollection( m_attributes ) ;
+        return Collections.unmodifiableCollection( attributes ) ;
     }
 
 
@@ -112,19 +114,19 @@
      */
     public String getBase()
     {
-        return m_baseDn ;
+        return baseDn ;
     }
 
 
     /**
      * Sets the search base as a distinguished name.
      *
-     * @param a_base the search base
+     * @param base the search base
      */
-    public void setBase( String a_base )
+    public void setBase( String base )
     {
         lockCheck( "Attempt to alter search base of locked SearchRequest!" ) ;
-        m_baseDn = a_base ;
+        baseDn = base ;
     }
 
 
@@ -135,20 +137,20 @@
      */
     public DerefAliasesEnum getDerefAliases()
     {
-        return m_derefAliases ;
+        return derefAliases ;
     }
 
 
     /**
      * Sets the alias handling parameter.
      *
-     * @param a_derefAliases the alias handling parameter enumeration.
+     * @param derefAliases the alias handling parameter enumeration.
      */
-    public void setDerefAliases( DerefAliasesEnum a_derefAliases )
+    public void setDerefAliases( DerefAliasesEnum derefAliases )
     {
         lockCheck(
         "Attempt to alter alias dereferencing mode of locked SearchRequest!" ) ;
-        m_derefAliases = a_derefAliases ;
+        this.derefAliases = derefAliases ;
     }
 
 
@@ -159,20 +161,20 @@
      */
     public ExprNode getFilter()
     {
-        return m_filter ;
+        return filter ;
     }
 
 
     /**
      * Sets the search filter associated with this search request.
      *
-     * @param a_filter the expression node for the root of the filter expression
+     * @param filter the expression node for the root of the filter expression
      * tree.
      */
-    public void setFilter( ExprNode a_filter )
+    public void setFilter( ExprNode filter )
     {
         lockCheck( "Attempt to alter search filter of locked SearchRequest!" ) ;
-        m_filter = a_filter ;
+        this.filter = filter ;
     }
 
 
@@ -195,19 +197,19 @@
      */
     public ScopeEnum getScope()
     {
-        return m_scope ;
+        return scope ;
     }
 
 
     /**
      * Sets the search scope parameter enumeration.
      *
-     * @param a_scope the scope enumeration parameter.
+     * @param scope the scope enumeration parameter.
      */
-    public void setScope( ScopeEnum a_scope )
+    public void setScope( ScopeEnum scope )
     {
         lockCheck( "Attempt to alter search scope of locked SearchReqest!" ) ;
-        m_scope = a_scope ;
+        this.scope = scope ;
     }
 
 
@@ -221,7 +223,7 @@
      */
     public int getSizeLimit()
     {
-        return m_sizeLimit ;
+        return sizeLimit ;
     }
 
 
@@ -231,12 +233,12 @@
      * that no client-requested sizelimit restrictions are in effect for the
      * search.  Servers may enforce a maximum number of entries to return.
      * 
-     * @param a_entriesMax maximum search result entries to return.
+     * @param entriesMax maximum search result entries to return.
      */
-    public void setSizeLimit( int a_entriesMax )
+    public void setSizeLimit( int entriesMax )
     {
         lockCheck( "Attempt to alter size limit on locked SearchRequest!" ) ;
-        m_sizeLimit = a_entriesMax ;
+        sizeLimit = entriesMax ;
     }
 
 
@@ -249,7 +251,7 @@
      */
     public int getTimeLimit()
     {
-        return m_timeLimit ;
+        return timeLimit ;
     }
 
 
@@ -258,12 +260,12 @@
      * for a search. A value of 0 in this field indicates that no client-
      * requested timelimit restrictions are in effect for the search.
      *
-     * @param a_secondsMax the search time limit in seconds.
+     * @param secondsMax the search time limit in seconds.
      */
-    public void setTimeLimit( int a_secondsMax )
+    public void setTimeLimit( int secondsMax )
     {
         lockCheck( "Attempt to alter time limit on locked SearchRequest!" ) ;
-        m_timeLimit = a_secondsMax ;
+        timeLimit = secondsMax ;
     }
 
 
@@ -277,7 +279,7 @@
      */
     public boolean getTypesOnly()
     {
-        return m_typesOnly ;
+        return typesOnly ;
     }
 
 
@@ -287,38 +289,143 @@
      * causes only attribute types (no values) to be returned.  Setting this
      * field to FALSE causes both attribute types and values to be returned.
      *
-     * @param a_typesOnly true for only types, false for types and values.
+     * @param typesOnly true for only types, false for types and values.
      */
-    public void setTypesOnly( boolean a_typesOnly )
+    public void setTypesOnly( boolean typesOnly )
     {
         lockCheck(
             "Attempt to alter typesOnly flag of locked SearchRequest!" ) ;
-        m_typesOnly = a_typesOnly ;
+        this.typesOnly = typesOnly ;
     }
 
 
     /**
      * Adds an attribute to the set of entry attributes to return.
      *
-     * @param a_attribute the attribute description or identifier.
+     * @param attribute the attribute description or identifier.
      */
-    public void addAttribute( String a_attribute )
+    public void addAttribute( String attribute )
     {
         lockCheck(
             "Attempt to add return attribute to locked SearchRequest!" ) ;
-        m_attributes.add( a_attribute ) ;
+        attributes.add( attribute ) ;
     }
 
 
     /**
      * Removes an attribute to the set of entry attributes to return.
      *
-     * @param a_attribute the attribute description or identifier.
+     * @param attribute the attribute description or identifier.
      */
-    public void removeAttribute( String a_attribute )
+    public void removeAttribute( String attribute )
     {
         lockCheck(
             "Attempt to remove return attribute from locked SearchRequest!" ) ;
-        m_attributes.remove( a_attribute ) ;
+        attributes.remove( attribute ) ;
+    }
+
+
+    /**
+     * Checks to see if two search requests are equal.  The Lockable properties
+     * and the get/set context specific parameters are not consulted to
+     * determine equality.  The filter expression tree comparison will
+     * normalize the child order of filter branch nodes then generate a string
+     * representation which is comparable.  For the time being this is a very
+     * costly operation.
+     *
+     * @param obj the object to check for equality to this SearchRequest
+     * @return true if the obj is a SearchRequest and equals this
+     * SearchRequest, false otherwise
+     */
+    public boolean equals( Object obj )
+    {
+        if ( obj == this )
+        {
+            return true;
+        }
+
+        if ( ! super.equals( obj ) )
+        {
+            return false;
+        }
+
+        SearchRequest req = ( SearchRequest ) obj;
+
+        if ( ! req.getBase().equals( baseDn ) )
+        {
+            return false;
+        }
+
+        if ( req.getDerefAliases() != derefAliases )
+        {
+             return false;
+        }
+
+        if ( req.getScope() != scope )
+        {
+            return false;
+        }
+
+        if ( req.getSizeLimit() != sizeLimit )
+        {
+            return false;
+        }
+
+        if ( req.getTimeLimit() != timeLimit )
+        {
+            return false;
+        }
+
+        if ( req.getTypesOnly() != typesOnly )
+        {
+            return false;
+        }
+
+        if ( req.getAttributes() == null && attributes != null )
+        {
+            if ( attributes.size() > 0 )
+            {
+                return false;
+            }
+        }
+
+        if ( req.getAttributes() != null && attributes == null )
+        {
+            if ( req.getAttributes().size() > 0 )
+            {
+                return false;
+            }
+        }
+
+        if ( req.getAttributes() != null && attributes != null )
+        {
+            if ( req.getAttributes().size() != attributes.size() )
+            {
+                return false;
+            }
+
+            Iterator list = attributes.iterator();
+            while ( list.hasNext() )
+            {
+                if ( ! req.getAttributes().contains( list.next() ) )
+                {
+                    return false;
+                }
+            }
+        }
+
+        BranchNormalizedVisitor visitor = new BranchNormalizedVisitor();
+        req.getFilter().accept( visitor );
+        filter.accept( visitor );
+
+        StringBuffer buf = new StringBuffer();
+        filter.printToBuffer( buf );
+        String myFilterString = buf.toString();
+
+        buf.setLength( 0 );
+        req.getFilter().printToBuffer( buf );
+        String reqFilterString = buf.toString();
+
+        return myFilterString.equals( reqFilterString ) ;
     }
 }

Mime
View raw message