From d73dd29ce6a19cd9f81bc4db24d50a5b53f45a3c Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Fri, 13 Feb 2015 11:32:45 +0000
Subject: [PATCH] OPENDJ-1689: Remove MatchingRule.comparator() and MatchingRuleImpl.comparator()

---
 opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OrderingMatchingRuleTest.java                           |    4 
 opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRuleImpl.java |   35 -----
 opendj-core/clirr-ignored-api-changes.xml                                                                          |   12 ++
 opendj-core/src/main/java/org/forgerock/opendj/ldap/SortKey.java                                                   |   12 -
 opendj-server-legacy/src/main/java/org/opends/server/types/RDN.java                                                |    4 
 opendj-server-legacy/src/test/java/org/opends/server/schema/AttributeTypeSyntaxTest.java                           |   18 --
 opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java                              |    6 
 /dev/null                                                                                                          |  131 ---------------------
 opendj-server-legacy/src/main/java/org/opends/server/schema/AbstractPasswordEqualityMatchingRuleImpl.java          |   10 -
 opendj-server-legacy/src/main/java/org/opends/server/types/SortKey.java                                            |   11 -
 opendj-core/src/main/java/org/forgerock/opendj/ldap/AVA.java                                                       |   19 --
 opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaTestMatchingRuleImpl.java                      |   27 ----
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleImpl.java                                   |   20 +--
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRule.java                                       |   21 +--
 opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/VLVKeyComparator.java                            |   13 -
 opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java                           |    9 -
 16 files changed, 52 insertions(+), 300 deletions(-)

diff --git a/opendj-core/clirr-ignored-api-changes.xml b/opendj-core/clirr-ignored-api-changes.xml
index e69eea0..69d76ba 100644
--- a/opendj-core/clirr-ignored-api-changes.xml
+++ b/opendj-core/clirr-ignored-api-changes.xml
@@ -408,4 +408,16 @@
     <method>boolean copyTo(java.nio.CharBuffer, java.nio.charset.CharsetDecoder)</method>
     <justification>OPENDJ-1585: Added new utility method copyTo for a char buffer</justification>
   </difference>
+  <difference>
+    <className>org/forgerock/opendj/ldap/schema/MatchingRule</className>
+    <differenceType>7002</differenceType>
+    <method>java.util.Comparator comparator()</method>
+    <justification>OPENDJ-1689 method has been removed because all matching rules should support the default comparator</justification>
+  </difference>
+  <difference>
+    <className>org/forgerock/opendj/ldap/schema/MatchingRuleImpl</className>
+    <differenceType>7002</differenceType>
+    <method>java.util.Comparator comparator(org.forgerock.opendj.ldap.schema.Schema)</method>
+    <justification>OPENDJ-1689 method has been removed because all matching rules should support the default comparator</justification>
+  </difference>
 </differences>
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/AVA.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/AVA.java
index b4baf5b..6b84fbf 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/AVA.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/AVA.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2010 Sun Microsystems, Inc.
- *      Portions copyright 2011-2012 ForgeRock AS.
+ *      Portions copyright 2011-2015 ForgeRock AS.
  */
 
 package org.forgerock.opendj.ldap;
@@ -36,7 +36,6 @@
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CodingErrorAction;
-import java.util.Comparator;
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.LocalizedIllegalArgumentException;
@@ -657,13 +656,7 @@
 
         final ByteString normalizedValue = getOrderingNormalizedValue();
         final ByteString otherNormalizedValue = ava.getOrderingNormalizedValue();
-        final MatchingRule rule = attributeType.getOrderingMatchingRule();
-        if (rule != null) {
-            final Comparator<ByteSequence> comparator = rule.comparator();
-            return comparator.compare(normalizedValue, otherNormalizedValue);
-        } else {
-            return normalizedValue.compareTo(otherNormalizedValue);
-        }
+        return normalizedValue.compareTo(otherNormalizedValue);
     }
 
     /** {@inheritDoc} */
@@ -680,13 +673,7 @@
 
             final ByteString normalizedValue = getEqualityNormalizedValue();
             final ByteString otherNormalizedValue = ava.getEqualityNormalizedValue();
-            final MatchingRule rule = attributeType.getEqualityMatchingRule();
-            if (rule != null) {
-                final Comparator<ByteSequence> comparator = rule.comparator();
-                return comparator.compare(normalizedValue, otherNormalizedValue) == 0;
-            } else {
-                return normalizedValue.equals(otherNormalizedValue);
-            }
+            return normalizedValue.equals(otherNormalizedValue);
         } else {
             return false;
         }
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/SortKey.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/SortKey.java
index 55fa9b9..178c0f4 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/SortKey.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/SortKey.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2010 Sun Microsystems, Inc.
- *      Portions copyright 2012-2013 ForgeRock AS.
+ *      Portions copyright 2012-2015 ForgeRock AS.
  */
 package org.forgerock.opendj.ldap;
 
@@ -98,14 +98,12 @@
     private static final class EntryComparator implements Comparator<Entry> {
         private final AttributeDescription attributeDescription;
         private final MatchingRule matchingRule;
-        private final Comparator<ByteSequence> valueComparator;
         private final boolean isReverseOrder;
 
         private EntryComparator(final AttributeDescription attributeDescription,
                 final MatchingRule matchingRule, final boolean isReverseOrder) {
             this.attributeDescription = attributeDescription;
             this.matchingRule = matchingRule;
-            this.valueComparator = matchingRule.comparator();
             this.isReverseOrder = isReverseOrder;
         }
 
@@ -125,9 +123,9 @@
             } else if (normalizedValue2 == null) {
                 return -1;
             } else if (isReverseOrder) {
-                return valueComparator.compare(normalizedValue2, normalizedValue1);
+                return normalizedValue2.compareTo(normalizedValue1);
             } else {
-                return valueComparator.compare(normalizedValue1, normalizedValue2);
+                return normalizedValue1.compareTo(normalizedValue2);
             }
         }
 
@@ -137,9 +135,7 @@
                 for (final ByteString value : attribute) {
                     try {
                         final ByteString tmp = matchingRule.normalizeAttributeValue(value);
-                        if (normalizedValue == null) {
-                            normalizedValue = tmp;
-                        } else if (valueComparator.compare(tmp, normalizedValue) < 0) {
+                        if (normalizedValue == null || tmp.compareTo(normalizedValue) < 0) {
                             normalizedValue = tmp;
                         }
                     } catch (final DecodeException ignored) {
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java
index d95745c..69233fc 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/AbstractMatchingRuleImpl.java
@@ -22,12 +22,11 @@
  *
  *
  *      Copyright 2009 Sun Microsystems, Inc.
- *      Portions copyright 2014 ForgeRock AS
+ *      Portions copyright 2014-2015 ForgeRock AS
  */
 package org.forgerock.opendj.ldap.schema;
 
 import java.util.Collection;
-import java.util.Comparator;
 import java.util.List;
 
 import org.forgerock.opendj.ldap.Assertion;
@@ -105,11 +104,6 @@
     }
 
     @Override
-    public Comparator<ByteSequence> comparator(final Schema schema) {
-        return ByteSequence.COMPARATOR;
-    }
-
-    @Override
     public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
             throws DecodeException {
         return UNDEFINED_ASSERTION;
@@ -134,7 +128,6 @@
         return UNDEFINED_ASSERTION;
     }
 
-    /** {@inheritDoc} */
     @Override
     public boolean isIndexingSupported() {
         return !getIndexers().isEmpty();
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EqualLengthApproximateMatchingRuleImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EqualLengthApproximateMatchingRuleImpl.java
deleted file mode 100644
index 894b7ef..0000000
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/EqualLengthApproximateMatchingRuleImpl.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- *      Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- *      Copyright 2009 Sun Microsystems, Inc.
- *      Portions copyright 2014 ForgeRock AS
- */
-package org.forgerock.opendj.ldap.schema;
-
-import org.forgerock.opendj.ldap.Assertion;
-import org.forgerock.opendj.ldap.ByteSequence;
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ConditionResult;
-import org.forgerock.opendj.ldap.DecodeException;
-import org.forgerock.opendj.ldap.spi.IndexQueryFactory;
-
-/**
- * This class implements an extremely simple approximate matching rule that will
- * consider two values approximately equal only if they have the same length. It
- * is intended purely for testing purposes.
- */
-final class EqualLengthApproximateMatchingRuleImpl extends AbstractApproximateMatchingRuleImpl {
-    @Override
-    public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue)
-            throws DecodeException {
-        return new Assertion() {
-            @Override
-            public ConditionResult matches(final ByteSequence attributeValue) {
-                return ConditionResult.valueOf(attributeValue.length() == assertionValue.length());
-            }
-
-            @Override
-            public <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException {
-                return factory.createExactMatchQuery("approximate", ByteString.valueOf(assertionValue.length()));
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    public ByteString normalizeAttributeValue(final Schema schema, final ByteSequence value) {
-        return value.toByteString();
-    }
-}
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRule.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRule.java
index e9f6bdc..f57b37a 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRule.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRule.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2009-2010 Sun Microsystems, Inc.
- *      Portions copyright 2013-2014 ForgeRock AS.
+ *      Portions copyright 2013-2015 ForgeRock AS.
  */
 package org.forgerock.opendj.ldap.schema;
 
@@ -30,7 +30,6 @@
 
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Comparator;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -256,17 +255,6 @@
     }
 
     /**
-     * Get a comparator that can be used to compare the attribute values
-     * normalized by this matching rule.
-     *
-     * @return A comparator that can be used to compare the attribute values
-     *         normalized by this matching rule.
-     */
-    public Comparator<ByteSequence> comparator() {
-        return impl.comparator(schema);
-    }
-
-    /**
      * Returns {@code true} if the provided object is a matching rule having the
      * same numeric OID as this matching rule.
      *
@@ -468,12 +456,17 @@
     /**
      * Returns the normalized form of the provided attribute value, which is
      * best suited for efficiently performing matching operations on that value.
+     * The returned normalized representation can be compared for equality with
+     * other values normalized with this matching rule using
+     * {@link ByteSequence#equals(Object)}. In addition, normalized values can
+     * be compared using {@link ByteSequence#compareTo(ByteSequence)}, although
+     * the sort order is only defined for ordering matching rules.
      *
      * @param value
      *            The attribute value to be normalized.
      * @return The normalized version of the provided attribute value.
      * @throws DecodeException
-     *             if the syntax of the value is not valid.
+     *             If the syntax of the value is not valid.
      */
     public ByteString normalizeAttributeValue(final ByteSequence value) throws DecodeException {
         return impl.normalizeAttributeValue(schema, value);
diff --git a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleImpl.java b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleImpl.java
index 7147788..3ca11b8 100644
--- a/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleImpl.java
+++ b/opendj-core/src/main/java/org/forgerock/opendj/ldap/schema/MatchingRuleImpl.java
@@ -22,12 +22,11 @@
  *
  *
  *      Copyright 2009 Sun Microsystems, Inc.
- *      Portions copyright 2014 ForgeRock AS
+ *      Portions copyright 2014-2015 ForgeRock AS
  */
 package org.forgerock.opendj.ldap.schema;
 
 import java.util.Collection;
-import java.util.Comparator;
 import java.util.List;
 
 import org.forgerock.opendj.ldap.Assertion;
@@ -43,17 +42,6 @@
 public interface MatchingRuleImpl {
 
     /**
-     * Get a comparator that can be used to compare the attribute values
-     * normalized by this matching rule.
-     *
-     * @param schema
-     *            The schema in which this matching rule is defined.
-     * @return A comparator that can be used to compare the attribute values
-     *         normalized by this matching rule.
-     */
-    Comparator<ByteSequence> comparator(Schema schema);
-
-    /**
      * Retrieves the normalized form of the provided assertion value, which is
      * best suited for efficiently performing less than matching operations on
      * that value. The assertion value is guaranteed to be valid against this
@@ -128,6 +116,10 @@
     /**
      * Retrieves the normalized form of the provided attribute value, which is
      * best suited for efficiently performing matching operations on that value.
+     * Equality and ordering matching rules should return a normalized
+     * representation which can be compared with other normalized values using
+     * {@link ByteSequence#equals(Object)} and
+     * {@link ByteSequence#compareTo(ByteSequence)}.
      *
      * @param schema
      *            The schema in which this matching rule is defined.
@@ -135,7 +127,7 @@
      *            The attribute value to be normalized.
      * @return The normalized version of the provided attribute value.
      * @throws DecodeException
-     *             if an syntax error occurred while parsing the value.
+     *             If an syntax error occurred while parsing the value.
      */
     ByteString normalizeAttributeValue(Schema schema, ByteSequence value) throws DecodeException;
 
diff --git a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OrderingMatchingRuleTest.java b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OrderingMatchingRuleTest.java
index 88ce5c2..7faea2b 100644
--- a/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OrderingMatchingRuleTest.java
+++ b/opendj-core/src/test/java/org/forgerock/opendj/ldap/schema/OrderingMatchingRuleTest.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2009 Sun Microsystems, Inc.
- *      Portions copyright 2014 ForgeRock AS
+ *      Portions copyright 2014-2015 ForgeRock AS
  */
 package org.forgerock.opendj.ldap.schema;
 
@@ -70,7 +70,7 @@
                 ruleInstance.normalizeAttributeValue(ByteString.valueOf(value2));
 
         // Test the comparator
-        final int comp = ruleInstance.comparator().compare(normalizedValue1, normalizedValue2);
+        final int comp = normalizedValue1.compareTo(normalizedValue2);
         if (comp == 0) {
             Assert.assertEquals(comp, result);
         } else if (comp > 0) {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/VLVKeyComparator.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/VLVKeyComparator.java
index 737c3e7..774429a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/VLVKeyComparator.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/jeb/VLVKeyComparator.java
@@ -22,13 +22,10 @@
  *
  *
  *      Copyright 2006-2008 Sun Microsystems, Inc.
- *      Portions Copyright 2014 ForgeRock AS
+ *      Portions Copyright 2014-2015 ForgeRock AS
  */
 package org.opends.server.backends.jeb;
 
-import java.util.Comparator;
-
-import org.forgerock.opendj.ldap.ByteSequence;
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.DecodeException;
 import org.forgerock.opendj.ldap.ResultCode;
@@ -201,11 +198,9 @@
         return -1;
       }
 
-      final Comparator<ByteSequence> comp = orderingRules[j].comparator();
       final ByteString val1 = ByteString.valueOf(b1Bytes);
       final ByteString val2 = ByteString.valueOf(b2Bytes);
-      final int result = ascending[j] ? comp.compare(val1, val2) : comp.compare(val2, val1);
-
+      final int result = ascending[j] ? val1.compareTo(val2) : val2.compareTo(val1);
       if(result != 0)
       {
         return result;
@@ -299,9 +294,7 @@
         return -1;
       }
 
-      final Comparator<ByteSequence> comp = orderingRules[j].comparator();
-      final int result = ascending[j] ? comp.compare(b1Bytes, b2Bytes) : comp.compare(b2Bytes, b1Bytes);
-
+      final int result = ascending[j] ? b1Bytes.compareTo(b2Bytes) : b2Bytes.compareTo(b1Bytes);
       if(result != 0)
       {
         return result;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java
index 97ce39e..3c7e447 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VLVIndex.java
@@ -29,7 +29,6 @@
 import static org.opends.messages.JebMessages.*;
 import static org.opends.server.util.StaticUtils.*;
 
-import java.util.Comparator;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -1349,10 +1348,7 @@
         return -1;
       }
 
-      final Comparator<ByteSequence> comp = orderingRule.comparator();
-      final int result = ascending ? comp.compare(b1Bytes, b2Bytes) : comp
-          .compare(b2Bytes, b1Bytes);
-
+      final int result = ascending ? b1Bytes.compareTo(b2Bytes) : b2Bytes.compareTo(b1Bytes);
       if (result != 0)
       {
         return result;
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRuleImpl.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRuleImpl.java
index 837a4d0..ae51b8d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRuleImpl.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/plugin/HistoricalCsnOrderingMatchingRuleImpl.java
@@ -22,13 +22,12 @@
  *
  *
  *      Copyright 2006-2010 Sun Microsystems, Inc.
- *      Portions Copyright 2012-2014 ForgeRock AS.
+ *      Portions Copyright 2012-2015 ForgeRock AS.
  */
 package org.opends.server.replication.plugin;
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 
 import org.forgerock.opendj.ldap.Assertion;
@@ -73,18 +72,6 @@
     }
   }
 
-  /**
-   * Compare two ByteString values containing historical information.
-   *
-   * @param value1 first value to compare
-   * @param value2 second value to compare
-   * @return 0 when equals, -1 or 1 to establish order
-   */
-  private int compareValues(ByteSequence value1, ByteSequence value2)
-  {
-    return value1.compareTo(value2);
-  }
-
   /** {@inheritDoc} */
   @Override
   public ByteString normalizeAttributeValue(Schema schema, ByteSequence value) throws DecodeException
@@ -114,20 +101,6 @@
 
   /** {@inheritDoc} */
   @Override
-  public Comparator<ByteSequence> comparator(Schema schema)
-  {
-    return new Comparator<ByteSequence>()
-    {
-      @Override
-      public int compare(final ByteSequence o1, final ByteSequence o2)
-      {
-        return compareValues(o1, o2);
-      }
-    };
-  }
-
-  /** {@inheritDoc} */
-  @Override
   public Assertion getAssertion(final Schema schema, final ByteSequence value) throws DecodeException
   {
     final ByteString normAssertion = normalizeAttributeValue(schema, value);
@@ -136,7 +109,7 @@
       @Override
       public ConditionResult matches(final ByteSequence attributeValue)
       {
-        return ConditionResult.valueOf(compareValues(attributeValue, normAssertion) < 0);
+        return ConditionResult.valueOf(attributeValue.compareTo(normAssertion) < 0);
       }
 
       @Override
@@ -165,7 +138,7 @@
       @Override
       public ConditionResult matches(final ByteSequence normalizedAttributeValue)
       {
-        return ConditionResult.valueOf(compareValues(normalizedAttributeValue, normAssertion) >= 0);
+        return ConditionResult.valueOf(normalizedAttributeValue.compareTo(normAssertion) >= 0);
       }
 
       @Override
@@ -186,7 +159,7 @@
       @Override
       public ConditionResult matches(final ByteSequence normalizedAttributeValue)
       {
-        return ConditionResult.valueOf(compareValues(normalizedAttributeValue, normAssertion) <= 0);
+        return ConditionResult.valueOf(normalizedAttributeValue.compareTo(normAssertion) <= 0);
       }
 
       @Override
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/schema/AbstractPasswordEqualityMatchingRuleImpl.java b/opendj-server-legacy/src/main/java/org/opends/server/schema/AbstractPasswordEqualityMatchingRuleImpl.java
index 605c9a1..878025a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/schema/AbstractPasswordEqualityMatchingRuleImpl.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/schema/AbstractPasswordEqualityMatchingRuleImpl.java
@@ -22,13 +22,12 @@
  *
  *
  *      Copyright 2006-2008 Sun Microsystems, Inc.
- *      Portions Copyright 2014 ForgeRock AS
+ *      Portions Copyright 2014-2015 ForgeRock AS
  */
 package org.opends.server.schema;
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 
 import org.forgerock.opendj.ldap.Assertion;
@@ -68,13 +67,6 @@
     }
   });
 
-  /** {@inheritDoc} */
-  @Override
-  public Comparator<ByteSequence> comparator(Schema schema)
-  {
-    return ByteSequence.COMPARATOR;
-  }
-
   /**
    * Retrieves the normalized form of the provided value, which is best suited
    * for efficiently performing matching operations on that value.
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/RDN.java b/opendj-server-legacy/src/main/java/org/opends/server/types/RDN.java
index ad3d5ae..0585edd 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/RDN.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/RDN.java
@@ -61,8 +61,6 @@
 {
   private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
-  private static final char HEX_STRING_SEPARATOR = '%';
-
   /** The set of attribute types for the elements in this RDN. */
   private AttributeType[] attributeTypes;
 
@@ -1343,7 +1341,7 @@
       {
         val1 = rule.normalizeAttributeValue(val1);
         val2 = rule.normalizeAttributeValue(val2);
-        return rule.comparator().compare(val1, val2);
+        return val1.compareTo(val2);
       }
       catch (DecodeException e)
       {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/SortKey.java b/opendj-server-legacy/src/main/java/org/opends/server/types/SortKey.java
index 6e6b487..534a734 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/SortKey.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/SortKey.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2008 Sun Microsystems, Inc.
- *      Portions Copyright 2014 ForgeRock AS
+ *      Portions Copyright 2014-2015 ForgeRock AS
  */
 package org.opends.server.types;
 
@@ -187,14 +187,7 @@
     {
       final ByteString val1 = rule.normalizeAttributeValue(value1);
       final ByteString val2 = rule.normalizeAttributeValue(value2);
-      if (ascending)
-      {
-        return rule.comparator().compare(val1, val2);
-      }
-      else
-      {
-        return rule.comparator().compare(val2, val1);
-      }
+      return ascending ? val1.compareTo(val2) : val2.compareTo(val1);
     }
     catch (Exception e)
     {
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaTestMatchingRuleImpl.java b/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaTestMatchingRuleImpl.java
index b416dcf..350712b 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaTestMatchingRuleImpl.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/backends/SchemaTestMatchingRuleImpl.java
@@ -22,14 +22,13 @@
  *
  *
  *      Copyright 2008 Sun Microsystems, Inc.
- *      Portions Copyright 2014 ForgeRock AS
+ *      Portions Copyright 2014-2015 ForgeRock AS
  */
 package org.opends.server.backends;
 
 
 
 import java.util.Collection;
-import java.util.Comparator;
 import java.util.List;
 
 import org.forgerock.opendj.ldap.Assertion;
@@ -62,17 +61,6 @@
     caseIgnoreMatchingRule = CoreSchema.getCaseIgnoreMatchingRule();
   }
 
-  /**
-   * Retrieves the normalized form of the provided value, which is best suited
-   * for efficiently performing matching operations on that value.
-   *
-   * @param  value  The value to be normalized.
-   *
-   * @return  The normalized version of the provided value.
-   *
-   * @throws  DecodeException  If the provided value is invalid according to
-   *                              the associated attribute syntax.
-   */
   @Override
   public ByteString normalizeAttributeValue(Schema schema, ByteSequence value)
          throws DecodeException
@@ -80,21 +68,12 @@
     return caseIgnoreMatchingRule.normalizeAttributeValue(value);
   }
 
-  /** {@inheritDoc} */
-  @Override
-  public Comparator<ByteSequence> comparator(Schema schema)
-  {
-    return caseIgnoreMatchingRule.comparator();
-  }
-
-  /** {@inheritDoc} */
   @Override
   public Assertion getAssertion(Schema schema, ByteSequence assertionValue) throws DecodeException
   {
     return caseIgnoreMatchingRule.getAssertion(assertionValue);
   }
 
-  /** {@inheritDoc} */
   @Override
   public Assertion getSubstringAssertion(Schema schema, ByteSequence subInitial,
       List<? extends ByteSequence> subAnyElements, ByteSequence subFinal) throws DecodeException
@@ -102,28 +81,24 @@
     return caseIgnoreMatchingRule.getSubstringAssertion(subInitial, subAnyElements, subFinal);
   }
 
-  /** {@inheritDoc} */
   @Override
   public Assertion getGreaterOrEqualAssertion(Schema schema, ByteSequence value) throws DecodeException
   {
     return caseIgnoreMatchingRule.getGreaterOrEqualAssertion(value);
   }
 
-  /** {@inheritDoc} */
   @Override
   public Assertion getLessOrEqualAssertion(Schema schema, ByteSequence value) throws DecodeException
   {
     return caseIgnoreMatchingRule.getLessOrEqualAssertion(value);
   }
 
-  /** {@inheritDoc} */
   @Override
   public Collection<? extends Indexer> getIndexers()
   {
     return caseIgnoreMatchingRule.getIndexers();
   }
 
-  /** {@inheritDoc} */
   @Override
   public boolean isIndexingSupported()
   {
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/schema/AttributeTypeSyntaxTest.java b/opendj-server-legacy/src/test/java/org/opends/server/schema/AttributeTypeSyntaxTest.java
index e8f8894..9f60026 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/schema/AttributeTypeSyntaxTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/schema/AttributeTypeSyntaxTest.java
@@ -30,9 +30,8 @@
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.ResultCode;
 import org.forgerock.opendj.ldap.SearchScope;
-import org.forgerock.opendj.ldap.schema.CoreSchema;
 import org.forgerock.opendj.ldap.schema.MatchingRule;
-import org.forgerock.opendj.ldap.schema.SchemaBuilder;
+import org.forgerock.opendj.ldap.schema.Schema;
 import org.opends.server.TestCaseUtils;
 import org.opends.server.api.AttributeSyntax;
 import org.opends.server.core.DirectoryServer;
@@ -44,7 +43,6 @@
 
 import static org.opends.server.protocols.internal.InternalClientConnection.*;
 import static org.opends.server.protocols.internal.Requests.*;
-import static org.opends.server.schema.EqualLengthApproximateMatchingRule.*;
 import static org.testng.Assert.*;
 
 /**
@@ -149,16 +147,8 @@
   @Test
   public void testXAPPROXExtension() throws Exception
   {
-    // Create and register the approximate matching rule for testing purposes.
-    MatchingRule testApproxRule = new SchemaBuilder(CoreSchema.getInstance())
-        .buildMatchingRule(EQUAL_LENGTH_APPROX_MR_OID)
-          .names(EQUAL_LENGTH_APPROX_MR_NAME).implementation(new EqualLengthApproximateMatchingRule())
-          .syntaxOID(EQUAL_LENGTH_APPROX_MR_SYNTAX_OID)
-          .addToSchema()
-        .toSchema().getMatchingRule(EQUAL_LENGTH_APPROX_MR_OID);
-    DirectoryServer.registerMatchingRule(testApproxRule, false);
-
-
+    MatchingRule mrule = Schema.getCoreSchema().getMatchingRule("ds-mr-double-metaphone-approx");
+      
     // Get a reference to the attribute type syntax implementation in the
     // server.
     AttributeTypeSyntax attrTypeSyntax =
@@ -185,7 +175,7 @@
                                                  false);
     assertNotNull(attrType);
     assertNotNull(attrType.getApproximateMatchingRule());
-    assertEquals(attrType.getApproximateMatchingRule(), testApproxRule);
+    assertEquals(attrType.getApproximateMatchingRule(), mrule);
   }
 
 
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/schema/EqualLengthApproximateMatchingRule.java b/opendj-server-legacy/src/test/java/org/opends/server/schema/EqualLengthApproximateMatchingRule.java
deleted file mode 100644
index 7365aa0..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/schema/EqualLengthApproximateMatchingRule.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
- * or http://forgerock.org/license/CDDLv1.0.html.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at legal-notices/CDDLv1_0.txt.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information:
- *      Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- *
- *
- *      Copyright 2008 Sun Microsystems, Inc.
- *      Portions Copyright 2014 ForgeRock AS
- */
-package org.opends.server.schema;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.List;
-
-import org.forgerock.opendj.ldap.Assertion;
-import org.forgerock.opendj.ldap.ByteSequence;
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.ConditionResult;
-import org.forgerock.opendj.ldap.DecodeException;
-import org.forgerock.opendj.ldap.schema.MatchingRuleImpl;
-import org.forgerock.opendj.ldap.schema.Schema;
-import org.forgerock.opendj.ldap.spi.IndexQueryFactory;
-import org.forgerock.opendj.ldap.spi.Indexer;
-
-import static java.util.Collections.*;
-
-/**
- * Implementation of an extremely simple approximate matching rule that will
- * consider two values approximately equal only if they have the same length.
- *
- * This class is intended only for testing purposes.
- */
-@SuppressWarnings("javadoc")
-class EqualLengthApproximateMatchingRule implements MatchingRuleImpl
-{
-  static final String EQUAL_LENGTH_APPROX_MR_NAME = "equalLengthApproximateMatch";
-  static final String EQUAL_LENGTH_APPROX_MR_OID = "1.3.6.1.4.1.26027.1.999.26";
-  static final String EQUAL_LENGTH_APPROX_MR_SYNTAX_OID = SchemaConstants.SYNTAX_DIRECTORY_STRING_OID;
-
-  @Override
-  public ByteString normalizeAttributeValue(Schema schema, ByteSequence value) throws DecodeException
-  {
-    // Any value is acceptable, so we can just return a copy of the value.
-    return value.toByteString();
-  }
-
-  @Override
-  public Comparator<ByteSequence> comparator(final Schema schema)
-  {
-    return new Comparator<ByteSequence>()
-    {
-      @Override
-      public int compare(final ByteSequence o1, final ByteSequence o2)
-      {
-        return o1.length() - o2.length();
-      }
-    };
-  }
-
-  @Override
-  public Assertion getAssertion(final Schema schema, final ByteSequence assertionValue) throws DecodeException
-  {
-    final ByteString normAssertion = normalizeAttributeValue(schema, assertionValue);
-    return new Assertion()
-    {
-      @Override
-      public ConditionResult matches(final ByteSequence normalizedAttributeValue)
-      {
-        return ConditionResult.valueOf(normalizedAttributeValue.length() == normAssertion.length());
-      }
-
-      @Override
-      public <T> T createIndexQuery(IndexQueryFactory<T> factory) throws DecodeException
-      {
-        return factory.createMatchAllQuery();
-      }
-    };
-  }
-
-  @Override
-  public Assertion getSubstringAssertion(final Schema schema, final ByteSequence subInitial,
-      final List<? extends ByteSequence> subAnyElements, final ByteSequence subFinal) throws DecodeException
-  {
-    return Assertion.UNDEFINED_ASSERTION;
-  }
-
-  @Override
-  public Assertion getGreaterOrEqualAssertion(final Schema schema, final ByteSequence value) throws DecodeException
-  {
-    return Assertion.UNDEFINED_ASSERTION;
-  }
-
-  @Override
-  public Assertion getLessOrEqualAssertion(final Schema schema, final ByteSequence value) throws DecodeException
-  {
-    return Assertion.UNDEFINED_ASSERTION;
-  }
-
-  /** {@inheritDoc} */
-  @Override
-  public boolean isIndexingSupported()
-  {
-    return false;
-  }
-
-  /** {@inheritDoc} */
-  @Override
-  public Collection<? extends Indexer> getIndexers()
-  {
-    return emptyList();
-  }
-
-}

--
Gitblit v1.10.0