From 8adb7af006bb6bf8a71f86bb520671de381c8e3e Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 13 Feb 2013 09:49:16 +0000
Subject: [PATCH] Minor API cleanup to make it easier to use.

---
 opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/LinkedAttribute.java |   50 ++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/LinkedAttribute.java b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/LinkedAttribute.java
index 1a4458e..ff8e0dc 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/LinkedAttribute.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/LinkedAttribute.java
@@ -22,12 +22,11 @@
  *
  *
  *      Copyright 2009-2010 Sun Microsystems, Inc.
- *      Portions copyright 2012 ForgeRock AS.
+ *      Portions copyright 2012-2013 ForgeRock AS.
  */
 
 package org.forgerock.opendj.ldap;
 
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.ConcurrentModificationException;
 import java.util.HashMap;
@@ -506,6 +505,9 @@
     /**
      * Creates a new attribute having the specified attribute description and
      * single attribute value.
+     * <p>
+     * If {@code value} is not an instance of {@code ByteString} then it will be
+     * converted using the {@link ByteString#valueOf(Object)} method.
      *
      * @param attributeDescription
      *            The attribute description.
@@ -515,7 +517,7 @@
      *             If {@code attributeDescription} or {@code value} was
      *             {@code null} .
      */
-    public LinkedAttribute(final AttributeDescription attributeDescription, final ByteString value) {
+    public LinkedAttribute(final AttributeDescription attributeDescription, final Object value) {
         this(attributeDescription);
         add(value);
     }
@@ -523,6 +525,9 @@
     /**
      * Creates a new attribute having the specified attribute description and
      * attribute values.
+     * <p>
+     * Any attribute values which are not instances of {@code ByteString} will
+     * be converted using the {@link ByteString#valueOf(Object)} method.
      *
      * @param attributeDescription
      *            The attribute description.
@@ -533,14 +538,17 @@
      *             {@code null}.
      */
     public LinkedAttribute(final AttributeDescription attributeDescription,
-            final ByteString... values) {
+            final Object... values) {
         this(attributeDescription);
-        addAll(Arrays.asList(values));
+        add(values);
     }
 
     /**
      * Creates a new attribute having the specified attribute description and
      * attribute values.
+     * <p>
+     * Any attribute values which are not instances of {@code ByteString} will
+     * be converted using the {@link ByteString#valueOf(Object)} method.
      *
      * @param attributeDescription
      *            The attribute description.
@@ -551,9 +559,9 @@
      *             {@code null}.
      */
     public LinkedAttribute(final AttributeDescription attributeDescription,
-            final Collection<ByteString> values) {
+            final Collection<?> values) {
         this(attributeDescription);
-        addAll(values);
+        addAll(values, null);
     }
 
     /**
@@ -575,6 +583,30 @@
 
     /**
      * Creates a new attribute having the specified attribute description and
+     * attribute values. The attribute description will be decoded using the
+     * default schema.
+     * <p>
+     * Any attribute values which are not instances of {@code ByteString} will
+     * be converted using the {@link ByteString#valueOf(Object)} method.
+     *
+     * @param attributeDescription
+     *            The attribute description.
+     * @param values
+     *            The attribute values.
+     * @throws LocalizedIllegalArgumentException
+     *             If {@code attributeDescription} could not be decoded using
+     *             the default schema.
+     * @throws NullPointerException
+     *             If {@code attributeDescription} or {@code values} was
+     *             {@code null}.
+     */
+    public LinkedAttribute(final String attributeDescription, final Collection<?> values) {
+        this(attributeDescription);
+        addAll(values, null);
+    }
+
+    /**
+     * Creates a new attribute having the specified attribute description and
      * single attribute value. The attribute description will be decoded using
      * the default schema.
      * <p>
@@ -618,9 +650,7 @@
      */
     public LinkedAttribute(final String attributeDescription, final Object... values) {
         this(attributeDescription);
-        for (final Object value : values) {
-            add(ByteString.valueOf(value));
-        }
+        add(values);
     }
 
     /**

--
Gitblit v1.10.0