@PublicAPI(stability=UNCOMMITTED, mayInstantiate=true, mayExtend=false, mayInvoke=true) public final class AttributeBuilder extends Object implements Iterable<org.forgerock.opendj.ldap.ByteString>
Attribute
s, or "real" attributes.
An attribute can be created incrementally using either
AttributeBuilder(AttributeType)
or
AttributeBuilder(AttributeType, String)
. The caller is
then free to add new options using setOption(String)
and
new values using add(ByteString)
or
addAll(Collection)
. Once all the options and values have
been added, the attribute can be retrieved using the
toAttribute()
method.
A real attribute can also be created based on the values taken from
another attribute using the AttributeBuilder(Attribute)
constructor. The caller is then free to modify the values within
the attribute before retrieving the updated attribute using the
toAttribute()
method.
The Attributes
class contains
convenience factory methods,
e.g. Attributes.empty(String)
for
creating empty attributes, and
Attributes.create(String, String)
for creating single-valued attributes.
AttributeBuilder
s can be re-used. Once an
AttributeBuilder
has been converted to an
Attribute
using toAttribute()
, its state is reset
so that its attribute type, user-provided name, options, and values
are all undefined:
AttributeBuilder builder = new AttributeBuilder(); for (int i = 0; i < 10; i++) { builder.setAttributeType("myAttribute" + i); builder.setOption("an-option"); builder.add("a value"); Attribute attribute = builder.toAttribute(); // Do something with attribute... }
Implementation Note: this class is optimized for the common case where there is only a single value. By doing so, we avoid using unnecessary storage space and also performing any unnecessary normalization. In addition, this class is optimized for the common cases where there are zero or one attribute type options.
Constructor and Description |
---|
AttributeBuilder(Attribute attribute)
Creates a new attribute builder from an existing attribute.
|
AttributeBuilder(org.forgerock.opendj.ldap.AttributeDescription attributeDescription)
Creates a new attribute builder with the specified description.
|
AttributeBuilder(org.forgerock.opendj.ldap.schema.AttributeType attributeType)
Creates a new attribute builder with the specified type and no
options and no values.
|
AttributeBuilder(org.forgerock.opendj.ldap.schema.AttributeType attributeType,
String name)
Creates a new attribute builder with the specified type and
user-provided name and no options and no values.
|
AttributeBuilder(String attributeDescription)
Creates a new attribute builder with the specified attribute description and no values.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(org.forgerock.opendj.ldap.ByteString attributeValue)
Adds the specified attribute value to this attribute builder if it is not
already present.
|
boolean |
add(String valueString)
Adds the specified attribute value to this attribute builder if
it is not already present.
|
boolean |
addAll(Attribute attribute)
Adds all the values from the specified attribute to this
attribute builder if they are not already present.
|
boolean |
addAll(Collection<org.forgerock.opendj.ldap.ByteString> values)
Adds the specified attribute values to this attribute builder if
they are not already present.
|
boolean |
addAllStrings(Collection<? extends Object> values)
Adds the specified attribute values to this attribute builder
if they are not already present.
|
void |
clear()
Removes all attribute values from this attribute builder.
|
boolean |
contains(org.forgerock.opendj.ldap.ByteString value)
Indicates whether this attribute builder contains the specified
value.
|
boolean |
containsAll(Collection<?> values)
Indicates whether this attribute builder contains all the values
in the collection.
|
boolean |
isEmpty()
Returns
true if this attribute builder contains no
attribute values. |
Iterator<org.forgerock.opendj.ldap.ByteString> |
iterator()
Returns an iterator over the attribute values in this attribute
builder.
|
boolean |
optionsEqual(org.forgerock.opendj.ldap.AttributeDescription attributeDescription)
Indicates whether this attribute builder has exactly the specified set of options.
|
boolean |
remove(org.forgerock.opendj.ldap.ByteString value)
Removes the specified attribute value from this attribute builder
if it is present.
|
boolean |
remove(String valueString)
Removes the specified attribute value from this attribute builder
if it is present.
|
boolean |
removeAll(Attribute attribute)
Removes all the values from the specified attribute from this
attribute builder if they are not already present.
|
boolean |
removeAll(Collection<org.forgerock.opendj.ldap.ByteString> values)
Removes the specified attribute values from this attribute
builder if they are present.
|
void |
replace(org.forgerock.opendj.ldap.ByteString value)
Replaces all the values in this attribute value with the
specified attribute value.
|
void |
replace(String valueString)
Replaces all the values in this attribute value with the
specified attribute value.
|
void |
replaceAll(Attribute attribute)
Replaces all the values in this attribute value with the
attributes from the specified attribute.
|
void |
replaceAll(Collection<org.forgerock.opendj.ldap.ByteString> values)
Replaces all the values in this attribute value with the
specified attribute values.
|
boolean |
setOption(String option)
Adds the specified option to this attribute builder if it is not
already present.
|
boolean |
setOptions(Iterable<String> options)
Adds the specified options to this attribute builder if they are
not already present.
|
int |
size()
Returns the number of attribute values in this attribute builder.
|
Attribute |
toAttribute()
Returns an attribute representing the content of this attribute builder.
|
List<Attribute> |
toAttributeList()
Returns a List with a single attribute representing the content of this attribute builder.
|
String |
toString() |
public AttributeBuilder(Attribute attribute)
Modifications to the attribute builder will not impact the provided attribute.
attribute
- The attribute to be copied.public AttributeBuilder(org.forgerock.opendj.ldap.AttributeDescription attributeDescription)
attributeDescription
- The attribute description for this attribute builder.public AttributeBuilder(org.forgerock.opendj.ldap.schema.AttributeType attributeType)
attributeType
- The attribute type for this attribute builder.public AttributeBuilder(org.forgerock.opendj.ldap.schema.AttributeType attributeType, String name)
attributeType
- The attribute type for this attribute builder.name
- The user-provided name for this attribute builder.public AttributeBuilder(String attributeDescription)
If the attribute name cannot be found in the schema, a new attribute type is created using the default attribute syntax.
attributeDescription
- The attribute description for this attribute builder.public boolean add(String valueString)
valueString
- The string representation of the attribute value to be
added to this attribute builder.true
if this attribute builder did not
already contain the specified attribute value.public boolean add(org.forgerock.opendj.ldap.ByteString attributeValue)
attributeValue
- The ByteString
representation of the attribute value to be
added to this attribute builder.true
if this attribute builder did not already contain
the specified attribute value.public boolean addAll(Attribute attribute)
attribute
- The attribute containing the values to be added to this
attribute builder.true
if this attribute builder was
modified.public boolean addAll(Collection<org.forgerock.opendj.ldap.ByteString> values)
values
- The attribute values to be added to this attribute builder.true
if this attribute builder was modified.public boolean addAllStrings(Collection<? extends Object> values)
values
- The attribute values to be added to this attribute builder.true
if this attribute builder was modified.NullPointerException
- if any of the values is nullpublic void clear()
public boolean contains(org.forgerock.opendj.ldap.ByteString value)
value
- The value for which to make the determination.true
if this attribute builder has the
specified value, or false
if not.public boolean containsAll(Collection<?> values)
values
- The set of values for which to make the determination.true
if this attribute builder contains
all the values in the provided collection, or
false
if it does not contain at least one
of them.public boolean isEmpty()
true
if this attribute builder contains no
attribute values.true
if this attribute builder contains no
attribute values.public Iterator<org.forgerock.opendj.ldap.ByteString> iterator()
remove
method.public boolean remove(org.forgerock.opendj.ldap.ByteString value)
value
- The attribute value to be removed from this attribute
builder.true
if this attribute builder contained
the specified attribute value.public boolean remove(String valueString)
valueString
- The string representation of the attribute value to be
removed from this attribute builder.true
if this attribute builder contained
the specified attribute value.public boolean removeAll(Attribute attribute)
attribute
- The attribute containing the values to be removed from
this attribute builder.true
if this attribute builder was
modified.public boolean removeAll(Collection<org.forgerock.opendj.ldap.ByteString> values)
values
- The attribute values to be removed from this attribute
builder.true
if this attribute builder was
modified.public void replace(org.forgerock.opendj.ldap.ByteString value)
value
- The attribute value to replace all existing values.public void replace(String valueString)
valueString
- The string representation of the attribute value to
replace all existing values.public void replaceAll(Attribute attribute)
attribute
- The attribute containing the values to replace all
existing values.public void replaceAll(Collection<org.forgerock.opendj.ldap.ByteString> values)
values
- The attribute values to replace all existing values.public boolean setOption(String option)
option
- The option to be added to this attribute builder.true
if this attribute builder did not
already contain the specified option.public boolean setOptions(Iterable<String> options)
options
- The options to be added to this attribute builder.true
if this attribute builder was
modified.public boolean optionsEqual(org.forgerock.opendj.ldap.AttributeDescription attributeDescription)
attributeDescription
- The attribute description containing the set of options for which to make the
determinationtrue
if this attribute builder has exactly the specified set of options.public int size()
public Attribute toAttribute() throws IllegalStateException
For efficiency purposes this method resets the content of this
attribute builder so that it no longer contains any options or
values and its attribute type is null
.
IllegalStateException
- If this attribute builder has an undefined attribute type or name.public List<Attribute> toAttributeList() throws IllegalStateException
For efficiency purposes this method resets the content of this
attribute builder so that it no longer contains any options or
values and its attribute type is null
.
IllegalStateException
- If this attribute builder has an undefined attribute type or name.Copyright © 2010-2017 ForgeRock AS. All Rights Reserved.