directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r488969 - /directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparator/BooleanComparator.java
Date Wed, 20 Dec 2006 08:48:14 GMT
Author: elecharny
Date: Wed Dec 20 00:48:10 2006
New Revision: 488969

URL: http://svn.apache.org/viewvc?view=rev&rev=488969
Log:
Created a new package for comparators (Matchers)
Added a boolean comparator

Added:
    directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparator/BooleanComparator.java

Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparator/BooleanComparator.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparator/BooleanComparator.java?view=auto&rev=488969
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparator/BooleanComparator.java
(added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/comparator/BooleanComparator.java
Wed Dec 20 00:48:10 2006
@@ -0,0 +1,66 @@
+/*
+ *  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.shared.ldap.schema.comparator;
+
+
+import java.util.Comparator;
+
+/**
+ * A class for the BooleanComparator matchingRule (RFC 4517, par. 4.2.2)
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 437007 $
+ */
+public class BooleanComparator implements Comparator<Object>
+{
+    /**
+     * Implementation of the Compare method
+     */
+    public int compare( Object backendValue, Object assertValue ) 
+    {
+        // First, shortcut the process by comparing
+        // references. If they are equals, then o1 and o2
+        // reference the same object
+        if ( backendValue == assertValue )
+        {
+            return 0;
+        }
+        
+        // Then, deal with one of o1 or o2 being null
+        // Both can't be null, because then they would 
+        // have been catched by the previous test
+        if ( ( backendValue == null ) || ( assertValue == null ) )
+        {
+            return ( backendValue == null ? -1 : 1 );
+        }
+
+        // Both object must be stored as String for boolean
+        // values. If this is not the case, we have a pb...
+        // However, the method will then throw a ClassCastException
+        String b1 = (String)backendValue;
+
+        // The boolean should have been stored as 'TRUE' or 'FALSE'
+        // into the server, and the compare method will be called
+        // with normalized booleans, so no need to uppercase them.
+        // We don't need to check the assertion value, because we
+        // are dealing with booleans.
+        return ( b1.equals( "TRUE" ) ? 1 : -1 );
+    }
+}



Mime
View raw message