mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
13.32.2014 0c7ecbc4e3c91aa10086a9be077f97f25cd8ff0d
OPENDJ-1591 (CR-5256) Switch to SDK matching rules

Replaced AtributeIndex.KeyComparator and AtributeIndex.BSKeyComparator to use ByteSequence comparators.
4 files modified
118 ■■■■ changed files
opendj3-server-dev/src/server/org/opends/server/backends/jeb/AttributeIndex.java 97 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/jeb/Index.java 3 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/jeb/Indexer.java 14 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java 4 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/jeb/AttributeIndex.java
@@ -35,6 +35,7 @@
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.Assertion;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DecodeException;
import org.forgerock.opendj.ldap.ResultCode;
@@ -686,96 +687,42 @@
  }
  /**
   * The default lexicographic byte array comparator.
   * Is there one available in the Java platform?
   * Delegator to {@link ByteSequence#BYTE_ARRAY_COMPARATOR}.
   * <p>
   * This intermediate class is necessary to satisfy JE's requirements for a btree comparator.
   *
   * @see com.sleepycat.je.DatabaseConfig#setBtreeComparator(Comparator)
   */
  public static class KeyComparator implements Comparator<byte[]>
  {
    /**
     * Compares its two arguments for order.  Returns a negative integer,
     * zero, or a positive integer as the first argument is less than, equal
     * to, or greater than the second.
     *
     * @param a the first object to be compared.
     * @param b the second object to be compared.
     * @return a negative integer, zero, or a positive integer as the
     *         first argument is less than, equal to, or greater than the
     *         second.
     */
    /** The instance. */
    public static final KeyComparator INSTANCE = new KeyComparator();
    /** {@inheritDoc} */
    @Override
    public int compare(byte[] a, byte[] b)
    {
      int i;
      for (i = 0; i < a.length && i < b.length; i++)
      {
        if (a[i] > b[i])
        {
          return 1;
        }
        else if (a[i] < b[i])
        {
          return -1;
        }
      }
      if (a.length == b.length)
      {
        return 0;
      }
      if (a.length > b.length)
      {
        return 1;
      }
      return -1;
      return ByteSequence.BYTE_ARRAY_COMPARATOR.compare(a, b);
    }
  }
  /**
   * Byte string key comparator. The default lexicographic byte string
   * comparator.
   * Delegator to {@link ByteSequence#COMPARATOR}.
   * <p>
   * This is the byte string equivalent of {@link KeyComparator}.
   * <p>
   * Note: Matt reckons we could simply use ByteString.compareTo(),
   * but I am using this for now as an intermediate step.
   */
  public static class BSKeyComparator implements Comparator<ByteString>
  {
    /**
     * Compares its two arguments for order. Returns a negative integer, zero,
     * or a positive integer as the first argument is less than, equal to, or
     * greater than the second.
   * This intermediate class is necessary to satisfy JE's requirements for a btree comparator.
     *
     * @param a
     *          the first object to be compared.
     * @param b
     *          the second object to be compared.
     * @return a negative integer, zero, or a positive integer as the first
     *         argument is less than, equal to, or greater than the second.
   * @see com.sleepycat.je.DatabaseConfig#setBtreeComparator(Comparator)
     */
  public static class BSKeyComparator implements Comparator<ByteSequence>
  {
    /** The instance. */
    public static final BSKeyComparator INSTANCE = new BSKeyComparator();
    /** {@inheritDoc} */
    @Override
    public int compare(ByteString a, ByteString b)
    public int compare(ByteSequence a, ByteSequence b)
    {
      int i;
      for (i = 0; i < a.length() && i < b.length(); i++)
      {
        if (a.byteAt(i) > b.byteAt(i))
        {
          return 1;
        }
        else if (a.byteAt(i) < b.byteAt(i))
        {
          return -1;
        }
      }
      if (a.length() == b.length())
      {
        return 0;
      }
      if (a.length() > b.length())
      {
        return 1;
      }
      return -1;
      return ByteSequence.COMPARATOR.compare(a, b);
    }
  }
opendj3-server-dev/src/server/org/opends/server/backends/jeb/Index.java
@@ -29,6 +29,7 @@
import java.util.*;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ConditionResult;
import org.forgerock.opendj.ldap.spi.IndexingOptions;
@@ -65,7 +66,7 @@
  /**
   * The comparator for index keys.
   */
  private final Comparator<ByteString> bsComparator;
  private final Comparator<ByteSequence> bsComparator;
  /**
   * The limit on the number of entry IDs that may be indexed by one key.
opendj3-server-dev/src/server/org/opends/server/backends/jeb/Indexer.java
@@ -31,6 +31,7 @@
import java.util.Map;
import java.util.Set;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.spi.IndexingOptions;
import org.opends.server.backends.jeb.AttributeIndex.BSKeyComparator;
@@ -45,12 +46,6 @@
public abstract class Indexer
{
  /**
   * The comparator for keys generated by this class.
   */
  private static final KeyComparator comparator = new KeyComparator();
  private static final BSKeyComparator bsComparator = new BSKeyComparator();
  /**
   * Get the comparator that must be used to compare index keys generated by
   * this class.
   *
@@ -58,7 +53,7 @@
   */
  public final Comparator<byte[]> getComparator()
  {
    return comparator;
    return KeyComparator.INSTANCE;
  }
  /**
@@ -67,9 +62,9 @@
   *
   * @return A byte string comparator.
   */
  public final Comparator<ByteString> getBSComparator()
  public final Comparator<ByteSequence> getBSComparator()
  {
    return bsComparator;
    return BSKeyComparator.INSTANCE;
  }
  /**
@@ -112,5 +107,6 @@
   * used to name an index created using this object.
   * @return A string representation of this object.
   */
  @Override
  public abstract String toString();
}
opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java
@@ -32,6 +32,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.opendj.config.server.ConfigException;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.opends.server.admin.std.server.BackendCfg;
@@ -1152,8 +1153,7 @@
        DatabaseEntry data = new DatabaseEntry();
        LockMode lockMode = LockMode.DEFAULT;
        OperationStatus status;
        Comparator<byte[]> defaultComparator =
            new AttributeIndex.KeyComparator();
        Comparator<byte[]> defaultComparator = ByteSequence.BYTE_ARRAY_COMPARATOR;
        byte[] start = null;
        byte[] end = null;
        int minSize = -1;