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 2004/10/21 23:53:44 UTC

svn commit: rev 55270 - incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema

Author: akarasulu
Date: Thu Oct 21 14:53:44 2004
New Revision: 55270

Added:
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/AcceptAllSyntaxChecker.java
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ComparableComparator.java
Log:
Commit changes ...

 o added new comparator to detect and use Comparables
 o added new accept all syntax checker which is a no-op checker
   that accepts all values as being valid to whatever is its syntax



Added: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/AcceptAllSyntaxChecker.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/AcceptAllSyntaxChecker.java	Thu Oct 21 14:53:44 2004
@@ -0,0 +1,74 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.common.schema;
+
+
+import javax.naming.NamingException;
+
+
+/**
+ * A SyntaxChecker implementation which accepts all values as valid.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class AcceptAllSyntaxChecker implements SyntaxChecker
+{
+    /** the OID of the Syntax this checker is associated with */
+    private final String oid;
+
+
+    /**
+     * Creates a SyntaxChecker which accepts all values.
+     *
+     * @param oid the oid of the Syntax this checker is associated with
+     */
+    public AcceptAllSyntaxChecker( String oid )
+    {
+        this.oid = oid;
+    }
+
+
+    /**
+     * @see SyntaxChecker#getSyntaxOid()
+     */
+    public String getSyntaxOid()
+    {
+        return oid;
+    }
+
+
+    /**
+     * Returns true every time.
+     *
+     * @see SyntaxChecker#isValidSyntax(Object)
+     */
+    public boolean isValidSyntax( Object a_value )
+    {
+        return true;
+    }
+
+
+    /**
+     * Does nothing but return immediately and no exceptions are ever thrown.
+     *
+     * @see SyntaxChecker#assertSyntax(Object)
+     */
+    public void assertSyntax( Object value ) throws NamingException
+    {
+    }
+}

Added: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ComparableComparator.java
==============================================================================
--- (empty file)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/schema/ComparableComparator.java	Thu Oct 21 14:53:44 2004
@@ -0,0 +1,55 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed 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.ldap.common.schema;
+
+
+import java.util.Comparator;
+
+
+/**
+ * Compares two objects taking into account that one might be a Comparable.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ComparableComparator implements Comparator
+{
+    /**
+     * Compares two objects taking into account that one may be a Comparable.
+     * If the first is a comparable then its compareTo operation is called and
+     * the result returned as is.  If the first is not a Comparable but the
+     * second is then its compareTo method is called and the result is returned
+     * after being negated.  If none are comparables the hashCode of o1 minus
+     * the hashCode of o2 is returned.
+     *
+     * @see Comparator#compare(Object, Object)
+     */
+    public int compare( Object o1, Object o2 )
+    {
+        if ( o1 instanceof Comparable )
+        {
+            return ( ( Comparable ) o1 ).compareTo( o2 );
+        }
+
+        if ( o2 instanceof Comparable )
+        {
+            return - ( ( Comparable ) o2 ).compareTo( o1 );
+        }
+
+        return o1.hashCode() - o2.hashCode();
+    }
+}