From ff37f98690a3578fca909da64261422c2d5b0503 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 04 Feb 2016 16:43:42 +0000
Subject: [PATCH] AttributeBuilder.java: remove now unnecessary inner classes
---
opendj-server-legacy/src/main/java/org/opends/server/types/AttributeBuilder.java | 117 ++++-----------------------------------
opendj-server-legacy/src/test/java/org/opends/server/types/AttributeBuilderTest.java | 48 ----------------
2 files changed, 12 insertions(+), 153 deletions(-)
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 ea9762e..2ceb6fa 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
@@ -115,30 +115,26 @@
/**
* A real attribute - options handled by sub-classes.
*/
- private static abstract class RealAttribute
- extends AbstractAttribute
+ private static class RealAttribute extends AbstractAttribute
{
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
/** The attribute description for this attribute. */
private final AttributeDescription attributeDescription;
-
/** The name of this attribute as provided by the end user. */
private final String name;
-
/**
* The unmodifiable set of attribute values, which are lazily normalized.
* <p>
- * When required, the attribute values are normalized according to the equality
- * matching rule.
+ * When required, the attribute values are normalized according to the equality matching rule.
*/
private final Set<AttributeValue> values;
/**
* Creates a new real attribute.
*
- * @param attributeType
- * The attribute type.
+ * @param attributeDescription
+ * The attribute description.
* @param name
* The user-provided attribute name.
* @param values
@@ -292,8 +288,6 @@
return result;
}
-
-
@Override
public final boolean isVirtual()
{
@@ -426,97 +420,6 @@
}
}
-
-
- /**
- * A real attribute with a many options.
- */
- private static final class RealAttributeManyOptions
- extends RealAttribute
- {
- /**
- * Creates a new real attribute that has multiple options.
- *
- * @param attributeType
- * The attribute type.
- * @param name
- * The user-provided attribute name.
- * @param values
- * The attribute values.
- * @param options
- * The attribute options.
- * @param normalizedOptions
- * The normalized attribute options.
- */
- private RealAttributeManyOptions(
- AttributeType attributeType, String name, Set<AttributeValue> values, Set<String> options,
- SortedSet<String> normalizedOptions)
- {
- super(AttributeDescription.create(attributeType, options), name, values);
- }
- }
-
-
-
- /**
- * A real attribute with no options.
- */
- private static final class RealAttributeNoOptions extends RealAttribute
- {
- /**
- * Creates a new real attribute that has no options.
- *
- * @param attributeType
- * The attribute type.
- * @param name
- * The user-provided attribute name.
- * @param values
- * The attribute values.
- */
- private RealAttributeNoOptions(AttributeType attributeType, String name, Set<AttributeValue> values)
- {
- super(AttributeDescription.create(attributeType), name, values);
- }
-
- @Override
- public String getNameWithOptions()
- {
- return getName();
- }
- }
-
-
-
- /**
- * A real attribute with a single option.
- */
- private static final class RealAttributeSingleOption
- extends RealAttribute
- {
- /**
- * Creates a new real attribute that has a single option.
- *
- * @param attributeType
- * The attribute type.
- * @param name
- * The user-provided attribute name.
- * @param values
- * The attribute values.
- * @param option
- * The attribute option.
- */
- private RealAttributeSingleOption(
- AttributeType attributeType,
- String name,
- Set<AttributeValue> values,
- String option)
- {
- super(AttributeDescription.create(attributeType, option), name, values);
- }
- }
-
-
-
/**
* A small set of values. This set implementation is optimized to
* use as little memory as possible in the case where there zero or
@@ -1574,15 +1477,19 @@
private Attribute toAttribute0()
{
+ return new RealAttribute(toAttributeDescription(), name, values);
+ }
+
+ private AttributeDescription toAttributeDescription()
+ {
switch (options.size())
{
case 0:
- return new RealAttributeNoOptions(attributeType, name, values);
+ return AttributeDescription.create(attributeType);
case 1:
- return new RealAttributeSingleOption(attributeType, name, values, options.firstElement);
+ return AttributeDescription.create(attributeType, options.firstElement);
default:
- return new RealAttributeManyOptions(attributeType, name, values,
- Collections.unmodifiableSet(options.elements), Collections.unmodifiableSortedSet(normalizedOptions));
+ return AttributeDescription.create(attributeType, options.elements);
}
}
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 ffaa7dd..ee7b57f 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
@@ -1678,54 +1678,6 @@
Assert.assertNotNull(a);
}
-
-
- /**
- * Tests that the generated attribute is optimized correctly for
- * storage of attribute options. This test is very implementation
- * dependent, but because Attributes are so performance sensitive it
- * is worth doing.
- *
- * @param testCase
- * Test case index (useful for debugging).
- * @param a
- * The attribute.
- * @param type
- * The expected attribute type.
- * @param name
- * The expected user provided attribute name.
- * @param options
- * The expected attribute options.
- * @param values
- * The expected attribute values.
- */
- @Test(dataProvider = "createAttributes", dependsOnMethods = "testAttributeGetOptions")
- public void testAttributeOptionOptimization(int testCase, Attribute a,
- AttributeType type, String name, String[] options, String[] values)
- throws Exception
- {
- switch (options.length)
- {
- case 0:
- // Attribute must be optimized for zero options.
- Assert.assertEquals(a.getClass().getName(),
- "org.opends.server.types.AttributeBuilder$RealAttributeNoOptions");
- break;
- case 1:
- // Attribute must be optimized for single option.
- Assert.assertEquals(a.getClass().getName(),
- "org.opends.server.types.AttributeBuilder$RealAttributeSingleOption");
- break;
- default:
- // Attribute must be optimized for many options.
- Assert.assertEquals(a.getClass().getName(),
- "org.opends.server.types.AttributeBuilder$RealAttributeManyOptions");
- break;
- }
- }
-
-
-
/**
* Tests {@link Attribute#optionsEqual(Set)}.
*
--
Gitblit v1.10.0