From 2f8ddecb5c2234bb90f6879100656cbfa6c1f5fe Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 11 Dec 2014 13:32:43 +0000
Subject: [PATCH] Code cleanup.

---
 opendj3-server-dev/src/server/org/opends/server/backends/jeb/JebFormat.java |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/JebFormat.java b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/JebFormat.java
index fabaa25..a0a0d4b 100644
--- a/opendj3-server-dev/src/server/org/opends/server/backends/jeb/JebFormat.java
+++ b/opendj3-server-dev/src/server/org/opends/server/backends/jeb/JebFormat.java
@@ -257,34 +257,31 @@
    * Decode a DN value from its database key representation.
    *
    * @param dnKey The database key value of the DN.
-   * @param offset Starting position in the database key data.
-   * @param length The length of the database key data.
-   * @param prefix The DN to prefix the deocded DN value.
+   * @param prefix The DN to prefix the decoded DN value.
    * @return The decoded DN value.
    * @throws DirectoryException if an error occurs while decoding the DN value.
    * @see #dnToDNKey(DN, int)
    */
-  public static DN dnFromDNKey(byte[] dnKey, int offset, int length, DN prefix)
+  public static DN dnFromDNKey(byte[] dnKey, DN prefix)
       throws DirectoryException
   {
     DN dn = prefix;
-    int start = offset;
     boolean escaped = false;
     ByteStringBuilder buffer = new ByteStringBuilder();
-    for(int i = start; i < length; i++)
+    for (byte b : dnKey)
     {
-      if(dnKey[i] == 0x5C)
+      if (b == 0x5C)
       {
         escaped = true;
         continue;
       }
-      else if(!escaped && dnKey[i] == 0x01)
+      else if (!escaped && b == 0x01)
       {
         buffer.append(0x01);
         escaped = false;
         continue;
       }
-      else if(!escaped && dnKey[i] == 0x00)
+      else if (!escaped && b == 0x00)
       {
         if(buffer.length() > 0)
         {
@@ -299,7 +296,7 @@
           buffer.append(0x5C);
           escaped = false;
         }
-        buffer.append(dnKey[i]);
+        buffer.append(b);
       }
     }
 
@@ -311,6 +308,20 @@
     return dn;
   }
 
+
+  /**
+   * Find the length of bytes that represents the superior DN of the given
+   * DN key. The superior DN is represented by the initial bytes of the DN key.
+   *
+   * @param dnKey The database key value of the DN.
+   * @return The length of the superior DN or -1 if the given dn is the
+   *         root DN or 0 if the superior DN is removed.
+   */
+  public static int findDNKeyParent(byte[] dnKey)
+  {
+    return findDNKeyParent(dnKey, 0, dnKey.length);
+  }
+
   /**
    * Find the length of bytes that represents the superior DN of the given
    * DN key. The superior DN is represented by the initial bytes of the DN key.
@@ -347,7 +358,7 @@
    * @param prefixRDNs The number of prefix RDNs to remove from the encoded
    *                   representation.
    * @return A DatabaseEntry containing the key.
-   * @see #dnFromDNKey(byte[], int, int, DN)
+   * @see #dnFromDNKey(byte[], DN)
    */
   public static byte[] dnToDNKey(DN dn, int prefixRDNs)
   {

--
Gitblit v1.10.0