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

Jean-Noël Rouvignac
03.51.2016 0b75361593e78cb6a83d7f763080b36a60e3eb79
OPENDJ-1342 Migrate AVA, RDN, and DN classes: Moved DN2ID.isChild() to DNKeyFormat

DNKeyFormat.java:
Made all fields private.
Moved DN2ID.isChild() here.
4 files modified
87 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/DN2ID.java 33 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/DnKeyFormat.java 38 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java 2 ●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/DN2IDTest.java 14 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/DN2ID.java
@@ -192,37 +192,6 @@
    }
  }
  /**
   * Check if two DN have a parent-child relationship.
   *
   * @param parent
   *          The potential parent
   * @param child
   *          The potential child of parent
   * @return true if child is a direct children of parent, false otherwise.
   */
  static boolean isChild(ByteSequence parent, ByteSequence child)
  {
    if (!child.startsWith(parent))
    {
      return false;
    }
    // Immediate children should only have one RDN separator past the parent length
    int nbSeparator = 0;
    for (int i = parent.length() ; i < child.length(); i++)
    {
      if (child.byteAt(i) == DnKeyFormat.NORMALIZED_RDN_SEPARATOR)
      {
        nbSeparator++;
        if (nbSeparator > 1)
        {
          return false;
        }
      }
    }
    return nbSeparator == 1;
  }
  @Override
  public String keyToString(ByteString key)
  {
@@ -378,7 +347,7 @@
    private void popCompleteParents(ByteString dn)
    {
      ParentInfo<V> currentParent;
      while ((currentParent = parentsInfoStack.peek()) != null && !isChild(currentParent.parentDN, dn))
      while ((currentParent = parentsInfoStack.peek()) != null && !DnKeyFormat.isChild(currentParent.parentDN, dn))
      {
        visitor.endParent(parentsInfoStack.pop().visitorData);
      }
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/DnKeyFormat.java
@@ -27,12 +27,13 @@
  /** The format version used by this class to encode and decode a ByteString. */
  static final byte FORMAT_VERSION = 0x01;
  // The following fields have been copied from the DN class in the SDK
  /** RDN separator for normalized byte string of a DN. */
  public static final byte NORMALIZED_RDN_SEPARATOR = 0x00;
  private static final byte NORMALIZED_RDN_SEPARATOR = 0x00;
  /** AVA separator for normalized byte string of a DN. */
  static final byte NORMALIZED_AVA_SEPARATOR = 0x01;
  private static final byte NORMALIZED_AVA_SEPARATOR = 0x01;
  /** Escape byte for normalized byte string of a DN. */
  static final byte NORMALIZED_ESC_BYTE = 0x02;
  private static final byte NORMALIZED_ESC_BYTE = 0x02;
  /**
   * Find the length of bytes that represents the superior DN of the given DN
@@ -107,4 +108,35 @@
    afterKey.appendByte(NORMALIZED_AVA_SEPARATOR);
    return afterKey;
  }
  /**
   * Check if two DN have a parent-child relationship.
   *
   * @param parent
   *          The potential parent
   * @param child
   *          The potential child of parent
   * @return true if child is a direct children of parent, false otherwise.
   */
  static boolean isChild(ByteSequence parent, ByteSequence child)
  {
    if (!child.startsWith(parent))
    {
      return false;
    }
    // Immediate children should only have one RDN separator past the parent length
    int nbSeparator = 0;
    for (int i = parent.length() ; i < child.length(); i++)
    {
      if (child.byteAt(i) == NORMALIZED_RDN_SEPARATOR)
      {
        nbSeparator++;
        if (nbSeparator > 1)
        {
          return false;
        }
      }
    }
    return nbSeparator == 1;
  }
}
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/VerifyJob.java
@@ -496,7 +496,7 @@
      final ByteString key, final EntryID entryID)
  {
    ChildrenCount currentParent = childrenCounters.peekLast();
    while (currentParent != null && !DN2ID.isChild(currentParent.baseDN, key))
    while (currentParent != null && !DnKeyFormat.isChild(currentParent.baseDN, key))
    {
      // This subtree is fully processed, pop the counter of the parent DN from the stack and verify it's value
      verifyID2ChildrenCount(txn, childrenCounters.removeLast());
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/DN2IDTest.java
@@ -150,20 +150,20 @@
          cursor.next();
          final ByteString parentDN = cursor.getKey();
          cursor.next();
          assertThat(DN2ID.isChild(rootDN, parentDN)).isTrue();
          assertThat(DnKeyFormat.isChild(rootDN, parentDN)).isTrue();
          final ByteString childDN = cursor.getKey();
          assertThat(DN2ID.isChild(parentDN, childDN)).isTrue();
          assertThat(DnKeyFormat.isChild(parentDN, childDN)).isTrue();
          cursor.next();
          final ByteString otherChildDN = cursor.getKey();
          assertThat(DN2ID.isChild(parentDN, otherChildDN)).isTrue();
          assertThat(DN2ID.isChild(childDN, otherChildDN)).isFalse();
          assertThat(DnKeyFormat.isChild(parentDN, otherChildDN)).isTrue();
          assertThat(DnKeyFormat.isChild(childDN, otherChildDN)).isFalse();
          final ByteString lastChildDN = cursor.getKey();
          assertThat(DN2ID.isChild(parentDN, lastChildDN)).isTrue();
          assertThat(DN2ID.isChild(otherChildDN, lastChildDN)).isFalse();
          assertThat(DN2ID.isChild(childDN, lastChildDN)).isFalse();
          assertThat(DnKeyFormat.isChild(parentDN, lastChildDN)).isTrue();
          assertThat(DnKeyFormat.isChild(otherChildDN, lastChildDN)).isFalse();
          assertThat(DnKeyFormat.isChild(childDN, lastChildDN)).isFalse();
        }
        return null;
      }