directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1655536 - in /directory/shared/trunk/ldap/client/api/src: main/java/org/apache/directory/ldap/client/api/search/ test/java/org/apache/directory/ldap/client/api/search/
Date Thu, 29 Jan 2015 06:48:12 GMT
Author: elecharny
Date: Thu Jan 29 06:48:12 2015
New Revision: 1655536

URL: http://svn.apache.org/r1655536
Log:
o Added the missing Javadoc
o Created a single FilterOperator enum used by the other classes

Added:
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterOperator.java
Modified:
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeFilter.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilter.java
    directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/UnaryFilter.java
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilterTest.java
    directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/UnaryFilterTest.java

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeFilter.java?rev=1655536&r1=1655535&r2=1655536&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeFilter.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeFilter.java
Thu Jan 29 06:48:12 2015
@@ -58,6 +58,6 @@ package org.apache.directory.ldap.client
     @Override
     public StringBuilder build( StringBuilder builder )
     {
-        return builder.append( "(" ).append( attribute ).append( "=*)" );
+        return builder.append( "(" ).append( attribute ).append( FilterOperator.PRESENT.operator()
).append( ")" );
     }
 }
\ No newline at end of file

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java?rev=1655536&r1=1655535&r2=1655536&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/AttributeValueAssertionFilter.java
Thu Jan 29 06:48:12 2015
@@ -24,19 +24,26 @@ import org.apache.directory.api.ldap.mod
 
 
 /**
- * 
- * TODO AttributeValueAssertionFilter.
+ * A class to represent the various filters that take a value, like =, <=, >= or ~=.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 /* No qualifier*/class AttributeValueAssertionFilter extends AbstractFilter
 {
+    /** The associated attribute */
     private String attribute;
+
+    /** The filter value */
     private String value;
-    private Operator operator;
+
+    /** The Filter operator */
+    private FilterOperator operator;
 
 
-    private AttributeValueAssertionFilter( String attribute, String value, Operator operator
)
+    /**
+     * Creates a new instance of AttributeValueAssertionFilter.
+     */
+    private AttributeValueAssertionFilter( String attribute, String value, FilterOperator
operator )
     {
         this.attribute = attribute;
         this.value = value;
@@ -44,30 +51,61 @@ import org.apache.directory.api.ldap.mod
     }
 
 
+    /**
+     * Creates an Approximate Filter : ( <attribute> ~= <value> )
+     *
+     * @param attribute The AttributeType
+     * @param value The Value
+     * @return An instance of the Approximate Filter
+     */
     public static AttributeValueAssertionFilter approximatelyEqual( String attribute, String
value )
     {
-        return new AttributeValueAssertionFilter( attribute, value, Operator.APPROXIMATELY_EQUAL
);
+        return new AttributeValueAssertionFilter( attribute, value, FilterOperator.APPROXIMATELY_EQUAL
);
     }
 
 
+    /**
+     * Creates an equam Filter : ( <attribute> = <value> )
+     *
+     * @param attribute The AttributeType
+     * @param value The Value
+     * @return An instance of the Equal Filter
+     */
     public static AttributeValueAssertionFilter equal( String attribute, String value )
     {
-        return new AttributeValueAssertionFilter( attribute, value, Operator.EQUAL );
+        return new AttributeValueAssertionFilter( attribute, value, FilterOperator.EQUAL
);
     }
 
 
+    /**
+     * Creates a Greater Than Or Equal Filter : ( <attribute> >= <value> )
+     *
+     * @param attribute The AttributeType
+     * @param value The Value
+     * @return An instance of the Greater Than Or Equal Filter
+     */
     public static AttributeValueAssertionFilter greaterThanOrEqual( String attribute, String
value )
     {
-        return new AttributeValueAssertionFilter( attribute, value, Operator.GREATER_THAN_OR_EQUAL
);
+        return new AttributeValueAssertionFilter( attribute, value, FilterOperator.GREATER_THAN_OR_EQUAL
);
     }
 
 
+    /**
+     * Creates a Less Than Or Equal Filter : ( <attribute> <= <value> )
+     *
+     * @param attribute The AttributeType
+     * @param value The Value
+     * @return An instance of the Less Than Or Equal Filter
+     */
     public static AttributeValueAssertionFilter lessThanOrEqual( String attribute, String
value )
     {
-        return new AttributeValueAssertionFilter( attribute, value, Operator.LESS_THAN_OR_EQUAL
);
+        return new AttributeValueAssertionFilter( attribute, value, FilterOperator.LESS_THAN_OR_EQUAL
);
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public StringBuilder build( StringBuilder builder )
     {
@@ -75,26 +113,4 @@ import org.apache.directory.api.ldap.mod
             .append( operator.operator() )
             .append( FilterEncoder.encodeFilterValue( value ) ).append( ")" );
     }
-
-    public static enum Operator
-    {
-        APPROXIMATELY_EQUAL("~="),
-        EQUAL("="),
-        GREATER_THAN_OR_EQUAL(">="),
-        LESS_THAN_OR_EQUAL("<=");
-
-        private String operator;
-
-
-        private Operator( String operator )
-        {
-            this.operator = operator;
-        }
-
-
-        public String operator()
-        {
-            return operator;
-        }
-    }
 }
\ No newline at end of file

Added: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterOperator.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterOperator.java?rev=1655536&view=auto
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterOperator.java
(added)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/FilterOperator.java
Thu Jan 29 06:48:12 2015
@@ -0,0 +1,70 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+
+package org.apache.directory.ldap.client.api.search;
+
+
+/**
+ * The operators that can be used in a Filter :
+ * <ul>
+ * <li>AND: the '&' operator</li>
+ * <li>OR: the '|' operator</li>
+ * <li>NOT: the '!' operator</li>
+ * <li>EQUAL: the '=' operator</li>
+ * <li>LESS_THAN_OR_EQUAL: the '<=' operator</li>
+ * <li>GREATER_THAN_OR_EQUAL: the '>=' operator</li>
+ * <li>PRESENT: the '=*' operator</li>
+ * <li>APPROXIMATELY_EQUAL: the '~=' operator</li>
+ * </ul>
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+/* No Qualifier */enum FilterOperator
+{
+    AND("&"),
+    OR("|"),
+    NOT("!"),
+    APPROXIMATELY_EQUAL("~="),
+    EQUAL("="),
+    PRESENT("=*"),
+    GREATER_THAN_OR_EQUAL(">="),
+    LESS_THAN_OR_EQUAL("<=");
+
+    /** The String representing the operator in a FIlter */
+    private String operator;
+
+
+    /**
+     * Creates a new instance of FilterOperator.
+     */
+    private FilterOperator( String operator )
+    {
+        this.operator = operator;
+    }
+
+
+    /**
+     * @return The String representation of the operator
+     */
+    public String operator()
+    {
+        return operator;
+    }
+}

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilter.java?rev=1655536&r1=1655535&r2=1655536&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilter.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilter.java
Thu Jan 29 06:48:12 2015
@@ -31,17 +31,29 @@ import java.util.List;
  */
 /* No qualifier*/class SetOfFiltersFilter extends AbstractFilter
 {
-    private Operator operator;
+    /** The operator to use with this set (AND or OR) */
+    private FilterOperator operator;
+
+    /** The list of inner filters */
     private List<Filter> filters;
 
 
-    private SetOfFiltersFilter( Operator operator )
+    /**
+     * Creates a new instance of SetOfFiltersFilter.
+     */
+    private SetOfFiltersFilter( FilterOperator operator )
     {
         this.operator = operator;
         this.filters = new ArrayList<Filter>();
     }
 
 
+    /**
+     * Adds a Filter into the set of Filters 
+     *
+     * @param filter The filter to add
+     * @return The Set of Filters with the added filter
+     */
     public SetOfFiltersFilter add( Filter filter )
     {
         filters.add( filter );
@@ -49,6 +61,12 @@ import java.util.List;
     }
 
 
+    /**
+     * Injects a list of Filters into the set of Filters 
+     *
+     * @param filters The filters to inject
+     * @return The Set of Filters with the injected filters
+     */
     public SetOfFiltersFilter addAll( Filter... filters )
     {
         for ( Filter filter : filters )
@@ -60,25 +78,47 @@ import java.util.List;
     }
 
 
+    /**
+     * Injects a list of Filters into the set of Filters 
+     *
+     * @param filters The filters to inject
+     * @return The Set of Filters with the injected filters
+     */
     public SetOfFiltersFilter addAll( List<Filter> filters )
     {
         this.filters.addAll( filters );
+
         return this;
     }
 
 
+    /**
+     * Creates an AND set of filters
+     *
+     * @param filters The inner filters
+     * @return An AND filter
+     */
     public static SetOfFiltersFilter and( Filter... filters )
     {
-        return new SetOfFiltersFilter( Operator.AND ).addAll( filters );
+        return new SetOfFiltersFilter( FilterOperator.AND ).addAll( filters );
     }
 
 
+    /**
+     * Creates an OR set of filters
+     *
+     * @param filters The inner filters
+     * @return An OR filter
+     */
     public static SetOfFiltersFilter or( Filter... filters )
     {
-        return new SetOfFiltersFilter( Operator.OR ).addAll( filters );
+        return new SetOfFiltersFilter( FilterOperator.OR ).addAll( filters );
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public StringBuilder build( StringBuilder builder )
     {
@@ -96,24 +136,4 @@ import java.util.List;
 
         return builder.append( ")" );
     }
-
-    public static enum Operator
-    {
-        AND("&"),
-        OR("|");
-
-        private String operator;
-
-
-        private Operator( String operator )
-        {
-            this.operator = operator;
-        }
-
-
-        public String operator()
-        {
-            return operator;
-        }
-    }
 }
\ No newline at end of file

Modified: directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/UnaryFilter.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/UnaryFilter.java?rev=1655536&r1=1655535&r2=1655536&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/UnaryFilter.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/search/UnaryFilter.java
Thu Jan 29 06:48:12 2015
@@ -20,37 +20,54 @@
 package org.apache.directory.ldap.client.api.search;
 
 
+/**
+ * Creates a NOT filter
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
 /* No qualifier*/class UnaryFilter extends AbstractFilter
 {
-    private Operator operator;
+    /** The NOT filter */
     private Filter filter;
 
 
-    private UnaryFilter( Operator operator )
+    /**
+     * Creates a new instance of UnaryFilter.
+     */
+    private UnaryFilter()
     {
-        this.operator = operator;
-    }
-
-
-    public UnaryFilter setFilter( Filter filter )
-    {
-        this.filter = filter;
-        return this;
     }
 
 
+    /**
+     * Constructs a NOT filter 
+     *
+     * @return The constructed NOT Filter
+     */
     public static UnaryFilter not()
     {
-        return new UnaryFilter( Operator.NOT );
+        return new UnaryFilter();
     }
 
 
+    /**
+     * Constructs a NOT filter with the associated inner Filter
+     *
+     * @param Filter The inner Filter
+     * @return The constructed NOT Filter
+     */
     public static UnaryFilter not( Filter filter )
     {
-        return not().setFilter( filter );
+        UnaryFilter notFilter = not();
+        notFilter.filter = filter;
+
+        return notFilter;
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public StringBuilder build( StringBuilder builder )
     {
@@ -59,28 +76,9 @@ package org.apache.directory.ldap.client
             throw new IllegalStateException( "filter not set" );
         }
 
-        builder.append( "(" ).append( operator.operator() );
+        builder.append( "(" ).append( FilterOperator.NOT.operator() );
         filter.build( builder );
 
         return builder.append( ")" );
     }
-
-    public static enum Operator
-    {
-        NOT("!");
-
-        private String operator;
-
-
-        private Operator( String operator )
-        {
-            this.operator = operator;
-        }
-
-
-        public String operator()
-        {
-            return operator;
-        }
-    }
 }
\ No newline at end of file

Modified: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilterTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilterTest.java?rev=1655536&r1=1655535&r2=1655536&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilterTest.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/SetOfFiltersFilterTest.java
Thu Jan 29 06:48:12 2015
@@ -35,7 +35,7 @@ import org.junit.Test;
  */
 public class SetOfFiltersFilterTest
 {
-    private String expected( SetOfFiltersFilter.Operator operator, Filter... filters )
+    private String expected( FilterOperator operator, Filter... filters )
     {
         StringBuilder builder = new StringBuilder( "(" )
             .append( operator.operator() );
@@ -55,7 +55,7 @@ public class SetOfFiltersFilterTest
         AttributeFilter attributeFilter = AttributeFilter.present( "objectClass" );
         AttributeValueAssertionFilter attributeValueAssertionFilter =
             AttributeValueAssertionFilter.equal( "objectClass", "person" );
-        String expected = expected( SetOfFiltersFilter.Operator.AND, attributeFilter, attributeValueAssertionFilter
);
+        String expected = expected( FilterOperator.AND, attributeFilter, attributeValueAssertionFilter
);
 
         assertEquals( expected,
             SetOfFiltersFilter.and( attributeFilter, attributeValueAssertionFilter )
@@ -85,7 +85,7 @@ public class SetOfFiltersFilterTest
         AttributeFilter attributeFilter = AttributeFilter.present( "objectClass" );
         AttributeValueAssertionFilter attributeValueAssertionFilter =
             AttributeValueAssertionFilter.equal( "objectClass", "person" );
-        String expected = expected( SetOfFiltersFilter.Operator.OR, attributeFilter, attributeValueAssertionFilter
);
+        String expected = expected( FilterOperator.OR, attributeFilter, attributeValueAssertionFilter
);
 
         assertEquals( expected,
             SetOfFiltersFilter.or( attributeFilter, attributeValueAssertionFilter )

Modified: directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/UnaryFilterTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/UnaryFilterTest.java?rev=1655536&r1=1655535&r2=1655536&view=diff
==============================================================================
--- directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/UnaryFilterTest.java
(original)
+++ directory/shared/trunk/ldap/client/api/src/test/java/org/apache/directory/ldap/client/api/search/UnaryFilterTest.java
Thu Jan 29 06:48:12 2015
@@ -39,14 +39,10 @@ public class UnaryFilterTest
         AttributeFilter attributeFilter = AttributeFilter.present( "objectClass" );
         assertEquals( "(!" + attributeFilter.build().toString() + ")",
             UnaryFilter.not( attributeFilter ).build().toString() );
-        assertEquals( "(!" + attributeFilter.build().toString() + ")",
-            UnaryFilter.not().setFilter( attributeFilter ).build().toString() );
 
         AttributeValueAssertionFilter attributeValueAssertionFilter =
             AttributeValueAssertionFilter.equal( "objectClass", "person" );
         assertEquals( "(!" + attributeValueAssertionFilter.build().toString() + ")",
             UnaryFilter.not( attributeValueAssertionFilter ).build().toString() );
-        assertEquals( "(!" + attributeValueAssertionFilter.build().toString() + ")",
-            UnaryFilter.not().setFilter( attributeValueAssertionFilter ).build().toString()
);
     }
 }



Mime
View raw message