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

Jean-Noël Rouvignac
12.54.2016 46af3a54b9e7cd3bceea596bd7cba4ff5d19617e
OPENDJ-3296 Remove AttributeBuilder.setAttributeDescription()

AttributeBuilder.setAttributeDescription() only exists to be able to reuse AttributeBuilders.
It is still possible to reuse an AttributeBuilder after calling AttributeBuilder.toAttribute().

AttributeBuilder.java:
Made objects of this class less reusable: remove default constructor and setAttributeDescription().
4 files modified
97 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaFilesWriter.java 11 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java 39 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java 8 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/types/AttributeBuilderTest.java 39 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaFilesWriter.java
@@ -54,7 +54,6 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.ldap.AVA;
import org.forgerock.opendj.ldap.AttributeDescription;
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.ModificationType;
@@ -421,16 +420,14 @@
  private static void compareConcatenatedSchema(Set<String> oldElements, Set<String> newElements,
      AttributeType elementType, List<Modification> mods)
  {
    AttributeBuilder builder = new AttributeBuilder(elementType);
    addModification(mods, DELETE, oldElements, newElements, builder);
    builder.setAttributeDescription(AttributeDescription.create(elementType));
    addModification(mods, ADD, newElements, oldElements, builder);
    addModification(mods, DELETE, oldElements, newElements, elementType);
    addModification(mods, ADD, newElements, oldElements, elementType);
  }
  private static void addModification(List<Modification> mods, ModificationType modType, Set<String> included,
      Set<String> excluded, AttributeBuilder builder)
      Set<String> excluded, AttributeType attrType)
  {
    AttributeBuilder builder = new AttributeBuilder(attrType);
    for (String val : included)
    {
      if (!excluded.contains(val))
opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java
@@ -16,6 +16,8 @@
 */
package org.opends.server.types;
import static org.forgerock.util.Reject.checkNotNull;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -514,24 +516,11 @@
  }
  /** The attribute description for this attribute. */
  private AttributeDescription attributeDescription;
  private final AttributeDescription attributeDescription;
  /** The set of attribute values, which are lazily normalized. */
  private SmallSet<AttributeValue> values = new SmallSet<>();
  /**
   * Creates a new attribute builder with an undefined attribute type
   * and user-provided name. The attribute type, and optionally the
   * user-provided name, must be defined using
   * {@link #setAttributeDescription(AttributeDescription)} before the attribute
   * builder can be converted to an {@link Attribute}. Failure to do
   * so will yield an {@link IllegalStateException}.
   */
  public AttributeBuilder()
  {
    // No implementation required.
  }
  /**
   * Creates a new attribute builder from an existing attribute.
   * <p>
   * Modifications to the attribute builder will not impact the
@@ -554,7 +543,7 @@
   */
  public AttributeBuilder(AttributeDescription attributeDescription)
  {
    this.attributeDescription = attributeDescription;
    this.attributeDescription = checkNotNull(attributeDescription);
  }
  /**
@@ -941,17 +930,6 @@
  }
  /**
   * Sets the attribute description associated with this attribute builder.
   *
   * @param attrDesc
   *          The attribute description for this attribute builder.
   */
  public void setAttributeDescription(AttributeDescription attrDesc)
  {
    attributeDescription = attrDesc;
  }
  /**
   * Adds the specified option to this attribute builder if it is not
   * already present.
   *
@@ -1073,18 +1051,9 @@
   */
  public Attribute toAttribute() throws IllegalStateException
  {
    if (attributeDescription == null)
    {
      throw new IllegalStateException("Undefined attribute type or name");
    }
    // Now create the appropriate attribute based on the options.
    Attribute attribute = toAttribute0();
    // Reset the state of this builder.
    attributeDescription = null;
    values = new SmallSet<>();
    return attribute;
  }
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
@@ -3550,7 +3550,6 @@
    }
    else
    {
      AttributeBuilder builder = new AttributeBuilder();
      int startPos;
      int endPos;
      for (int i=0; i < attrs; i++)
@@ -3564,8 +3563,7 @@
        String name = entryBuffer.readStringUtf8(endPos - startPos);
        entryBuffer.skip(1);
        AttributeDescription attrDesc = AttributeDescription.valueOf(name);
        builder.setAttributeDescription(attrDesc);
        final AttributeBuilder builder = new AttributeBuilder(name);
        // Next, we have the number of values.
        int numValues = entryBuffer.readBERLength();
@@ -4476,8 +4474,8 @@
                  if (!attrName.equals(ocAttr.getAttributeDescription().getNameOrOID()))
                  {
                    // User requested non-default object class type name.
                    AttributeBuilder builder = new AttributeBuilder(ocAttr);
                    builder.setAttributeDescription(AttributeDescription.create(attrName, ocType));
                    AttributeBuilder builder = new AttributeBuilder(AttributeDescription.create(attrName, ocType));
                    builder.addAll(ocAttr);
                    ocAttr = builder.toAttribute();
                  }
opendj-server-legacy/src/test/java/org/opends/server/types/AttributeBuilderTest.java
@@ -682,8 +682,7 @@
  @Test
  public void testAttributeBuilderContains() throws Exception
  {
    AttributeBuilder builder = new AttributeBuilder();
    AttributeBuilder builder = new AttributeBuilder(cnType);
    builder.addAll(createAttribute(cnType, "cn", noOptions, twoValues));
    Assert.assertTrue(builder.contains(bs("value1")));
@@ -721,42 +720,6 @@
  }
  /**
   * Tests {@link AttributeBuilder#toAttribute()} throws
   * IllegalStateException after default constructor.
   */
  @Test(expectedExceptions = IllegalStateException.class)
  public void testAttributeBuilderIllegalStateException1() throws Exception
  {
    AttributeBuilder builder = new AttributeBuilder();
    builder.toAttribute();
  }
  /**
   * Tests {@link AttributeBuilder#toAttribute()} throws
   * IllegalStateException when called twice.
   */
  @Test(expectedExceptions = IllegalStateException.class)
  public void testAttributeBuilderIllegalStateException2() throws Exception
  {
    AttributeBuilder builder = new AttributeBuilder(cnType);
    try
    {
      builder.toAttribute();
    }
    catch (IllegalStateException e)
    {
      Assert.fail("Got unexpected IllegalStateException");
    }
    builder.toAttribute();
  }
  /**
   * Tests {@link AttributeBuilder#isEmpty()}.
   */
  @Test