From ab96c804928c3ca47b8d2f1f646bc3f4d902fe4b Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Thu, 16 Jun 2011 14:07:53 +0000
Subject: [PATCH] Use fluent style API for adding options to AttributeDescriptions.
---
opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFChangeRecordReader.java | 7 +--
opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/AbstractLDIFReader.java | 4 +-
opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java | 62 +++++++------------------------
3 files changed, 19 insertions(+), 54 deletions(-)
diff --git a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java
index 24e6be5..1379e95 100644
--- a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java
+++ b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/AttributeDescription.java
@@ -23,6 +23,7 @@
*
*
* Copyright 2009-2010 Sun Microsystems, Inc.
+ * Portions copyright 2011 ForgeRock AS
*/
package org.forgerock.opendj.ldap;
@@ -542,63 +543,28 @@
/**
- * Creates an attribute description having the same attribute type and options
- * as the provided attribute description and, in addition, the provided list
- * of options.
+ * Returns an attribute description having the same attribute type and options
+ * as this attribute description as well as the provided option.
*
- * @param attributeDescription
- * The attribute description.
- * @param options
- * The attribute options.
- * @return The new attribute description containing {@code options}.
- * @throws NullPointerException
- * If {@code attributeDescription} or {@code options} was {@code
- * null}.
- */
- public static AttributeDescription create(
- final AttributeDescription attributeDescription, final String... options)
- throws NullPointerException
- {
- Validator.ensureNotNull(attributeDescription, options);
-
- // This should not be called very often, so don't optimize.
- AttributeDescription newAttributeDescription = attributeDescription;
- for (final String option : options)
- {
- newAttributeDescription = create(newAttributeDescription, option);
- }
- return newAttributeDescription;
- }
-
-
-
- /**
- * Creates an attribute description having the same attribute type and options
- * as the provided attribute description and, in addition, the provided new
- * option.
- *
- * @param attributeDescription
- * The attribute description.
* @param option
* The attribute option.
* @return The new attribute description containing {@code option}.
* @throws NullPointerException
- * If {@code attributeDescription} or {@code option} was {@code
- * null}.
+ * If {@code attributeDescription} or {@code option} was
+ * {@code null}.
*/
- public static AttributeDescription create(
- final AttributeDescription attributeDescription, final String option)
+ public AttributeDescription withOption(final String option)
throws NullPointerException
{
- Validator.ensureNotNull(attributeDescription, option);
+ Validator.ensureNotNull(option);
final String normalizedOption = toLowerCase(option);
- if (attributeDescription.pimpl.containsOption(normalizedOption))
+ if (pimpl.containsOption(normalizedOption))
{
- return attributeDescription;
+ return this;
}
- final String oldAttributeDescription = attributeDescription.attributeDescription;
+ final String oldAttributeDescription = attributeDescription;
final StringBuilder builder = new StringBuilder(oldAttributeDescription
.length()
+ option.length() + 1);
@@ -607,11 +573,11 @@
builder.append(option);
final String newAttributeDescription = builder.toString();
- final Impl impl = attributeDescription.pimpl;
+ final Impl impl = pimpl;
if (impl instanceof ZeroOptionImpl)
{
return new AttributeDescription(newAttributeDescription,
- attributeDescription.attributeType, new SingleOptionImpl(option,
+ attributeType, new SingleOptionImpl(option,
normalizedOption));
}
@@ -631,7 +597,7 @@
}
return new AttributeDescription(newAttributeDescription,
- attributeDescription.attributeType, new MultiOptionImpl(newOptions,
+ attributeType, new MultiOptionImpl(newOptions,
newNormalizedOptions));
}
else
@@ -677,7 +643,7 @@
}
return new AttributeDescription(newAttributeDescription,
- attributeDescription.attributeType, new MultiOptionImpl(newOptions,
+ attributeType, new MultiOptionImpl(newOptions,
newNormalizedOptions));
}
}
diff --git a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/AbstractLDIFReader.java b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/AbstractLDIFReader.java
index 2f59caa..d2fb8c8 100644
--- a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/AbstractLDIFReader.java
+++ b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/AbstractLDIFReader.java
@@ -23,6 +23,7 @@
*
*
* Copyright 2009-2010 Sun Microsystems, Inc.
+ * Portions copyright 2011 ForgeRock AS
*/
package org.forgerock.opendj.ldif;
@@ -623,8 +624,7 @@
}
else
{
- attributeDescription = AttributeDescription.create(attributeDescription,
- "binary");
+ attributeDescription = attributeDescription.withOption("binary");
}
Attribute attribute = entry.getAttribute(attributeDescription);
diff --git a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFChangeRecordReader.java b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFChangeRecordReader.java
index 33926d7..0d0e7ed 100644
--- a/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFChangeRecordReader.java
+++ b/opendj-sdk/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/LDIFChangeRecordReader.java
@@ -23,6 +23,7 @@
*
*
* Copyright 2009-2010 Sun Microsystems, Inc.
+ * Portions copyright 2011 ForgeRock AS
*/
package org.forgerock.opendj.ldif;
@@ -586,8 +587,7 @@
}
else
{
- attributeDescription = AttributeDescription.create(
- attributeDescription, "binary");
+ attributeDescription = attributeDescription.withOption("binary");
}
// Now go through the rest of the attributes until the "-" line is
@@ -620,8 +620,7 @@
if (attributeDescription.getAttributeType().getSyntax()
.isBEREncodingRequired())
{
- attributeDescription2 = AttributeDescription.create(
- attributeDescription2, "binary");
+ attributeDescription2 = attributeDescription2.withOption("binary");
}
if (!attributeDescription2.equals(attributeDescription))
--
Gitblit v1.10.0