From 46af3a54b9e7cd3bceea596bd7cba4ff5d19617e Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Wed, 14 Sep 2016 13:16:21 +0000
Subject: [PATCH] OPENDJ-3296 Remove AttributeBuilder.setAttributeDescription()
---
opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaFilesWriter.java | 11 ++---
opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java | 39 ++-----------------
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java | 8 +--
opendj-server-legacy/src/test/java/org/opends/server/types/AttributeBuilderTest.java | 39 -------------------
4 files changed, 12 insertions(+), 85 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaFilesWriter.java b/opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaFilesWriter.java
index 89a2677..3c7c0c0 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/schema/SchemaFilesWriter.java
+++ b/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))
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java b/opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java
index cf619e2..a7a1180 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java
+++ b/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;
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java b/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
index 10dcde5..311a2c8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
+++ b/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();
}
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/types/AttributeBuilderTest.java b/opendj-server-legacy/src/test/java/org/opends/server/types/AttributeBuilderTest.java
index dae878e..7f93011 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/types/AttributeBuilderTest.java
+++ b/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
--
Gitblit v1.10.0