From 2f13f91c158747ca997a44d8e61830f46b77dd82 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 14 Mar 2014 11:31:24 +0000
Subject: [PATCH] OPENDJ-1308 (CR-3156) Migrate schema support - ByteString - Indexer

---
 opendj3-server-dev/src/server/org/opends/server/backends/jeb/AttributeIndex.java |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/AttributeIndex.java b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/AttributeIndex.java
index b646ad4..6740516 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/AttributeIndex.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/AttributeIndex.java
@@ -1313,6 +1313,59 @@
   }
 
   /**
+   * Byte string key comparator. The default lexicographic byte string
+   * 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.
+     *
+     * @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.
+     */
+    @Override
+    public int compare(ByteString a, ByteString 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;
+      }
+      else
+      {
+        return -1;
+      }
+    }
+  }
+
+  /**
    * Retrieve the entry IDs that might match an approximate filter.
    *
    * @param approximateFilter The approximate filter.

--
Gitblit v1.10.0