Package org.ldaptive
Class LdapAttribute
java.lang.Object
org.ldaptive.AbstractFreezable
org.ldaptive.LdapAttribute
- All Implemented Interfaces:
Freezable
- Direct Known Subclasses:
UnicodePwdAttribute
LDAP attribute defined as:
Attribute ::= PartialAttribute(WITH COMPONENTS {
...,
vals (SIZE(1..MAX))})
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classContainer for an attribute value.static classprivate static final classComparator for byte arrays.private static final classComparator for strings. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate StringAttribute name.private final Collection<LdapAttribute.AttributeValue>Attribute values.private booleanWhether this attribute is binary and string representations should be base64 encoded.private static final String[]List of custom binary attribute names.private static final String[]List of attribute names known to use binary syntax.private static final inthash code seed. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.LdapAttribute(String type) Creates a new attribute.LdapAttribute(String type, byte[]... value) Creates a new attribute.LdapAttribute(String type, String... value) Creates a new attribute. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBinaryValues(byte[]... value) Adds the supplied byte array as a value for this attribute.voidaddBinaryValues(Collection<byte[]> values) Adds all the byte arrays in the supplied collection as values for this attribute.(package private) voidaddBinaryValuesInternal(Collection<byte[]> values) Adds all the byte arrays in the supplied collection as values for this attribute.voidaddStringValues(String... value) Adds the supplied string as a value for this attribute.voidaddStringValues(Collection<String> values) Adds all the strings in the supplied collection as values for this attribute.<T> voidaddValues(Function<T, byte[]> func, Collection<T> values) Adds all the values in the supplied collection for this attribute by encoding them with the supplied function.<T> voidAdds the supplied values for this attribute by encoding them with the supplied function.static LdapAttribute.Builderbuilder()Creates a builder for this class.final voidclear()Removes all the values in this ldap attribute.final voidconfigureBinary(String... attrNames) Checks whether attrNames matches the name of this attribute.static LdapAttributecopy(LdapAttribute attr) Creates a mutable copy of the supplied attribute.booleanbyte[]Returns a single byte array value of this attribute.Collection<byte[]>Returns the values of this attribute as byte arrays.private Collection<String>Returns the attribute values encoded if they contain special characters.final StringgetName()Returns the attribute description with options.final StringgetName(boolean withOptions) Returns the attribute description with or without options.Returns any options that may exist on the attribute description.Returns a single string value of this attribute.Returns the values of this attribute as strings.<T> TReturns a single decoded value of this attribute.<T> Collection<T>Returns the values of this attribute decoded by the supplied function.inthashCode()booleanhasValue(byte[] value) Returns whether the supplied value exists in this attribute.booleanReturns whether the supplied value exists in this attribute.<T> booleanReturns whether the supplied value exists in this attribute.final booleanisBinary()Returns whether this ldap attribute is binary.voidmerge(LdapAttribute attr) Merges the values in the supplied attribute with this attribute.voidremoveBinaryValues(byte[]... value) Removes the supplied byte array as a value from this attribute.voidremoveBinaryValues(Collection<byte[]> values) Removes all the byte arrays in the supplied collection as values from this attribute.voidremoveStringValues(String... value) Removes the supplied string as a value from this attribute.voidremoveStringValues(Collection<String> values) Removes all the strings in the supplied collection as values from this attribute.<T> voidremoveValues(Function<T, byte[]> func, Collection<T> values) Removes all the values in the supplied collection for this attribute by encoding them with the supplied function.<T> voidremoveValues(Function<T, byte[]> func, T... value) Removes the supplied values for this attribute by encoding them with the supplied function.final voidsetBinary(boolean b) Sets whether this ldap attribute is binary.final voidSets the name.final intsize()Returns the number of values in this ldap attribute.static LdapAttributesort(LdapAttribute attr) Returns a new attribute whose values are sorted.toString()Methods inherited from class org.ldaptive.AbstractFreezable
assertMutable, freeze, freeze, freeze, isFrozen
-
Field Details
-
HASH_CODE_SEED
private static final int HASH_CODE_SEEDhash code seed.- See Also:
-
DEFAULT_BINARY_ATTRIBUTES
List of attribute names known to use binary syntax. -
BINARY_ATTRIBUTES
List of custom binary attribute names. -
attributeValues
Attribute values. -
attributeName
Attribute name. -
binary
private boolean binaryWhether this attribute is binary and string representations should be base64 encoded.
-
-
Constructor Details
-
LdapAttribute
public LdapAttribute()Default constructor. -
LdapAttribute
Creates a new attribute.- Parameters:
type- attribute description
-
LdapAttribute
Creates a new attribute.- Parameters:
type- attribute descriptionvalue- attribute values
-
LdapAttribute
Creates a new attribute.- Parameters:
type- attribute descriptionvalue- attribute values
-
-
Method Details
-
setName
Sets the name. This method has the side effect of setting this attribute as binary if the name has an option of 'binary' or the name matches one ofBINARY_ATTRIBUTES.- Parameters:
type- attribute name
-
isBinary
public final boolean isBinary()Returns whether this ldap attribute is binary.- Returns:
- whether this ldap attribute is binary
-
setBinary
public final void setBinary(boolean b) Sets whether this ldap attribute is binary.- Parameters:
b- whether this ldap attribute is binary
-
configureBinary
Checks whether attrNames matches the name of this attribute. If a match is found this attribute is set as binary.- Parameters:
attrNames- custom binary attribute names
-
getName
Returns the attribute description with options.- Returns:
- attribute description
-
getName
Returns the attribute description with or without options.- Parameters:
withOptions- whether the attribute description should include options- Returns:
- attribute description
-
getOptions
Returns any options that may exist on the attribute description.- Returns:
- attribute description options
-
getBinaryValue
public byte[] getBinaryValue()Returns a single byte array value of this attribute.- Returns:
- single byte array attribute value or null if this attribute is empty
-
getBinaryValues
Returns the values of this attribute as byte arrays. The return collection cannot be modified.- Returns:
- collection of byte array attribute values
-
getStringValue
Returns a single string value of this attribute.- Returns:
- single string attribute value or null if this attribute is empty
-
getStringValues
Returns the values of this attribute as strings. Binary data is base64 encoded. The return collection cannot be modified.- Returns:
- collection of string attribute values
-
getValue
Returns a single decoded value of this attribute.- Type Parameters:
T- type of decoded attribute- Parameters:
func- to decode attribute value with- Returns:
- single decoded attribute value or null if this attribute is empty
-
getValues
Returns the values of this attribute decoded by the supplied function.- Type Parameters:
T- type of decoded attributes- Parameters:
func- to decode attribute values with- Returns:
- collection of decoded attribute values, null values are discarded
-
addBinaryValues
public void addBinaryValues(byte[]... value) Adds the supplied byte array as a value for this attribute.- Parameters:
value- to add, null values are discarded
-
addBinaryValues
Adds all the byte arrays in the supplied collection as values for this attribute.- Parameters:
values- to add, null values are discarded
-
addBinaryValuesInternal
Adds all the byte arrays in the supplied collection as values for this attribute. This method does not create a copy of the supplied byte arrays.- Parameters:
values- to add
-
addStringValues
Adds the supplied string as a value for this attribute.- Parameters:
value- to add, null values are discarded
-
addStringValues
Adds all the strings in the supplied collection as values for this attribute.- Parameters:
values- to add, null values are discarded
-
addValues
Adds the supplied values for this attribute by encoding them with the supplied function.- Type Parameters:
T- type attribute to encode- Parameters:
func- to encode value withvalue- to encode and add, null values are discarded
-
addValues
Adds all the values in the supplied collection for this attribute by encoding them with the supplied function. SeeaddValues(Function, Object...).- Type Parameters:
T- type attribute to encode- Parameters:
func- to encode value withvalues- to encode and add, null values are discarded
-
merge
Merges the values in the supplied attribute with this attribute. Duplicate values are not merged.- Parameters:
attr- to merge
-
removeBinaryValues
public void removeBinaryValues(byte[]... value) Removes the supplied byte array as a value from this attribute.- Parameters:
value- to remove, null values are discarded
-
removeBinaryValues
Removes all the byte arrays in the supplied collection as values from this attribute.- Parameters:
values- to remove, null values are discarded
-
removeStringValues
Removes the supplied string as a value from this attribute.- Parameters:
value- to remove, null values are discarded
-
removeStringValues
Removes all the strings in the supplied collection as values from this attribute.- Parameters:
values- to remove, null values are discarded
-
removeValues
Removes the supplied values for this attribute by encoding them with the supplied function.- Type Parameters:
T- type attribute to encode- Parameters:
func- to encode value withvalue- to encode and remove, null values are discarded
-
removeValues
Removes all the values in the supplied collection for this attribute by encoding them with the supplied function. SeeremoveValues(Function, Object...).- Type Parameters:
T- type attribute to encode- Parameters:
func- to encode value withvalues- to encode and remove, null values are discarded
-
hasValue
public boolean hasValue(byte[] value) Returns whether the supplied value exists in this attribute.- Parameters:
value- to find- Returns:
- whether value exists
-
hasValue
Returns whether the supplied value exists in this attribute.- Parameters:
value- to find- Returns:
- whether value exists
-
hasValue
Returns whether the supplied value exists in this attribute.- Type Parameters:
T- type attribute to encode- Parameters:
func- to encode value withvalue- to find- Returns:
- whether value exists
-
size
public final int size()Returns the number of values in this ldap attribute.- Returns:
- number of values in this ldap attribute
-
clear
public final void clear()Removes all the values in this ldap attribute. -
equals
-
hashCode
public int hashCode() -
toString
-
getEncodedAttributeValues
Returns the attribute values encoded if they contain special characters. SeeLdapUtils.percentEncodeControlChars(String). Note thatbinaryattributes are base64 encoded by default.- Returns:
- encoded values
-
copy
Creates a mutable copy of the supplied attribute.- Parameters:
attr- to copy- Returns:
- new ldap attribute instance
-
sort
Returns a new attribute whose values are sorted. String values are sorted naturally. Binary values are sorted usingArrays.compare(byte[], byte[]).- Parameters:
attr- attribute to sort- Returns:
- new ldap attribute with sorted values
-
builder
Creates a builder for this class.- Returns:
- new builder
-