Class AttributeBuilder
- java.lang.Object
-
- org.opends.server.types.AttributeBuilder
-
- All Implemented Interfaces:
Iterable<ByteString>
@PublicAPI(stability=UNCOMMITTED, mayInstantiate=true, mayExtend=false, mayInvoke=true) public final class AttributeBuilder extends Object implements Iterable<ByteString>
This class provides an interface for creating new non-virtualAttributes, or "real" attributes.An attribute can be created incrementally using either
AttributeBuilder(AttributeType)orAttributeBuilder(AttributeType, String). The caller is then free to add new options usingsetOption(String)and new values usingadd(ByteString)oraddAll(Collection). Once all the options and values have been added, the attribute can be retrieved using thetoAttribute()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 thetoAttribute()method.The
Attributesclass contains convenience factory methods, e.g.Attributes.empty(String)for creating empty attributes, andAttributes.create(String, String)for creating single-valued attributes.AttributeBuilders can be re-used. Once anAttributeBuilderhas been converted to anAttributeusingtoAttribute(), 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 Summary
Constructors Constructor Description AttributeBuilder(String attributeDescription)Creates a new attribute builder with the specified attribute description and no values.AttributeBuilder(AttributeDescription attributeDescription)Creates a new attribute builder with the specified description.AttributeBuilder(AttributeType attributeType)Creates a new attribute builder with the specified type and no options and no values.AttributeBuilder(AttributeType attributeType, String name)Creates a new attribute builder with the specified type and user-provided name and no options and no values.AttributeBuilder(Attribute attribute)Creates a new attribute builder from an existing attribute.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(String valueString)Adds the specified attribute value to this attribute builder if it is not already present.booleanadd(ByteString attributeValue)Adds the specified attribute value to this attribute builder if it is not already present.booleanaddAll(Collection<ByteString> values)Adds the specified attribute values to this attribute builder if they are not already present.booleanaddAll(Attribute attribute)Adds all the values from the specified attribute to this attribute builder if they are not already present.booleanaddAllStrings(Collection<? extends Object> values)Adds the specified attribute values to this attribute builder if they are not already present.voidclear()Removes all attribute values from this attribute builder.booleancontains(ByteString value)Indicates whether this attribute builder contains the specified value.booleancontainsAll(Collection<?> values)Indicates whether this attribute builder contains all the values in the collection.booleanisEmpty()Returnstrueif this attribute builder contains no attribute values.Iterator<ByteString>iterator()Returns an iterator over the attribute values in this attribute builder.booleanoptionsEqual(AttributeDescription attributeDescription)Indicates whether this attribute builder has exactly the specified set of options.booleanremove(String valueString)Removes the specified attribute value from this attribute builder if it is present.booleanremove(ByteString value)Removes the specified attribute value from this attribute builder if it is present.booleanremoveAll(Collection<ByteString> values)Removes the specified attribute values from this attribute builder if they are present.booleanremoveAll(Attribute attribute)Removes all the values from the specified attribute from this attribute builder if they are not already present.voidreplace(String valueString)Replaces all the values in this attribute value with the specified attribute value.voidreplace(ByteString value)Replaces all the values in this attribute value with the specified attribute value.voidreplaceAll(Collection<ByteString> values)Replaces all the values in this attribute value with the specified attribute values.voidreplaceAll(Attribute attribute)Replaces all the values in this attribute value with the attributes from the specified attribute.booleansetOption(String option)Adds the specified option to this attribute builder if it is not already present.booleansetOptions(Iterable<String> options)Adds the specified options to this attribute builder if they are not already present.intsize()Returns the number of attribute values in this attribute builder.AttributetoAttribute()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.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
AttributeBuilder
public AttributeBuilder(Attribute attribute)
Creates a new attribute builder from an existing attribute.Modifications to the attribute builder will not impact the provided attribute.
- Parameters:
attribute- The attribute to be copied.
-
AttributeBuilder
public AttributeBuilder(AttributeDescription attributeDescription)
Creates a new attribute builder with the specified description.- Parameters:
attributeDescription- The attribute description for this attribute builder.
-
AttributeBuilder
public AttributeBuilder(AttributeType attributeType)
Creates a new attribute builder with the specified type and no options and no values.- Parameters:
attributeType- The attribute type for this attribute builder.
-
AttributeBuilder
public AttributeBuilder(AttributeType attributeType, String name)
Creates a new attribute builder with the specified type and user-provided name and no options and no values.- Parameters:
attributeType- The attribute type for this attribute builder.name- The user-provided name for this attribute builder.
-
AttributeBuilder
public AttributeBuilder(String attributeDescription)
Creates a new attribute builder with the specified attribute description and no values.If the attribute name cannot be found in the schema, a new attribute type is created using the default attribute syntax.
- Parameters:
attributeDescription- The attribute description for this attribute builder.
-
-
Method Detail
-
add
public boolean add(String valueString)
Adds the specified attribute value to this attribute builder if it is not already present.- Parameters:
valueString- The string representation of the attribute value to be added to this attribute builder.- Returns:
trueif this attribute builder did not already contain the specified attribute value.
-
add
public boolean add(ByteString attributeValue)
Adds the specified attribute value to this attribute builder if it is not already present.- Parameters:
attributeValue- TheByteStringrepresentation of the attribute value to be added to this attribute builder.- Returns:
trueif this attribute builder did not already contain the specified attribute value.
-
addAll
public boolean addAll(Attribute attribute)
Adds all the values from the specified attribute to this attribute builder if they are not already present.- Parameters:
attribute- The attribute containing the values to be added to this attribute builder.- Returns:
trueif this attribute builder was modified.
-
addAll
public boolean addAll(Collection<ByteString> values)
Adds the specified attribute values to this attribute builder if they are not already present.- Parameters:
values- The attribute values to be added to this attribute builder.- Returns:
trueif this attribute builder was modified.
-
addAllStrings
public boolean addAllStrings(Collection<? extends Object> values)
Adds the specified attribute values to this attribute builder if they are not already present.- Parameters:
values- The attribute values to be added to this attribute builder.- Returns:
trueif this attribute builder was modified.- Throws:
NullPointerException- if any of the values is null
-
clear
public void clear()
Removes all attribute values from this attribute builder.
-
contains
public boolean contains(ByteString value)
Indicates whether this attribute builder contains the specified value.- Parameters:
value- The value for which to make the determination.- Returns:
trueif this attribute builder has the specified value, orfalseif not.
-
containsAll
public boolean containsAll(Collection<?> values)
Indicates whether this attribute builder contains all the values in the collection.- Parameters:
values- The set of values for which to make the determination.- Returns:
trueif this attribute builder contains all the values in the provided collection, orfalseif it does not contain at least one of them.
-
isEmpty
public boolean isEmpty()
Returnstrueif this attribute builder contains no attribute values.- Returns:
trueif this attribute builder contains no attribute values.
-
iterator
public Iterator<ByteString> iterator()
Returns an iterator over the attribute values in this attribute builder. The attribute values are returned in the order in which they were added to this attribute builder. The returned iterator supports attribute value removals via itsremovemethod.- Specified by:
iteratorin interfaceIterable<ByteString>- Returns:
- An iterator over the attribute values in this attribute builder.
-
remove
public boolean remove(ByteString value)
Removes the specified attribute value from this attribute builder if it is present.- Parameters:
value- The attribute value to be removed from this attribute builder.- Returns:
trueif this attribute builder contained the specified attribute value.
-
remove
public boolean remove(String valueString)
Removes the specified attribute value from this attribute builder if it is present.- Parameters:
valueString- The string representation of the attribute value to be removed from this attribute builder.- Returns:
trueif this attribute builder contained the specified attribute value.
-
removeAll
public boolean removeAll(Attribute attribute)
Removes all the values from the specified attribute from this attribute builder if they are not already present.- Parameters:
attribute- The attribute containing the values to be removed from this attribute builder.- Returns:
trueif this attribute builder was modified.
-
removeAll
public boolean removeAll(Collection<ByteString> values)
Removes the specified attribute values from this attribute builder if they are present.- Parameters:
values- The attribute values to be removed from this attribute builder.- Returns:
trueif this attribute builder was modified.
-
replace
public void replace(ByteString value)
Replaces all the values in this attribute value with the specified attribute value.- Parameters:
value- The attribute value to replace all existing values.
-
replace
public void replace(String valueString)
Replaces all the values in this attribute value with the specified attribute value.- Parameters:
valueString- The string representation of the attribute value to replace all existing values.
-
replaceAll
public void replaceAll(Attribute attribute)
Replaces all the values in this attribute value with the attributes from the specified attribute.- Parameters:
attribute- The attribute containing the values to replace all existing values.
-
replaceAll
public void replaceAll(Collection<ByteString> values)
Replaces all the values in this attribute value with the specified attribute values.- Parameters:
values- The attribute values to replace all existing values.
-
setOption
public boolean setOption(String option)
Adds the specified option to this attribute builder if it is not already present.- Parameters:
option- The option to be added to this attribute builder.- Returns:
trueif this attribute builder did not already contain the specified option.
-
setOptions
public boolean setOptions(Iterable<String> options)
Adds the specified options to this attribute builder if they are not already present.- Parameters:
options- The options to be added to this attribute builder.- Returns:
trueif this attribute builder was modified.
-
optionsEqual
public boolean optionsEqual(AttributeDescription attributeDescription)
Indicates whether this attribute builder has exactly the specified set of options.- Parameters:
attributeDescription- The attribute description containing the set of options for which to make the determination- Returns:
trueif this attribute builder has exactly the specified set of options.
-
size
public int size()
Returns the number of attribute values in this attribute builder.- Returns:
- The number of attribute values in this attribute builder.
-
toAttribute
public Attribute toAttribute() throws IllegalStateException
Returns an attribute representing the content of this attribute builder.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.- Returns:
- An attribute representing the content of this attribute builder.
- Throws:
IllegalStateException- If this attribute builder has an undefined attribute type or name.
-
toAttributeList
public List<Attribute> toAttributeList() throws IllegalStateException
Returns a List with a single attribute representing the content of this attribute builder.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.- Returns:
- A List with a single attribute representing the content of this attribute builder.
- Throws:
IllegalStateException- If this attribute builder has an undefined attribute type or name.
-
-